Skip to content

math.MutableComplex.Class.MutableComplex

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

dsp-collection / math/MutableComplex / MutableComplex

Class: MutableComplex

A mutable complex number.

This class implementation for storing complex numbers is optimized for high performance computation. Immutability is sacrificed in favor of fast in-place operations.

When mutability is no longer needed, a MutableComplex can be type cast into an immutable Complex.

Extends

Constructors

Constructor

new MutableComplex(re?, im?): MutableComplex;

Constructs a MutableComplex.

Parameters

re?

number = 0

The real part. Optional. Default is 0.

im?

number = 0

The imaginary part. Optional. Default is 0.

Returns

MutableComplex

Overrides

Complex.constructor

Properties

Property Modifier Type Description Overrides Inherited from
im public number Mutable imaginary part of the complex number. Complex.im -
re public number Mutable real part of the complex number. Complex.re -
I readonly Complex The imaginary unit i. - Complex.I
INFINITY readonly Complex A Complex representing "+Infinity + Infinity i" - Complex.INFINITY
NaN readonly Complex A Complex representing "NaN + NaN i" - Complex.NaN
ONE readonly Complex A Complex representing 1. - Complex.ONE
TWO readonly Complex A Complex representing 2. - Complex.TWO
ZERO readonly Complex A Complex representing 0. - Complex.ZERO

Methods

abs()

abs(): number;

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

Returns

number

Inherited from

Complex.abs


add()

add(x): Complex;

Returns this + x;

Parameters

x

Complex

Returns

Complex

Inherited from

Complex.add


addReal()

addReal(x): Complex;

Returns this + x;

Parameters

x

number

Returns

Complex

Inherited from

Complex.addReal


addRealTo()

addRealTo(x): void;

Mutates this MutableComplex by adding a real number.

Parameters

x

number

Returns

void


addTo()

addTo(x): void;

Mutates this MutableComplex by adding a Complex.

Parameters

x

Complex

Returns

void


arg()

arg(): number;

Returns the argument (angle).

Returns

number

Inherited from

Complex.arg


conj()

conj(): Complex;

Returns the conjugate.

Returns

Complex

Inherited from

Complex.conj


div()

div(x): Complex;

Returns this / x;

Parameters

x

Complex

Returns

Complex

Inherited from

Complex.div


divBy()

divBy(x): void;

Mutates this MutableComplex by dividing by a Complex.

Parameters

x

Complex

Returns

void


divByReal()

divByReal(x): void;

Mutates this MutableComplex by dividing by a real number.

Parameters

x

number

Returns

void


divReal()

divReal(x): Complex;

Returns this / x;

Parameters

x

number

Returns

Complex

Inherited from

Complex.divReal


equals()

equals(x): boolean;

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

Parameters

x

Complex

Returns

boolean

Inherited from

Complex.equals


exp()

exp(): Complex;

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

Returns

Complex

Inherited from

Complex.exp


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

Inherited from

Complex.fuzzyEquals


isFinite()

isFinite(): boolean;

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

Returns

boolean

Inherited from

Complex.isFinite


isInfinite()

isInfinite(): boolean;

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

Returns

boolean

Inherited from

Complex.isInfinite


isNaN()

isNaN(): boolean;

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

Returns

boolean

Inherited from

Complex.isNaN


log()

log(): Complex;

Returns the natural logarithm (base e).

Returns

Complex

Inherited from

Complex.log


mul()

mul(x): Complex;

Returns this * x;

Parameters

x

Complex

Returns

Complex

Inherited from

Complex.mul


mulBy()

mulBy(x): void;

Mutates this MutableComplex by multiplying a Complex.

Parameters

x

Complex

Returns

void


mulByReal()

mulByReal(x): void;

Mutates this MutableComplex by multiplying a real number.

Parameters

x

number

Returns

void


mulReal()

mulReal(x): Complex;

Returns this * x;

Parameters

x

number

Returns

Complex

Inherited from

Complex.mulReal


neg()

neg(): Complex;

Returns the negation (-this).

Returns

Complex

Inherited from

Complex.neg


pow()

pow(x): Complex;

Returns this raised to the power of x.

Parameters

x

Complex

Returns

Complex

Inherited from

Complex.pow


powInt()

powInt(x): Complex;

Returns this raised to the power of x.

Parameters

x

number

Returns

Complex

Inherited from

Complex.powInt


powReal()

powReal(x): Complex;

Returns this raised to the power of x.

Parameters

x

number

Returns

Complex

Inherited from

Complex.powReal


reciprocal()

reciprocal(): Complex;

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

Returns

Complex

Inherited from

Complex.reciprocal


set()

set(x): void;

Sets this MutableComplex to the value of another Complex.

Parameters

x

Complex

Returns

void


setDiv()

setDiv(
   re1, 
   im1, 
   re2, 
   im2): void;

Sets this MutableComplex to (re1, im1) / (re2, im2).

Parameters

re1

number

im1

number

re2

number

im2

number

Returns

void


setExpj()

setExpj(arg): void;

Sets this MutableComplex to e^(j * arg) (length 1 and argument arg).

Parameters

arg

number

Returns

void


setMul()

setMul(
   re1, 
   im1, 
   re2, 
   im2): void;

Sets this MutableComplex to (re1, im1) * (re2, im2).

Parameters

re1

number

im1

number

re2

number

im2

number

Returns

void


setPolar()

setPolar(abs, arg): void;

Sets this MutableComplex using polar coordinates.

Parameters

abs

number

arg

number

Returns

void


setReIm()

setReIm(re, im?): void;

Sets this MutableComplex to (re, im).

Parameters

re

number

im?

number = 0

Returns

void


sqr()

sqr(): Complex;

Returns the square.

Returns

Complex

Inherited from

Complex.sqr


sqrt()

sqrt(): Complex;

Returns one of the two square roots.

Returns

Complex

Inherited from

Complex.sqrt


sub()

sub(x): Complex;

Returns this - x;

Parameters

x

Complex

Returns

Complex

Inherited from

Complex.sub


subFrom()

subFrom(x): void;

Mutates this MutableComplex by subtracting a Complex.

Parameters

x

Complex

Returns

void


subReal()

subReal(x): Complex;

Returns this - x;

Parameters

x

number

Returns

Complex

Inherited from

Complex.subReal


subRealFrom()

subRealFrom(x): void;

Mutates this MutableComplex by substracting a real number.

Parameters

x

number

Returns

void


toNumber()

toNumber(eps): number;

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

Parameters

eps

number

Returns

number

Inherited from

Complex.toNumber


toString()

toString(): string;

Returns a string representing the complex number.

Returns

string

Inherited from

Complex.toString


divFromReal()

static divFromReal(x, y): Complex;

Returns x / y;

Parameters

x

number

y

Complex

Returns

Complex

Inherited from

Complex.divFromReal


expj()

static expj(arg): MutableComplex;

Creates a MutableComplex of length 1 and argument arg.

Parameters

arg

number

Returns

MutableComplex

Overrides

Complex.expj


fromComplex()

static fromComplex(x): MutableComplex;

Creates a MutableComplex from a Complex.

Parameters

x

Complex

Returns

MutableComplex


fromPolar()

static fromPolar(abs, arg): MutableComplex;

Creates a MutableComplex from polar coordinates.

Parameters

abs

number

arg

number

Returns

MutableComplex

Overrides

Complex.fromPolar


subFromReal()

static subFromReal(x, y): Complex;

Returns x - y;

Parameters

x

number

y

Complex

Returns

Complex

Inherited from

Complex.subFromReal

Clone this wiki locally