PEP 238 (revised)

Tim Peters tim.one at home.com
Fri Jul 27 15:43:24 EDT 2001


[Guido van Rossum]
> 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.

[Andrei Kulakov]
> When is 0 different from -0?

[James Logajan]
> When doing ones-complement arithmetic. Not too many machines use that
> anymore, and the ones that did (or do) should have comparison logic to
> consider -0 == 0. The CDC Cyber series used ones-complement.

The issue in context is about floats, and the sign bit of 0.0 follows very
specific rules under standard IEEE-754 arithmetic.  Multiplying by 1.0
preserves the sign of a 754 zero, but adding 0.0 (of either sign) may not;
so adding 0.0 as a means to convert to float is wrong under 754 arithmetic
rules, albeit subtly wrong.





More information about the Python-list mailing list