[MacRuby-devel] difference in float behaviour

Emil Tin emil at tin.dk
Sat Jun 5 09:59:19 PDT 2010


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1920 bytes
Desc: not available
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100605/c7498d8e/attachment.bin>


More information about the MacRuby-devel mailing list