[Python-bugs-list] [ python-Bugs-226586 ] Floating point is broken in Python 2.0

noreply@sourceforge.net noreply@sourceforge.net
Mon, 06 May 2002 11:04:27 -0700


Bugs item #226586, was opened at 2000-12-21 07:03
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=226586&group_id=5470

Category: IDLE
Group: Not a Bug
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: Floating point is broken in Python 2.0

Initial Comment:
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>> p=0.6
>>> p
0.59999999999999998
>>> 

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2002-05-06 14:04

Message:
Logged In: YES 
user_id=31435

You may not like it, but it's not a bug.  Read the docs for 
a detailed explanation:

http://www.python.org/doc/current/tut/node14.html

----------------------------------------------------------------------

Comment By: Michael Donegan (invader8)
Date: 2002-05-06 13:10

Message:
Logged In: YES 
user_id=537045

This is still a problem in
Python 2.2 (#1, Dec 31 2001, 15:21:18)

It is a bug. Why would we expect that
the interactive prompt would behave
differently (worse) from using print?

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2000-12-21 11:15

Message:
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 a detailed example:

http://www.python.org/cgi-bin/moinmoin/RepresentationError


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=226586&group_id=5470