Complex numbers appear wherever magnitude and phase belong together: AC circuits, two-dimensional rotations, Fourier transforms, control systems, and fractal geometry. Complex.js brings that number system to JavaScript with a compact, immutable API and careful handling of numerical edge cases.
Every arithmetic operation returns a new Complex value, so calculations can be chained without mutating their inputs. Values may be created from real and imaginary parts, strings such as 3-4i, arrays, or polar coordinates. The library includes arithmetic, powers, roots, logarithms, trigonometric functions, inverse functions, and predicates for finite, infinite, and invalid values.
Complex Number Calculator
Complex.js accepts Cartesian input directly. Try integers, decimals, purely imaginary values, or expressions such as 33.982-4i. The calculator evaluates the selected operation as the fields change.
Calculating All Complex Roots
A nonzero complex number has exactly \(n\) distinct \(n\)-th roots. If \(z=r(\cos\theta+\mathbf{i}\sin\theta)\), they are
\[ w_k=\sqrt[n]{r}\left(\cos\frac{\theta+2\pi k}{n} +\mathbf{i}\sin\frac{\theta+2\pi k}{n}\right), \qquad k=0,1,\ldots,n-1. \]
Their arguments differ by \(2\pi/n\), so the roots form a regular polygon centered at the origin. The demo uses Complex.js for parsing, polar construction, and verification, then sends every root to Plot.js.
Using Complex.js
Install the package from npm and import it in a JavaScript project:
npm install complex.js import Complex from 'complex.js';
const z = new Complex('99.3+8i');
const result = z
.mul({ re: 3, im: 9 })
.div(4.9)
.sub(3, 2);
console.log(result.toString()); The original value in z is unchanged. This immutable behavior makes intermediate values predictable and allows expressions to mirror the mathematical calculation closely.