[Python-bugs-list] [ python-Bugs-427036 ] [66.6] != [66.599999999999994]?

noreply@sourceforge.net noreply@sourceforge.net
Thu, 24 May 2001 16:34:20 -0700


Bugs item #427036, was updated on 2001-05-24 12:40
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=427036&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: David Waggle (darkmo0d)
Assigned to: Nobody/Anonymous (nobody)
Summary: [66.6] != [66.599999999999994]?

Initial Comment:
=darkmo0d=[14:52:28]darkmo0d<$> python -c 'a=[66.6]
;print a'
[66.599999999999994]


should this occur? seems like it could cause a serious
problem, provided this is not specific to my machine.
Which is:

x86 Linux Kernel 2.4.5-pre1
Python 2.1
Celeron 433mHz with 256MB SDRAM



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

>Comment By: Tim Peters (tim_one)
Date: 2001-05-24 16:34

Message:
Logged In: YES 
user_id=31435

As I mentioned in email, the tutorial has already been 
repaired but the new version has not yet been released (it 
will for be for 2.2).  Also (probably) adding a new 
Appendix (see your email).

Didn't understand the "all day" comment -- looks like you 
got a response in less than 2 hours (yes, a canned one, but 
had you searched the bug database you would have found many 
repetitions of this basic complaint on your own -- indeed, 
that's why a canned response exists <wink>).

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

Comment By: David Waggle (darkmo0d)
Date: 2001-05-24 14:23

Message:
Logged In: YES 
user_id=206710

The code/output that follows is what results from using the
python tutorial.
So, I grasp the concept of the binary floating point
"situation". No problem. But it took all day and a bug
report to elicit canned-text. So not only am I expericencing
a "RepresentationError", but so is the python tutorial. No
where in chap/sec 5.1 on pp 29-30 does it mention this and
it is quite confusing to a newbie when the teacher's answers
and the student's answers do not match. According to the
tutorial this code/output should be what I see when passed
through the interpreter:

>>>a = [66.6, 333, 333, 1, 1234.5]
>>>a
[66.6, 333, 333, 1, 1234.5]

but I see:

Python 2.1 (#1, May 24 2001, 09:28:32) 
[GCC 2.95.3 20010315 (release)] on linux2
Type "copyright", "credits" or "license" for more
information.
>>> a = [66.6, 333, 333, 1, 1234.5]
>>> a
[66.599999999999994, 333, 333, 1, 1234.5]
>>> str(a)
'[66.599999999999994, 333, 333, 1, 1234.5]'
>>> str(a[0])
'66.6'
>>> str(a[0:3])
'[66.599999999999994, 333, 333]'
>>> str(a[0:1])
'[66.599999999999994]'
>>> str(a[0:])
'[66.599999999999994, 333, 333, 1, 1234.5]'

So point taken and logged. So if you know the guy who wrote
the docs, or are the guy who wrote the docs: Take my point
into consideration. Docs can have bugs, too. 




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

Comment By: Tim Peters (tim_one)
Date: 2001-05-24 13:00

Message:
Logged In: YES 
user_id=31435

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=427036&group_id=5470