Bug #4135
closedbug in calculations in 1.9.3dev / 1.9.2
Description
=begin
$ ruby -v
ruby 1.9.3dev (2010-12-08 trunk 30125) [i686-linux]
I just installed ruby-head from rvm and run this in irb:
$ irb
ruby-head > 125.33 - (125.33/100.0*50.0)
=> 62.66499999999999
ruby-head > 125.33 / 100.0 * 50.0
=> 62.665000000000006
ruby-head > 15.33 / 100.0 * 50.0
=> 7.664999999999999
ruby-head > (15.33 / 100.0) * 50.0
=> 7.664999999999999
ruby-head > (14.33 / 100.0) * 50.0
=> 7.165000000000001
Which is obviously wrong.
The same in old ruby 1.9.2.dev
$ ruby -v
ruby 1.9.2dev (2009-07-18 trunk 24186) [i686-linux]
$ irb
ruby-1.9.2-preview1 > (14.33 / 100.0) * 50.0
=> 7.165000000000001
Ruby 1.8.7 looks good
$ ruby -v
ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-linux], MBARI 0x8770, Ruby Enterprise Edition 2010.02
$ irb
irb(main):001:0> (14.33 / 100.0) * 50.0
=> 7.165
=end
Updated by nobu (Nobuyoshi Nakada) about 14 years ago
- Status changed from Open to Rejected
=begin
=end
Updated by naruse (Yui NARUSE) about 14 years ago
=begin
Learn floating point numbers.
What Every Computer Scientist Should Know About Floating-Point Arithmetic
http://docs.sun.com/source/806-3568/ncg_goldberg.html
http://wiki.github.com/rdp/ruby_tutorials_core/ruby-talk-faq#floats_imprecise
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
=end
Updated by german (Dmitrii Samoilov) about 14 years ago
=begin
Stupid me. Sorry guys.
=end