Computing the square root of complex number in a stable manner

Solution 1:

You must first study the concept of catastrophic cancellation. This occurs when we subtract approximations of two real numbers that are relatively close to each other. This is a basic but extremely important point in numerical analysis. You will find very brief summary and analysis in this answer

Returning to the problem of complex square roots. The expression $$u = \sqrt{\frac{\sqrt{x^2+y^2}+x}{2}} $$ will not experience catastrophic cancellation as long as $x>0$. Afterwards, you can compute $v$ using $v = \frac{y}{2u}$.

However, the expression for $u$ will (almost certainly) experience catastrophic cancellation when $x<0$ and $y$ is nearly zero. If $x<0$, then you first compute $$v =\sqrt{\frac{\sqrt{x^2+y^2}-x}{2}}$$ and then $$u = \frac{y}{2v}.$$


If your complex number is given in polar form, then polar form of the square root can be computed using the naive formula. However, obtaining the polar form from the standard form in a reliable manner is not trivial.