Problem calling math.cos()
Roy Smith
roy at panix.com
Sat Apr 22 16:37:53 EDT 2006
In article <mailman.4892.1145736928.27775.python-list at python.org>,
"Tim Peters" <tim.peters at gmail.com> wrote:
> [Robert Kern]
> > ...
> > ph3 = math.atan( ac3.imag / ac3.real )
> > ...
>
> Don't do that: atan2 is the correct way to compute the angle, because
> the signs of both inputs are needed to determine the correct quadrant.
> So do:
>
> ph3 = math.atan2(ac3.imag, ac3.real)
>
> instead.
I certainly agree about using atan2() instead of atan(), but I'm surprised
there's not an easier way to get the phase of a complex, just like abs()
gives you the modulus. I can see why you wouldn't want to pollute the
global namespace with another built-in just for this purpose, but surely a
complex.phase property wouldn't hurt?
More information about the Python-list
mailing list