Manuscript Documentation
v2026.12.0

@std/math/complex.ms#

Import each required symbol with import Name from "@std/math/complex.ms".

Complex Type#

A complex number with Float parts. It is plain data, so .clone() gives an independent copy. Arithmetic uses named methods: Complex(re: 1.0, im: 2.0).multiply(Complex(0.0, 1.0)) is -2+1i.

Manuscript
type Complex {
    re Float
    im Float
}

Complex.im#

The imaginary part, a Float that may be infinite or NaN.

Manuscript
im Float

Complex.re#

The real part, a Float that may be infinite or NaN.

Manuscript
re Float

Complex.abs#

Returns the magnitude sqrt(re^2 + im^2) without intermediate overflow.

Manuscript
fn abs() Float

Complex.acos#

Returns the principal inverse cosine, pi/2 minus the inverse sine.

Manuscript
fn acos() Complex

Complex.add#

Returns the sum, adding real and imaginary parts separately with Float rounding.

Manuscript
fn add(other Complex) Complex

Complex.asin#

Returns the principal inverse sine, -i * log(i*z + sqrt(1 - z^2)).

Manuscript
fn asin() Complex

Complex.atan#

Returns the principal inverse tangent, i/2 * (log(1 - iz) - log(1 + iz)).

Manuscript
fn atan() Complex

Complex.conjugate#

Returns the number with the imaginary part negated, so (1+2i) becomes (1-2i).

Manuscript
fn conjugate() Complex

Complex.cos#

Returns the complex cosine, cos(a)cosh(b) - sin(a)sinh(b)i for a+bi.

Manuscript
fn cos() Complex

Complex.cosh#

Returns the hyperbolic cosine.

Manuscript
fn cosh() Complex

Complex.divide#

Returns the quotient. Dividing by zero follows Float rules and gives infinities or NaN, never a fault. The divisor is scaled by its larger part to avoid overflow in the intermediate squares. Finite operands whose parts are near the Float range limits are first scaled by exact powers of two so the quotient keeps its precision. A numerator is scaled only enough to stay in range, so its smaller part survives.

Manuscript
fn divide(other Complex) Complex

Complex.exp#

Returns e raised to this number.

Manuscript
fn exp() Complex

Complex.is_infinite#

Reports whether either part is infinite and neither is NaN.

Manuscript
fn is_infinite() Bool

Complex.is_nan#

Reports whether either part is NaN.

Manuscript
fn is_nan() Bool

Complex.log#

Returns the principal natural logarithm; the imaginary part is the phase.

Manuscript
fn log() Complex

Complex.multiply#

Returns the product (a+bi)(c+di) = (ac-bd) + (ad+bc)i with Float rounding.

Manuscript
fn multiply(other Complex) Complex

Complex.negate#

Returns the number with both parts negated.

Manuscript
fn negate() Complex

Complex.phase#

Returns the angle in radians, from -pi through pi; the principal argument.

Manuscript
fn phase() Float

Complex.pow#

Returns this number raised to exponent. A zero base gives 1 for a zero exponent, 0 when the exponent’s real part is positive, and infinity otherwise. A real integer exponent of magnitude 100 or less multiplies out exactly; any other exponent uses exp(exponent * log(self)).

Manuscript
fn pow(exponent Complex) Complex

Complex.scale#

Returns the product with a real factor.

Manuscript
fn scale(factor Float) Complex

Complex.sin#

Returns the complex sine, sin(a)cosh(b) + cos(a)sinh(b)i for a+bi.

Manuscript
fn sin() Complex

Complex.sinh#

Returns the hyperbolic sine.

Manuscript
fn sinh() Complex

Complex.sqrt#

Returns the principal square root, with a non-negative real part.

Manuscript
fn sqrt() Complex

Complex.subtract#

Returns the difference, subtracting real and imaginary parts separately with Float rounding.

Manuscript
fn subtract(other Complex) Complex

Complex.tan#

Returns the complex tangent, sine divided by cosine; poles give infinities or NaN.

Manuscript
fn tan() Complex

Complex.tanh#

Returns the hyperbolic tangent.

Manuscript
fn tanh() Complex

Complex.to_polar#

Returns the magnitude as radius and the angle as theta, as abs and phase do.

Manuscript
fn to_polar() PolarParts

Complex.to_string#

Formats as a+bi or a-bi using the Float text of each part, e.g. 1.5-2i.

Manuscript
fn to_string() String

PolarParts Type#

The magnitude and angle of a complex number, from to_polar.

Manuscript
type PolarParts {
    radius Float
    theta Float
}

PolarParts.radius#

The magnitude, never negative.

Manuscript
radius Float

PolarParts.theta#

The angle in radians, from -pi through pi.

Manuscript
theta Float

complex_polar Function#

Returns the number with magnitude radius and angle theta in radians. complex_polar(1.0, pi) is about -1, with a tiny imaginary part from rounding.

Manuscript
fn complex_polar(radius Float, theta Float) Complex { ... }

imaginary_unit Function#

Returns the imaginary unit i.

Manuscript
fn imaginary_unit() Complex { ... }