Bug in floating-point addition: is anyone else seeing this?

Henrique Dante de Almeida hdante at gmail.com
Thu May 22 00:26:32 EDT 2008


On May 21, 3:38 pm, Mark Dickinson <dicki... at gmail.com> wrote:
>>> a = 1e16-2.
> >>> a
> 9999999999999998.0
> >>> a+0.999     # gives expected result
> 9999999999999998.0
> >>> a+0.9999   # doesn't round correctly.
>
> 10000000000000000.0

 Notice that 1e16-1 doesn't exist in IEEE double precision:
 1e16-2 == 0x1.1c37937e07fffp+53
 1e16 == 0x1.1c37937e08p+53

 (that is, the hex representation ends with "7fff", then goes to
"8000").

 So, it's just rounding. It could go up, to 1e16, or down, to 1e16-2.
This is not a bug, it's a feature.



More information about the Python-list mailing list