Bug in floating-point addition: is anyone else seeing this?
Diez B. Roggisch
deets at nospam.web.de
Wed May 21 14:52:03 EDT 2008
Mark Dickinson schrieb:
> 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?
It is working under OSX:
(TG1044)mac-dir:~/projects/artnology/Van_Abbe_RMS/Van-Abbe-RMS deets$ python
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Welcome to rlcompleter2 0.96
for nice experiences hit <tab> multiple times
>>> a = 1e16-2.
>>> a
9999999999999998.0
>>> a+0.9999
9999999999999998.0
>>>
But under linux, I get the same behavior:
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Welcome to rlcompleter2 0.96
for nice experiences hit <tab> multiple times
>>> a = 1e16-2.
>>> a+0.9999
10000000000000000.0
>>>
So - seems to me it's a linux-thing. I don't know enough about
IEEE-floats to make any assumptions on the reasons for that.
Diez
More information about the Python-list
mailing list