floor() function and mathematical integers

Tim Peters tim.one at home.com
Thu May 24 16:00:30 EDT 2001


[Tim]
> The mathematical definition of floor(M * B**E) for non-negative
> integers M, B and E is M*B**E, and math.floor() does rigorously
> honor that.  You want something floating point doesn't address at all.

[Bengt Richter]
> # Well, rigorously within limits ;-) :

Your examples show only roundoff error in long->float conversion.  floor()
has nothing to do with that.

> ...
> BTW, the problem here is not in math.floor(), it's that the theoretical
> value is not preserved in the conversion to float before floor() is
> called.

Bingo.

> If you restrict M to 53 bits of precision, B to a value of two,
> and E to its almost 10-bit range, then I think what you say is true,
> which I guess is what you meant ;-)

In context, I meant math.floor(x) returns the mathematically correct result
for every non-zero float x:  it introduces no errors.  So when people
stumble into something like this:

>>> x = 32.05
>>> import math
>>> y = x * 100
>>> print y
3205.0
>>> print math.floor(y)
3204.0
>>>

the last thing they should be looking at is the floor <wink>.





More information about the Python-list mailing list