[Python-bugs-list] Floating Poiint Integer precision lost (PR#325)

tim_one@email.msn.com tim_one@email.msn.com
Wed, 10 May 2000 23:04:13 -0400 (EDT)


Joe, I'm afraid this isn't a bug:  Python floats use binary floating-point,
75.02 is not exactly representable in binary floating-point, so 75.02%1
isn't exactly 0.02 either, so that times 100 isn't exactly 2, etc etc.
You'll get the same results using C, C++, Java, Fortran, Perl, ... anything
that, like Python, uses native floating-point arithmetic.

However, under 1.5.2 the default display format used at the interactive
prompt hides the inaccuracy from you, by rounding away the inaccurate bits
for (& only for) display purposes.  The cause of the problem is clearer
under 1.6a2 (the latest alpha release of Python 1.6), which boosts the
number of digits displayed:

Python 1.6a2 (#0, Apr  6 2000, 11:45:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
IDLE 0.5 -- press F1 for help>>> (float("75.02")%1)*100
>>> (float("75.02")%1)*100
1.9999999999996021
>>> i = (float("75.02")%1)*100
>>> i
1.9999999999996021
>>> int(2.0)
2
>>> float(int(float(i)))
1.0
>>> int(float(2.0))
2
>>> int(float(str(i)))
2
>>> int(float(repr(i)))
1
>>>

> -----Original Message-----
> From: python-bugs-list-admin@python.org
> [mailto:python-bugs-list-admin@python.org]On Behalf Of
> kislo@athenium.com
> Sent: Wednesday, May 10, 2000 5:09 PM
> To: python-bugs-list@python.org
> Cc: bugs-py@python.org
> Subject: [Python-bugs-list] Floating Poiint Integer precision lost
> (PR#325)
>
>
> Full_Name: Joe Kislo
> Version: Python 1.5.2 (#1, Feb 18 2000, 11:28:06)  [GCC
> egcs-2.91.66 19990314/Linux
> OS: Linux 2.2 and Solaris OS 7 SPARC
> Submission from: houseatreides.ne.mediaone.net (24.128.32.113)
>
>
> Uhh, this doesn't seem to work on any platform I try it on.  Linux or
> solaris/sparc.
>
> If you could email me back at kislo@athenium.com the status of
> this bug, that
> would be great.
>
> >>> (float("75.02")%1)*100
> 2.0
> >>> i = (float("75.02")%1)*100
> >>> int(i)
> 1
> >>> i
> 2.0
> >>> int(2.0)
> 2
> >>> float(int(float(i)))
> 1.0
> >>> int(float(2.0))
> 2
> >>> int(float(str(i)))
> 2
>
>
>
>
>
> _______________________________________________
> Python-bugs-list maillist  -  Python-bugs-list@python.org
> http://www.python.org/mailman/listinfo/python-bugs-list