PEP 238 (revised)

Guido van Rossum guido at python.org
Fri Jul 27 15:59:16 EDT 2001


James Logajan <JamesL at Lugoj.Com> writes:

> Andrei Kulakov wrote:
> > 
> > Guido van Rossum wrote:
> > >
> > >     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.
> > 
> > When is 0 different from -0?
> 
> 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.

IEEE 754, the floating point standard in use in virtually all current
hardware, mandates that -0.0 be distinguishable from 0.0, in order to
be able to represent the sign of degenerated underflow results.  (Or
so I understand, having been educated in IEEE 754 through numerous
discussions with Tim Peters, but not by reading the standard.  If I'm
wrong, Tim will surely correct me. :-)

I don't know of a portable way to generate -0.0 in Python; on my Linux
box, simply writing -0.0 does it, but not on my Windows box.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list