Calculating the complex square root requires some care. The naive method may encounter overflow, underflow, or loss of precision due to the intermediate floating point results. A simple remedy[1] is:

Then using w,

Usage

require('complex-sqrt')( a, b [, result] )

Calculates sqrt(a + ib) and returns a two-element JS array with the real and imaginary components of the answer.

result is an optional to-element Array or typed array into which output is passed, if provided.

Example

var sqrt =require('complex-sqrt');

var result =sqrt(1,2);

// result = [ 1.272019649514069, 0.7861513777574233 ]