[Python-Dev] Caching float(0.0)

Tim Peters tim.peters at gmail.com
Wed Oct 4 06:42:04 CEST 2006

[skip at pobox.com]
> If C90 doesn't distinguish -0.0 and +0.0, how can Python?

With liberal applications of piss & vinegar ;-)

> Can you give a simple example where the difference between the two is apparent
> to the Python programmer?

Perhaps surprsingly, many (well, comparatively many, compared to none
....) people have noticed that the platform atan2 cares a lot:

>>> from math import atan2 as a
>>> z = 0.0  # postive zero
>>> m = -z   # minus zero
>>> a(z, z)   # the result here is actually +0.0
>>> a(z, m)
>>> a(m, z)    # the result here is actually -0.0
>>> a(m, m)

It work like that "even on Windows", and these are the results C99's
754-happy appendix mandates for atan2 applied to signed zeroes.  I've
even seen a /complaint/ on c.l.py that atan2 doesn't do the same when

z = 0.0

is replaced by

z = 0

That is, at least one person thought it was "a bug" that integer
zeroes didn't deliver the same behaviors.

Do people actually rely on this?  I know I don't, but given that more
than just 2 people have remarked on it seeming to like it, I expect
that changing this would break /some/ code out there.

BTW, on /some/ platforms all those examples trigger EDOM from the
platform libm instead -- which is also fine by C99, for
implementations ignoring C99's optional 754-happy appendix.

More information about the Python-Dev mailing list