Project

General

Profile

Actions

Bug #6274

closed

Float addition incorrect

Added by swanboy (Michael Swan) about 12 years ago. Updated about 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3p21 (2012-01-07 revision 34224) [x86_64-linux]
Backport:
[ruby-core:44233]

Description

Adding decimals with repeating values appears to lead to an error in returned value.

For example if you inspect:
10 + 1.0 / 3.0
or
33 + 1.0 / 3.0

the values are not what they should be. You will need to test this in IRB.

Actions #1

Updated by marcandre (Marc-Andre Lafortune) about 12 years ago

  • Status changed from Open to Rejected

This is due to the fact that floats are approximate. The results follow the IEEE standard. Try it in Javascript, you'll get the same result.

Updated by Anonymous about 12 years ago

Issue #6274 has been updated by marcandre (Marc-Andre Lafortune).

Status changed from Open to Rejected

This is due to the fact that floats are approximate. The results follow the IEEE standard. Try it in Javascript, you'll get the same result.

I am almost happy that Ruby shows the rounding point error.
Apparently many programmers just don't realize just how imprecise
those underlying floats are, and now get to learn :)

-roger-

Actions

Also available in: Atom PDF

Like0
Like0Like0