TITLE: How to figure out the Argument of complex number?
QUESTION [16 upvotes]: I have the absolute value of complex number ,
$$ r = |z| = \sqrt{x^2 + y^2}$$
when $z = x + iy$ is a complex number.
How can I calculate the Argument of $z$? 
Thanks.

REPLY [7 votes]: Note that the "answer" $arctan(y/x)$ is just wrong. To see it check out the example $-1-i$: $\arctan(-1/-1) = 45°$ but correct would be $225°$. And this is not just a problem with the definition of the range of the argument.
The correct answer is given by Wikipedia:
$\varphi = \arg(z) =
\begin{cases}
\arctan(\frac{y}{x}) & \mbox{if } x > 0 \\
\arctan(\frac{y}{x}) + \pi & \mbox{if } x < 0  \mbox{ and } y \ge 0\\
\arctan(\frac{y}{x}) - \pi & \mbox{if } x < 0 \mbox{ and } y < 0\\
\frac{\pi}{2} & \mbox{if } x = 0 \mbox{ and } y > 0\\
-\frac{\pi}{2} & \mbox{if } x = 0 \mbox{ and } y < 0\\
\mbox{indeterminate } & \mbox{if } x = 0 \mbox{ and } y = 0.
\end{cases}$
Because of that many programming languages have the function $\operatorname{atan2}(y,x)$ which gives the above correct argument for $x+iy$.