[Python-bugs-list] [Bug #124791] math.modf, math.floor, math.ceil give misleading result

noreply@sourceforge.net noreply@sourceforge.net
Wed, 6 Dec 2000 17:27:44 -0800


Bug #124791, was updated on 2000-Dec-06 17:04
Here is a current snapshot of the bug.

Project: Python
Category: Library
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Submitted by: Nobody
Assigned to : Nobody
Summary: math.modf, math.floor, math.ceil give misleading result

Details: c=64
e=1.0/3.0
x=pow(c,e)        We are calculating the cube root of 64
x
4.0                   ...which is 4
math.modf(x)
(1.0,3.0)           This is misleading.  Should be (0.0,4.0) 
This happens in version 1.5.2 on my 486.  

Note the following
y=4.0
math.modf(y)
(0.0,4.0)           All as it should be.

Follow-Ups:

Date: 2000-Dec-06 17:27
By: gvanrossum

Comment:
Trying this in Python 2.0, I get this:

>>> c=64
>>> e=1.0/3.0
>>> x=pow(c,e)
>>> x
3.9999999999999996
>>> import math
>>> math.modf(x)
(0.99999999999999956, 3.0)
>>> e
0.33333333333333331
>>> 

In other words, e is a little less than 1/3, and x is a little less than 4.
In Python 1.5.2, these values are printed after some rounding, which caused the confusion.

See also the entry on Floating Point in the Python 2.0 FAQ:

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

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=124791&group_id=5470