[ python-Bugs-919498 ] Math Division Problem?

SourceForge.net noreply at sourceforge.net
Fri Mar 19 09:23:05 EST 2004


Bugs item #919498, was opened at 2004-03-19 14:20
Message generated for change (Comment added) made by sjoerd
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=919498&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: GrASP (grasp81)
Assigned to: Nobody/Anonymous (nobody)
Summary: Math Division Problem?

Initial Comment:
Using
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC 
v.1200 32 bit (Intel)] on win32

A mere real division resulted in this:
>>> 7.0/3
2.3333333333333335

Mind the trailing '5'. Did I miss my University classes too 
much? ;)

Amazingly,
>>> 4.0/3
1.3333333333333333
- works OK.


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

Comment By: Sjoerd Mullender (sjoerd)
Date: 2004-03-19 15:23

Message:
Logged In: YES 
user_id=43607

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://www.python.org/doc/2.2.1/tut/node14.html

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

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



More information about the Python-bugs-list mailing list