Represents a numerical complex value backed by decimal.js components.

remarks

This class is a numerical helper used by algorithms such as polynomial root solving. It is distinct from Nerdamer's symbolic complex expressions: it does not parse expressions, carry symbolic structure, or implement branch-sensitive transcendental functions. Component arithmetic follows the active global decimal.js precision. Arithmetic methods return new Complex objects rather than modifying the receiver. The Complex.re and Complex.im fields are public, however, so callers can reassign components directly.

Members

abs(): DecimalMethod

Computes the modulus sqrt(re^2 + im^2).

Returns

Decimal — A new Decimal containing the nonnegative magnitude.

absSquared(): DecimalMethod

Returns the squared modulus re^2 + im^2 without computing a square root.

Returns

Decimal

add(other: Complex): ComplexMethod

Adds another complex value component-wise.

Parameters

NameTypeDescription
otherComplexComplex value to add.

Returns

Complex — A new complex sum.

conjugate(): ComplexMethod

Returns the complex conjugate re - im*i.

Returns

Complex — A new complex value with the imaginary component negated.

Complex(re: number | Decimal, im: number | Decimal): ComplexConstructor

Creates a numerical complex value.

remarks

Existing Decimal components are retained by reference; numeric inputs are converted to new Decimal values. decimal.js arithmetic itself returns new Decimal objects.

Parameters

NameTypeDescription
renumber | DecimalReal component.
imnumber | DecimalImaginary component; defaults to zero.

Returns

Complex

create(re: number | Decimal, im: number | Decimal): ComplexMethod

Creates a numerical complex value from Decimal or native-number components.

Parameters

NameTypeDescription
renumber | DecimalReal component.
imnumber | DecimalImaginary component; defaults to zero.

Returns

Complex — A new Complex value.

div(other: Complex): ComplexMethod

Divides this complex value by another using the standard rectangular formula.

remarks

Division rejects an exactly zero squared modulus. No numerical tolerance is applied at this arithmetic layer; iterative algorithms are responsible for choosing any tolerance appropriate to their convergence logic.

throws

core!DivisionByZeroError Thrown when both components of other are exactly zero at the current Decimal value.

Parameters

NameTypeDescription
otherComplexComplex divisor.

Returns

Complex — A new complex quotient.

im: DecimalProperty

Imaginary component.

mul(other: Complex): ComplexMethod

Multiplies two rectangular complex values.

Parameters

NameTypeDescription
otherComplexComplex factor.

Returns

Complex — A new complex product.

neg(): ComplexMethod

Returns the additive inverse of this complex value.

Returns

Complex — A new complex value with both components negated.

re: DecimalProperty

Real component.

reciprocal(): ComplexMethod

Returns the multiplicative inverse of this complex value.

throws

core!DivisionByZeroError Thrown when both components are exactly zero at the current Decimal value.

Returns

Complex — A new complex value equal to 1 / this.

scale(s: number | Decimal): ComplexMethod

Multiplies both complex components by a real scalar.

Parameters

NameTypeDescription
snumber | DecimalDecimal or native-number scale factor.

Returns

Complex — A new scaled complex value.

sub(other: Complex): ComplexMethod

Subtracts another complex value component-wise.

Parameters

NameTypeDescription
otherComplexComplex value to subtract.

Returns

Complex — A new complex difference.