How to get principal argument of complex number from complex plane?

The principal value of $\tan^{-1}\theta$ is always between $-\frac{\pi}2$ and $\frac{\pi}2$. The principal value of $\arg z$, on the other hand, is always in the interval $(-\pi,\pi]$. Thus, for $z$ in the first quadrant it’s between $0$ and $\frac{\pi}2$; for $z$ in the second quadrant it’s between $\frac{\pi}2$ and $\pi$; for $z$ in the third quadrant it’s between $-\frac{\pi}2$ and $-\pi$; and for $z$ in the fourth quadrant it’s between $0$ and $-\frac{\pi}2$. This means that the $\tan^{-1}$ function gives you the correct angle only when $z$ is in the first and fourth quadrants.

When $z$ is in the second quadrant, you have to find an angle between $\frac{\pi}2$ and $\pi$ that has the same tangent as the angle $\theta$ returned by the $\tan^{-1}$ function, which satisfies $-\frac{\pi}2<\theta\le 0$. The tangent function is periodic with period $\pi$, so $\tan(\theta+\pi)=\tan\theta$, and $$\frac{\pi}2=-\frac{\pi}2+\pi<\theta+\pi\le0+\pi=\pi\;,$$ so $\theta+\pi$ is indeed in the second quadrant.

When $z$ is in the third quadrant, you have to find an angle between $-\pi$ and $-\frac{\pi}2$ that has the same tangent as the angle $\theta$ returned by the $\tan^{-1}$ function, which satisfies $0\le\theta<\frac{\pi}2$. This time subtracting $\pi$ does the trick: $\tan(\theta-\pi)=\tan\theta$, and

$$-\pi=0-\pi<\theta-\pi<\frac{\pi}2-\pi=-\frac{\pi}2\;.$$

There’s just one slightly tricky bit. If $z$ is a negative real number, should you consider it to be in the second or in the third quadrant? The tangent is $0$, so the $\tan^{-1}$ function will return $0$. If you treat $z$ as being in the second quadrant, you’ll add $\pi$ and get a principal argument of $\pi$. If instead you treat $z$ as being in the third quadrant, you’ll subtract $\pi$ and get a principal argument of $-\pi$. But by definition the principal argument is in the half-open interval $(-\pi,\pi]$, which does not include $-\pi$; thus, you must take $z$ to be in the second quadrant and assign it the principal argument $\pi$.


One of the most important functions in analysis is the argument function $${\rm arg}:\quad \dot{\mathbb R}^2\to {\mathbb R}/(2\pi{\mathbb Z}),\qquad (x,y)\mapsto {\rm arg}(x,y)\ ,$$ resp. $${\rm arg}:\quad \dot{\mathbb C}\to {\mathbb R}/(2\pi{\mathbb Z}),\qquad z\mapsto {\rm arg}z\ ,$$ where the dot indicates that the origin is removed.

Intuitively ${\rm arg}(x,y)$ denotes the polar angle of $(x,y)$ "up to multiples of $2\pi$". For "local" considerations there are continuous real-valued ("numerical") representants of ${\rm arg}$; but these are defined only in a suitable part of $\dot{\mathbb R}^2$. In particular the principal value $${\rm Arg}:\quad {\mathbb R}^2\setminus\{(x,0)|x\leq0\}\ \to {\mathbb R},\qquad (x,y)\mapsto {\rm Arg}(x,y)$$ is defined on the $(x,y)$-plane slit up along the negative $x$-axis. It has the simple symmetry property ${\rm Arg}\bar z=-{\rm Arg}z$, and for $x>0$ it is given by $${\rm Arg}(x,y)=\arctan{y\over x}\qquad(x>0)\ .$$ Note that the ${\rm arg}$ function has a well defined gradient given by $$\nabla{\rm arg}(x,y)=\Bigl({-y\over x^2+y^2},{x\over x^2+y^2}\Bigr)\qquad\bigl((x,y)\ne(0,0)\bigr)\ .$$


I've come up with this recipe for principal argument. It saves messing around adding or subtracting $\pi$.

$$\text{Arg} (z) = n\ \text{cos}^{-1} \left(\frac{x}{z}\right)$$

in which n = 1 if y ≥ 0 but n = -1 if y < 0.

I've tried to 'automate' the value of n, but the best I can do is

$$\text{Arg} (z) = \frac{y}{|y|}\ \text{cos}^{-1} \left(\frac{x}{z}\right).$$

Unfortunately this fails for y = 0 (real z), so the y = 0 case would still have to be catered for separately.

Edit: A very ugly self-contained recipe would be

$$\text{Arg} (z) = \text{sgn}\left(\text{sgn}(y) + \frac{1}{2}\right)\ \text{cos}^{-1} \left(\frac{x}{z}\right).$$