Hi Emil, This is sort-of expected. MacRuby floats have less precision than MRI because we pack them as immediate values, for performance reasons. As a more generic issue, floating point arithmetic is almost never accurate.
Laurent On Jun 5, 2010, at 9:59 AM, Emil Tin wrote: > > hey, > thanks for all the great work with macruby! > > i'm experiencing a difference in floating point behaviour between mri and the > latest macruby 0.7 nightly: > > ~$ ruby -v > ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0] > > ~$ ruby -e "z = 0.034228469425; puts Math.sqrt(z*z) < z" > false > > ~$ ruby -e "z = 0.034228469424; puts Math.sqrt(z*z) < z" > false > > > ~$ macruby -v > MacRuby 0.7 (ruby 1.9.2) [universal-darwin10.0, x86_64] > > ~$ macruby -e "z = 0.034228469425; puts Math.sqrt(z*z) < z" > false > > ~$ macruby -e "z = 0.034228469424; puts Math.sqrt(z*z) < z" > true > > > notice how that last script outputs true instead of false. also i'm seeing > this difference with floats: > > ~$ ruby -e "puts 8.1" > 8.1 > > ~$ macruby -e "puts 8.1" > 8.09999999999999 > > > > > this difference is causing trouble because asin() might fail even when the > input seems to be 1.0: > > z = 0.034228469424 > r = Math.sqrt z*z > puts d = z/r # => 1.0 > puts d>1.0 # false with mri, but true with macruby > puts Math.asin d # => 1.5707963267949 with mri, but error with macruby (since > d>1.0) > > > > -emil > > _______________________________________________ > MacRuby-devel mailing list > MacRuby-devel@lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel