floor() function and mathematical integers
Bengt Richter
bokr at accessone.com
Fri May 25 09:37:39 CEST 2001
On Thu, 24 May 2001 16:00:30 -0400, "Tim Peters" <tim.one at home.com>
wrote:
[...]
>
>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
UIAM, zero is ok too :)
>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>.
>
>
This brings up the question of whether inexact print representations
of internal values (which themselves are exact, whether they represent
something else inexactly or not) should be flagged somehow by default.
>>> x = 32.05
>>> y = x * 100
>>> print y
3205.0
>>> y
3204.9999999999995
>>> print math.floor(y)
3204.0
>>>
There's no surprise about floor(y) from the long representation.
What if we got (e.g.)
>>> print y
3205.0'-
to indicate that the internal value is really less,
and 3205.0'+ if more ?
Obviously, you'd want to be able to suppress this, but for interactive
work, it would be less misleading and still fairly concise.
More information about the Python-list
mailing list