ok.
it confused me a bit that d prints as "1.0", but d==1.0 evaluates to false. but
sprintf shows that it's just float#to_s that is truncating the output:
z = 0.034228469424
r = Math.sqrt z*z
d = z/r
puts d # => 1.0
puts d==1.0 # => false
puts spri
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,
> thank
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