Core Module

rmath.scalar

80+ scalar math functions backed by Rust. Mirrors Python's math module with extras: clamp, lerp, fma, root, isclose, and more. Also provides Scalar, Complex, and LazyPipeline classes.

Scalar Class

A Rust-backed f64 wrapper with full numeric protocol (arithmetic, comparison, hashing, format).

Math Methods
.sqrt() · .cbrt() · .pow(exp)
.exp() · .exp2() · .log(base?) · .log2() · .log10()
.sin() · .cos() · .tan() · .asin() · .acos() · .atan() · .atan2(x)
.sinh() · .cosh() · .tanh() · .asinh() · .acosh() · .atanh()
.ceil() · .floor() · .round() · .trunc() · .fract() · .abs()
.hypot(y) · .clamp(lo, hi) · .signum() · .lerp(other, t)
Predicates
.is_nan() · .is_inf() · .is_finite()bool

Complex Class

Complex number re + im·j with full arithmetic, comparison by modulus, and math methods.

Complex(re, im)Create from real and imaginary parts
Complex.from_polar(r, theta)Create from polar form
.re / .imReal / imaginary part (read-write)
.abs() · .arg() · .conjugate() · .to_polar()
.exp() · .log() · .sqrt() · .pow(z) · .sin() · .cos()
+ - * / **All work with float, Scalar, or Complex

LazyPipeline

Lazy, parallel evaluation pipeline. Chain operations then materialize.

.sin() · .cos() · .sqrt() · .abs() · .exp()Map operations (lazy)
.add(v) · .mul(v) · .sub(v) · .div(v)Scalar transforms (lazy)
.filter_gt(v) · .filter_lt(v) · .filter_finite()Lazy filters
.sum() · .mean() · .var() · .std() · .max() · .min()Terminal operations → float
.to_vector() · .to_tuple()Materialize to Vector or tuple

Functional API — Arithmetic

FunctionDescription
add(x, y) · sub(x, y) · mul(x, y) · div(x, y)Basic arithmetic (div raises ZeroDivisionError)
fmod(x, y)C-style remainder (sign follows dividend)
remainder(x, y)Python-style remainder (sign follows divisor)

Rounding & Range

ceil(x) · floor(x) · trunc(x) · round(x)
round_half_even(x)Banker's rounding
signum(x)Returns -1.0, 0.0, or 1.0
abs(x)Absolute value
clamp(x, min, max)Clamp to [min, max]
lerp(a, b, t)Linear interpolation: a + t·(b − a)

Roots & Powers

sqrt(x) · cbrt(x) · root(x, n)
pow(x, y) · inv_sqrt(x)
hypot(x, y) · hypot_3d(x, y, z)
fma(x, y, z)Fused multiply-add: x·y + z (single rounding)

Trigonometry

sin(x) · cos(x) · tan(x)
asin(x) · acos(x) · atan(x) · atan2(y, x)
sinh(x) · cosh(x) · tanh(x)
asinh(x) · acosh(x) · atanh(x)
degrees(x) · radians(x)

Exponential & Logarithmic

exp(x) · exp2(x) · expm1(x)
log(x, base?) · log2(x) · log10(x) · log1p(x)
logsumexp2(x, y)Numerically stable ln(eˣ + eʸ)

Predicates & Utility

isfinite(x) · isinf(x) · isnan(x) · is_integer(x)bool
isclose(a, b, rel_tol=1e-9, abs_tol=0.0)Approximate equality
copysign(x, y)x with sign of y
nextafter(x, y)Next representable float
frexp(x)(mantissa, exp)Decompose into mantissa × 2ᵉˣᵖ
ulp(x)Unit in last place