Complex Number for JavaScript


Complex Number for JavaScript

<script src="math-complex.js" charset="UTF-8"></script>
var cplx = Math.Complex,    // for convenience 
= cplx(0, 1);
j.mul(Math.PI).exp() + '';  // -1+1.2246063538223773e-16i 
// ditto 
Math.Complex.exp(cplx(0, Math.PI));

This module implements complex number arithmetics. Basic arithmetics + All arithmetic functions in Math are supported.

Constructor. im === 0 if omitted.

var z = Math.Complex(1,2);
z.re === 1;
z.im === 2;

Constructor in polar form.

In the followin example z is a complex number object. Unless otherwise stated, all methods below return complex number objects.

returns true if z equals z1, false otherwise.

The opposite of z.eq( *z1 *)

returns the absolute value in Number.

returns the argument in Number.

returns - z

returns the conjugate.

Math.Complex(re, im).con().eq(Math.Complex(re, -im));

returns the norm in Number.

z + z1. z1 can be either complex number or real number If z1 is a real number (Number object, that is), it is automatically converted to complex number before the calculation. This applies to all binary methods.

z - z1

z * z1

z / z1

Copmplex version of Math.exp( z ) .

Copmplex version of Math.log( z ) .

Copmplex version of Math.exp( z, z1 ) .

Copmplex version of Math.sin( z ) .

Copmplex version of Math.cos( z ) .

Copmplex version of Math.tan( z ) .

Copmplex version of Math.asin( z ) .

Copmplex version of Math.acos( z ) .

Copmplex version of Math.atan( z ) .

Copmplex version of Math.atan2( z, z1 ) .

All methods above can also be accessed in functional form which is handy with with.

// does not work in strict mode 
    console.log(atan2(1,1)) // { re: 0.7853981633974483, im: 0 }