Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Prev Next


Complex square root.


void csqrt();
cmplx z, w;

csqrt(&z, &w);


If z = x + iy,  r = |z|, then

Im w  =  [ (r - x)/2 ]   ,

Re w  =  y / 2 Im w.

Note that -w is also a square root of z. The root chosen is always in the upper half plane.

Because of the potential for a cancellation error in r - x, the result is sharpened by doing a Heron iteration (see sqrt) in complex arithmetic.


                      Relative error:
arithmetic   domain     # trials      peak         rms
    DEC       -10,+10     25000       3.2e-17     9.6e-18
    IEEE      -10,+10    100000       3.2e-16     7.7e-17


var x = {"r":4.5,"i":3.14} ;
var a = cephes.csqrt(x);

returns a, complex object of schema
"r" : double,
"i": double