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

Marc Christiansen usenet at solar-empire.de
Wed May 21 15:22:22 EDT 2008


Mark Dickinson <dickinsm at gmail.com> wrote:
> On SuSE 10.2/Xeon there seems to be a rounding bug for
> floating-point addition:
> 
> dickinsm at weyl:~> python
> Python 2.5 (r25:51908, May 25 2007, 16:14:04)
> [GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> a = 1e16-2.
>>>> a
> 9999999999999998.0
>>>> a+0.999     # gives expected result
> 9999999999999998.0
>>>> a+0.9999   # doesn't round correctly.
> 10000000000000000.0
> 
> The last result here should be 9999999999999998.0,
> not 10000000000000000.0.  Is anyone else seeing this
> bug, or is it just a quirk of my system?

On my system, it works:

 Python 2.5.2 (r252:60911, May 21 2008, 18:49:26) 
 [GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> a = 1e16 - 2.; a
 9999999999999998.0
 >>> a + 0.9999
 9999999999999998.0

Marc



More information about the Python-list mailing list