Complex
Represents a numerical complex value backed by decimal.js components.
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(): DecimalMethodComputes the modulus sqrt(re^2 + im^2).
Returns
Decimal — A new Decimal containing the nonnegative magnitude.
absSquared(): DecimalMethodReturns the squared modulus re^2 + im^2 without computing a square root.
Returns
Decimal
Adds another complex value component-wise.
Parameters
| Name | Type | Description |
|---|---|---|
other | Complex | Complex value to add. |
Returns
Complex — A new complex sum.
conjugate(): ComplexMethodReturns the complex conjugate re - im*i.
Returns
Complex — A new complex value with the imaginary component negated.
Complex(re: number | Decimal, im: number | Decimal): ComplexConstructorCreates a numerical complex value.
Existing Decimal components are retained by reference; numeric inputs are converted to
new Decimal values. decimal.js arithmetic itself returns new Decimal objects.
Parameters
| Name | Type | Description |
|---|---|---|
re | number | Decimal | Real component. |
im | number | Decimal | Imaginary component; defaults to zero. |
Returns
create(re: number | Decimal, im: number | Decimal): ComplexMethodCreates a numerical complex value from Decimal or native-number components.
Parameters
| Name | Type | Description |
|---|---|---|
re | number | Decimal | Real component. |
im | number | Decimal | Imaginary component; defaults to zero. |
Returns
Complex — A new Complex value.
Divides this complex value by another using the standard rectangular formula.
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.
core!DivisionByZeroError
Thrown when both components of other are exactly zero at the current Decimal value.
Parameters
| Name | Type | Description |
|---|---|---|
other | Complex | Complex divisor. |
Returns
Complex — A new complex quotient.
im: DecimalPropertyImaginary component.
Multiplies two rectangular complex values.
Parameters
| Name | Type | Description |
|---|---|---|
other | Complex | Complex factor. |
Returns
Complex — A new complex product.
neg(): ComplexMethodReturns the additive inverse of this complex value.
Returns
Complex — A new complex value with both components negated.
re: DecimalPropertyReal component.
reciprocal(): ComplexMethodReturns the multiplicative inverse of this complex value.
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): ComplexMethodMultiplies both complex components by a real scalar.
Parameters
| Name | Type | Description |
|---|---|---|
s | number | Decimal | Decimal or native-number scale factor. |
Returns
Complex — A new scaled complex value.
Subtracts another complex value component-wise.
Parameters
| Name | Type | Description |
|---|---|---|
other | Complex | Complex value to subtract. |
Returns
Complex — A new complex difference.
