@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.
type Complex {
re Float
im Float
}Complex.im#
The imaginary part, a Float that may be infinite or NaN.
im FloatComplex.re#
The real part, a Float that may be infinite or NaN.
re FloatComplex.abs#
Returns the magnitude sqrt(re^2 + im^2) without intermediate overflow.
fn abs() FloatComplex.acos#
Returns the principal inverse cosine, pi/2 minus the inverse sine.
fn acos() ComplexComplex.add#
Returns the sum, adding real and imaginary parts separately with Float rounding.
fn add(other Complex) ComplexComplex.asin#
Returns the principal inverse sine, -i * log(i*z + sqrt(1 - z^2)).
fn asin() ComplexComplex.atan#
Returns the principal inverse tangent, i/2 * (log(1 - iz) - log(1 + iz)).
fn atan() ComplexComplex.conjugate#
Returns the number with the imaginary part negated, so (1+2i) becomes (1-2i).
fn conjugate() ComplexComplex.cos#
Returns the complex cosine, cos(a)cosh(b) - sin(a)sinh(b)i for a+bi.
fn cos() ComplexComplex.cosh#
Returns the hyperbolic cosine.
fn cosh() ComplexComplex.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.
fn divide(other Complex) ComplexComplex.exp#
Returns e raised to this number.
fn exp() ComplexComplex.is_infinite#
Reports whether either part is infinite and neither is NaN.
fn is_infinite() BoolComplex.is_nan#
Reports whether either part is NaN.
fn is_nan() BoolComplex.log#
Returns the principal natural logarithm; the imaginary part is the phase.
fn log() ComplexComplex.multiply#
Returns the product (a+bi)(c+di) = (ac-bd) + (ad+bc)i with Float rounding.
fn multiply(other Complex) ComplexComplex.negate#
Returns the number with both parts negated.
fn negate() ComplexComplex.phase#
Returns the angle in radians, from -pi through pi; the principal argument.
fn phase() FloatComplex.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)).
fn pow(exponent Complex) ComplexComplex.scale#
Returns the product with a real factor.
fn scale(factor Float) ComplexComplex.sin#
Returns the complex sine, sin(a)cosh(b) + cos(a)sinh(b)i for a+bi.
fn sin() ComplexComplex.sinh#
Returns the hyperbolic sine.
fn sinh() ComplexComplex.sqrt#
Returns the principal square root, with a non-negative real part.
fn sqrt() ComplexComplex.subtract#
Returns the difference, subtracting real and imaginary parts separately with Float rounding.
fn subtract(other Complex) ComplexComplex.tan#
Returns the complex tangent, sine divided by cosine; poles give infinities or NaN.
fn tan() ComplexComplex.tanh#
Returns the hyperbolic tangent.
fn tanh() ComplexComplex.to_polar#
Returns the magnitude as radius and the angle as theta, as abs and phase do.
fn to_polar() PolarPartsComplex.to_string#
Formats as a+bi or a-bi using the Float text of each part, e.g. 1.5-2i.
fn to_string() StringPolarParts Type#
The magnitude and angle of a complex number, from to_polar.
type PolarParts {
radius Float
theta Float
}PolarParts.radius#
The magnitude, never negative.
radius FloatPolarParts.theta#
The angle in radians, from -pi through pi.
theta Floatcomplex_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.
fn complex_polar(radius Float, theta Float) Complex { ... }imaginary_unit Function#
Returns the imaginary unit i.
fn imaginary_unit() Complex { ... }