PEP 238 (revised)

Bengt Richter bokr at accessone.com
Sat Jul 28 00:51:08 EDT 2001


On Fri, 27 Jul 2001 19:59:16 GMT, Guido van Rossum <guido at python.org> wrote:
[...]
>
>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.
>
My gut feeling is that the symmetry of sign,magnitude numbers in IEEE754 is not good
when you are dealing with a mapping of the real axis to the unit circle. It doesn't
feel right to me, though probably it's not of much practical consequence.

But, speaking of the unit circle, UIAM Scheme has what appears to me to be a wart.
Functions that return angles apparently do so as values in (-pi,pi] rather than
[-pi,pi). To me that is a wart. Apparently Scheme got it from APL, and I still haven't
got to the local U library to see the referenced paper with the rationale. Mathematically,
you can't translate the interval by exactly pi and get a 2pi interval that includes zero!
It strikes me as weird to exclude zero and include 2pi. [1]

And look what that interval does if you want to turn it into a Python index range
for k steps of 2*pi/k. Adding pi to an angle puts it in (0,2pi] -- and unless you
turn 2pi into zero before doing angle*k//twopi, you will have an out of range index
when an arctangent returns pi instead of -pi.

My intel book says the pentium FPATAN instruction returns radians with a magnitude
*less than* pi, so whatever constant is defined as pi for purposes of returning it
from software, the choice must have been made there between +pi and -pi, or they just
return whatever the hardware provides, which would make the scheme documentation wrong
about the interval. It could either be called (-pi,pi) or [-pi,pi], but not half open.

Is this something that might be given a clean resolution in Python?
I.e., [-pi,pi) , IMHO ;-)

[1] Afterthought ... unless angles are being represented inversely somewhere,
i.e., as x when you want 2*pi/x.



More information about the Python-list mailing list