Bug #4023
closedto_i pathological case in 1.8.7, 1.9.2
Description
=begin
% /usr/bin/ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
% /usr/bin/ruby -e "puts (4.55100).to_i"
455
% /usr/bin/ruby -e "puts (4.56100).to_i"
455
% /usr/bin/ruby -e "puts (4.57*100).to_i"
457
Also happens in 1.9.2 (2010-08-18) [i686-linux] (via http://tryruby.org/)
Should I really not expect (4.56*100).to_i to return 456?
=end
Updated by runpaint (Run Paint Run Run) about 14 years ago
=begin
Float#to_i is documented as truncating its receiver. Specifically, if the receiver is positive, it is floored. On trunk, 4.56*100 == 455.99999999999994, which when floored is 455.
=end
Updated by naruse (Yui NARUSE) about 14 years ago
- Status changed from Open to Rejected
=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