viva_math/complex
Complex numbers a + bi.
Standard algebra plus a small set of transcendental functions sufficient for FFT, eigenvalue work and signal processing.
All operations are pure and total — division by zero returns the zero
complex by convention (consistent with gleam/float).
Types
Values
pub fn from_polar(r: Float, theta: Float) -> Complex
Build from magnitude r and phase theta (polar form).
pub fn log(z: Complex) -> Complex
log(z) = ln|z| + i·arg(z). Branch cut along the negative real axis.
pub fn magnitude(z: Complex) -> Float
|z| = √(re² + im²). Uses hypot to avoid overflow.
pub fn magnitude_squared(z: Complex) -> Float
|z|² (cheaper than magnitude when comparing).
pub fn pow_int(z: Complex, n: Int) -> Complex
z^n for integer n via repeated multiplication. Handles negative exponents.
pub fn to_polar(z: Complex) -> #(Float, Float)
Polar decomposition: returns (magnitude, phase).