Project

General

Profile

Actions

Bug #10592

closed

Adding floats resluts in an incorrect result

Added by doma (Domokos Molnar) over 9 years ago. Updated over 9 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
[ruby-core:66799]

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

test_float.rb (17 Bytes) test_float.rb doma (Domokos Molnar), 12/12/2014 08:50 AM

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

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0