PEP 238 (revised)

Tim Peters tim.one at home.com
Fri Jul 27 19:40:04 EDT 2001


[James Logajan]
> Obviously I'm not familiar with IEEE-754 arithmetic. Is the intent to
> do IEEE-754 FP arithmetic on all platforms when FP is involved?

Python has no 754 story today, and nobody has written a 754 PEP, so it's not
likely to grow one soon.  I believe the NumPy people are pursuing this more
aggressively, though (it's important to many of them, yet despised by others
of them -- sound familiar <wink>?).

> What if the underlying hardware isn't conformant?

Python doesn't make any explicit promises about fp behavior; it does try to
pass on whatever fp behavior the platform C exhibits; unfortunately for
people who care, C89 has no 754 story either, so what you see for endcase
behavior from Python varies almost as much across platforms as C does.  Most
people never notice because their fp computations are unexceptional, and
then the x-platform reproducibility in Python is much higher than in C (the
way fp is implemented in Python checkmates C optimizers, effectively wiping
out platform variations due to platform-specific availability of assorted
extended-precision HW gimmicks).

> Sorry, since this seems to be going through the python-list mailing
> list, the "References:" header isn't being included for some reason,
> so I missed the introduction of  IEEE-754 into the discussion. Can't
> find it mentioned in that PEP (unless it is in another PEP or is
> documented elsewhere).

It's in relation to this part of PEP 238:

    The correct work-around is subtle: casting an argument to float()
    is wrong if it could be a complex number; adding 0.0 to an
    argument doesn't preserve the sign of the argument if it was minus
    zero.  The only solution without either downside is multiplying an
    argument (typically the first) by 1.0.  This leaves the value and
    sign unchanged for float and complex, and turns int and long into
    a float with the corresponding value.

Somebody asked why *1.0 is better than +0.0 as a general way to coerce to
float; if you're on 754 hardware (as most people are now), the explanation
given there is correct.





More information about the Python-list mailing list