Actions
Bug #10592
closedAdding floats resluts in an incorrect result
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
Backport:
Description
1.1+1.1+1.1 = 3.3
However in the current 2.1.5 this is what happens:
dmolnar@domalaptop:~> irb
2.1.5 :001 > 1.1+1.1+1.1
=> 3.3000000000000003
2.1.5 :002 >
Files
Updated by doma (Domokos Molnar) over 9 years ago
dmolnar@domalaptop:~> irb
2.1.5 :001 > 1.1+1.1+1.1-3.3
=> 4.440892098500626e-16
Updated by recursive-madman (Recursive Madman) over 9 years ago
This is not a ruby bug. See http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
Updated by recursive-madman (Recursive Madman) over 9 years ago
Use Rational if you want exact results:
1.1 * 3 #=> 3.3000000000000003
(Rational('1.1') * 3).to_f #=> 3.3
Updated by nobu (Nobuyoshi Nakada) over 9 years ago
- Description updated (diff)
- Status changed from Open to Rejected
Updated by doma (Domokos Molnar) over 9 years ago
So true. Sorry about reporting it.
Actions
Like0
Like0Like0Like0Like0Like0