[Python-bugs-list] [ python-Bugs-561913 ] float values in lists
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 29 May 2002 08:06:09 -0700
Bugs item #561913, was opened at 2002-05-29 10:36
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=561913&group_id=5470
Category: Python Interpreter Core
Group: Python 2.2.1
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Brian Townley (thranil)
Assigned to: Michael Hudson (mwh)
Summary: float values in lists
Initial Comment:
System: Windows 2000
Execute the following script to reproduce problem:
theList = [3.14,59,"A string", 1024]
print theList
What I am seeing:
The float value "3.14" is being displayed as
3.1400000000000001.
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2002-05-29 11:06
Message:
Logged In: YES
user_id=31435
For example, in C/C++ print with format %.17g
----------------------------------------------------------------------
Comment By: Brian Townley (thranil)
Date: 2002-05-29 10:56
Message:
Logged In: YES
user_id=555127
The explanation given makes sense, yet I am unable to
reproduce this floating point rounding error with a Visual C++
compiled project. Can you recommend a way to repro it so I
can see this issue within a compilable language?
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2002-05-29 10:41
Message:
Logged In: YES
user_id=6656
Hmm, try this URL instead:
http://www.python.org/doc/2.2.1/tut/node14.html
(I've fixed the canned response).
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2002-05-29 10:39
Message:
Logged In: YES
user_id=6656
This is not a bug.
Binary floating point cannot represent decimal fractions exactly,
so some rounding always occurs (even in Python 1.5.2).
What changed is that Python 2.0 shows more precision than before
in certain circumstances (repr() and the interactive prompt).
You can use str() or print to get the old, rounded output:
>>> print 0.1+0.1
0.2
>>>
Follow the link for more information:
http://python.sourceforge.net/devel-docs/tut/node14.html
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=561913&group_id=5470