Skip to content

math.Complex.Class.Complex

Christian d'Heureuse edited this page Jun 6, 2026 · 2 revisions

dsp-collection / math/Complex / Complex

Class: Complex

An immutable complex number.

Extended by

Constructors

Constructor

new Complex(re, im?): Complex;

Constructs a Complex.

Parameters

re

number

The real part.

im?

number = 0

The imaginary part. Optional. Default is 0.

Returns

Complex

Properties

Property Modifier Type Description
im readonly number Imaginary part of the complex number.
re readonly number Real part of the complex number.
I readonly Complex The imaginary unit i.
INFINITY readonly Complex A Complex representing "+Infinity + Infinity i"
NaN readonly Complex A Complex representing "NaN + NaN i"
ONE readonly Complex A Complex representing 1.
TWO readonly Complex A Complex representing 2.
ZERO readonly Complex A Complex representing 0.

Methods

abs()

abs(): number;

Returns the absolute value (magnitude, vector length, radius).

Returns

number


add()

add(x): Complex;

Returns this + x;

Parameters

x

Complex

Returns

Complex


addReal()

addReal(x): Complex;

Returns this + x;

Parameters

x

number

Returns

Complex


arg()

arg(): number;

Returns the argument (angle).

Returns

number


conj()

conj(): Complex;

Returns the conjugate.

Returns

Complex


div()

div(x): Complex;

Returns this / x;

Parameters

x

Complex

Returns

Complex


divReal()

divReal(x): Complex;

Returns this / x;

Parameters

x

number

Returns

Complex


equals()

equals(x): boolean;

Returns true if this complex number is exactly equal to another.

Parameters

x

Complex

Returns

boolean


exp()

exp(): Complex;

Returns the exponential function. (The Euler's number e raised to the power of this complex number).

Returns

Complex


fuzzyEquals()

fuzzyEquals(x, eps): boolean;

Returns true if the real and imaginary parts of the two numbers do not differ more than eps.

Parameters

x

Complex

eps

number

Returns

boolean


isFinite()

isFinite(): boolean;

Returns true if the real and imaginary parts are both finite.

Returns

boolean


isInfinite()

isInfinite(): boolean;

Returns true if the real or the imaginary part is infinite (positive or negative).

Returns

boolean


isNaN()

isNaN(): boolean;

Returns true if the real part or the imaginary part is NaN.

Returns

boolean


log()

log(): Complex;

Returns the natural logarithm (base e).

Returns

Complex


mul()

mul(x): Complex;

Returns this * x;

Parameters

x

Complex

Returns

Complex


mulReal()

mulReal(x): Complex;

Returns this * x;

Parameters

x

number

Returns

Complex


neg()

neg(): Complex;

Returns the negation (-this).

Returns

Complex


pow()

pow(x): Complex;

Returns this raised to the power of x.

Parameters

x

Complex

Returns

Complex


powInt()

powInt(x): Complex;

Returns this raised to the power of x.

Parameters

x

number

Returns

Complex


powReal()

powReal(x): Complex;

Returns this raised to the power of x.

Parameters

x

number

Returns

Complex


reciprocal()

reciprocal(): Complex;

Returns the reciprocal (1 / this, multiplicative inverse).

Returns

Complex


sqr()

sqr(): Complex;

Returns the square.

Returns

Complex


sqrt()

sqrt(): Complex;

Returns one of the two square roots.

Returns

Complex


sub()

sub(x): Complex;

Returns this - x;

Parameters

x

Complex

Returns

Complex


subReal()

subReal(x): Complex;

Returns this - x;

Parameters

x

number

Returns

Complex


toNumber()

toNumber(eps): number;

Returns the real part. Verifies that abs(im) <= eps or abs(im) <= abs(re) * eps.

Parameters

eps

number

Returns

number


toString()

toString(): string;

Returns a string representing the complex number.

Returns

string


divFromReal()

static divFromReal(x, y): Complex;

Returns x / y;

Parameters

x

number

y

Complex

Returns

Complex


expj()

static expj(arg): Complex;

Creates a Complex of length 1 and argument arg.

Parameters

arg

number

Returns

Complex


fromPolar()

static fromPolar(abs, arg): Complex;

Creates a Complex from polar coordinates.

Parameters

abs

number

arg

number

Returns

Complex


subFromReal()

static subFromReal(x, y): Complex;

Returns x - y;

Parameters

x

number

y

Complex

Returns

Complex

Clone this wiki locally