Joe da Silva wrote:
OK, if you're happy that the code is correct ... I guess I just don't understand what the "a := Abs(Im(z)) / (2 * b)" statement does ...
That's easy. Let u+iv=\sqrt{x+iy}. Then (u+iv)^2=x+iy, i.e. y=2uv. (The code makes either a:=u and b:=v, or a:=v and b:=u, depending on the sign of x. Both "a := ..." assignments in the "if" statement are mathematically equivalent, but "SqRt ((a - Abs (Re (z))) / 2)" is too inexact if |y|<<|x|, since it computes a _small_ number as a difference of two _big_ numbers.)
Emil