[Tim]
> >>> cmath.phase(complex(0.0, 0.0))
> 0.0
> >>> cmath.phase(complex(-0.0, 0.0))
> 3.141592653589793
> >>> cmath.phase(complex(0.0, -0.0))
> -0.0
> >>> cmath.phase(complex(-0.0, -0.0))
> -3.141592653589793

[Marco Sulla <marco.sulla.pyt...@gmail.com>]
> Whoa. I'm quite curious about why. ...

There's no compelling reason to be had. They just made stuff up. In
this case, it's apparently motivated by "OK, if the imaginary part is
near 0, the number is very close to the x axis, and the sign of the
real part determines on which side. Then we'll take the limit as the
imaginary part approaches zero from the direction of its own sign."
Why? Why not! The sign of a zero has no inherent "meaning".

Note that these non-made-up results show that limiting process in action:

>>> pr = 1.0   # abs(real part)
>>> pi = 1e-10  # abs(imaginary part)
>>> cmath.phase(complex(pr, pi))
1e-10
>>> cmath.phase(complex(-pr, pi))
3.141592653489793
>>> cmath.phase(complex(pr, -pi))
-1e-10
>>> cmath.phase(complex(-pr, -pi))
-3.141592653489793

Make |pi| ever smaller, and the limits are clearly what the original
example showed.

I'll leave off (this really has nothing to do with Python, as nobody
is volunteering to do anything in this area) with this link to more
details than anyone can bear ;-)

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1399.htm

As it says about two-argument complex functions:

"""
Since there are four components in (a+I*b)*(c+I*d), and each component
can have four classifications, there are 4**4 or 256 cases to
consider.  The same is true for divide.  That is why the reference
implementation is so large.
"""

Their "four classifications" is understating it. They have in mind
NaN, Inf, 0, or finite non-zero, but subdivisions within those
classifications can breed even more special cases.

"Bottomless pit."
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VG26YGL2QFPEDWF7AASGT4ZI2EVXZNGR/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to