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

Details

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 manage symbolic principal-branch simplification. Its logarithm and power\n * use the numerical principal branch. 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

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.

Details

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.

Details

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.

Errors

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.

exp(): ComplexMethod

Computes exp(re + im*i) without losing Decimal precision.

Returns

Complex

im: DecimalProperty

Imaginary component.

log(): ComplexMethod

Principal logarithm, with its argument in (-pi, pi].

Returns

Complex

minus(other: Complex): ComplexMethod

Subtracts another complex value component-wise.

Parameters

NameTypeDescription
otherComplexComplex value to subtract.

Returns

Complex — A new complex difference.

neg(): ComplexMethod

Returns the additive inverse of this complex value.

Returns

Complex — A new complex value with both components negated.

plus(other: Complex): ComplexMethod

Adds another complex value component-wise.

Parameters

NameTypeDescription
otherComplexComplex value to add.

Returns

Complex — A new complex sum.

pow(exponent: Complex): ComplexMethod

Principal complex power exp(exponent * log(this)).

Parameters

NameTypeDescription
exponentComplex—

Returns

Complex

re: DecimalProperty

Real component.

reciprocal(): ComplexMethod

Returns the multiplicative inverse of this complex value.

Errors

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.

times(other: Complex): ComplexMethod

Multiplies two rectangular complex values.

Parameters

NameTypeDescription
otherComplexComplex factor.

Returns

Complex — A new complex product.