1.1.1 • Published 9 years ago
complex-sqrt v1.1.1
complex-sqrt
Floating point complex square root
Intro
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 ]
References
1 Press, William H. Numerical Recipes 3rd Edition: The Art of Scientific Computing. Cambridge University Press, 2007.
Credits
(c) 2015 Ricky Reusser. MIT License