trouble with complex numbers

Dr. Phillip M. Feldman pfeldman at
Wed Aug 5 22:16:31 CEST 2009

I am using Python 2.5, and most of the cmath functions are not yet available
in this version.  Thanks!


P.S. In your code, that should be x+= 0J

P.P.S. I wish that the documentation indicated anything that is new.

Christian Heimes-2 wrote:
> <snip>
> phase() has been added to Python 2.6 and 3.0. It's not available in 
> Python 2.5 and earlier. If you'd used cmath.phase() instead of the ugly 
> "from cmath import *" statement you'd have seen the correct error message.
> You can write your own phase() function. This function is mostly correct 
> unless either the real and/or the imag part is NaN or INF.
> from math import atan2
> def phase(z):
>      z += 1j # convert int, long, float to complex
>      return atan2(z.imag, z.real)
> -- 

View this message in context:
Sent from the Python - python-list mailing list archive at

More information about the Python-list mailing list