complex-sqrt

1.1.1 • Public • Published

complex-sqrt

Build Status npm version Dependency Status

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:

Complex w

Then using w,

Complex sqrt

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

Package Sidebar

Install

npm i complex-sqrt

Weekly Downloads

1

Version

1.1.1

License

MIT

Last publish

Collaborators

  • rreusser
  • planeshifter
  • mikolalysenko