Possible Duplicate:
Floating Point Limitations
Hi there,
maybe this has a very simple answer. I was playing around with the Python interpreter.
>>> 1
1
>>> 1.1
1.1000000000000001
>>> 1.2
1.2
Why 1.1
was interpreted as 1.1000000000000001
?
Possible Duplicate:
Floating Point Limitations
Hi there,
maybe this has a very simple answer. I was playing around with the Python interpreter.
>>> 1
1
>>> 1.1
1.1000000000000001
>>> 1.2
1.2
Why 1.1
was interpreted as 1.1000000000000001
?
From The Floating-Point Guide:
Why don’t my numbers, like 0.1 + 0.2 add up to a nice round 0.3, and instead I get a weird result like 0.30000000000000004?
Because internally, computers use a format (binary floating-point) that cannot accurately represent a number like 0.1, 0.2 or 0.3 at all.
When the code is compiled or interpreted, your “0.1” is already rounded to the nearest number in that format, which results in a small rounding error even before the calculation happens.
That is due to the way the numbers are stored internally. The format is specified in the IEEE_754-2008 speficiation.
Some more information can be found on single precision floats here