raw code

Complex Numbers in JavaScript

Robert Eisele

Complex numbers sound complex, but in fact they are the most natural numbers - even if the name is a bit misleading. When extending the natural numbers to integers, to rational numbers, to real numbers and finally to complex numbers; it's the first field in which every operation is well defined.

Complex numbers have a wide vareity of applications, like calculation of AC voltage, representation of rotations in 2D, Discrete Fourier Transform, complex geometry and even Riemann hypothesis involve complex numbers. That's why I have written Complex.js to make work with complex numbers an easy task in JavaScript.

Download Complex.js

The library is well tested and contains a lot of functions, which try to overcome numerical imprecision and are implemented with performance in mind. To make the API more robust, every operation returns a new instance of the complex class. New JavaScript engines do a really good job on this and immutable functions are really fast nowadays.

Complex Numbers Calculator

Examples:
123+4i div 4.33
123.345-i div 3.1112

Simple Complex Numbers Example

var Complex = require('complex.js');

var c = new Complex("99.3+8i");
c.mul({re: 3, im: 9}).div(4.9).sub(3, 2);