Standard Library

VMath

Scalar math, rounding, activations, clamping, PCG32 random, and constants.

vmath is the scalar math module. Import it with use native vmath;. Trigonometry uses radians.

Constants

PropertyValue
vmath.pi3.141592653589793
vmath.e2.718281828459045
vmath.tau6.283185307179586
vmath.phi1.618033988749895
vmath.sqrt21.4142135623730951
vmath.infpositive infinity
vmath.nanNaN

One-argument functions

sqrt, abs, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, log, log10, exp, floor, ceil, round, erf, erfc, tgamma, lgamma, sigmoid, relu, degrees, radians.

 vyne snippetvyne
use native vmath; out(vmath.sqrt(9.0)); # 3 out(vmath.sin(vmath.pi / 2.0)); out(vmath.exp(0.0)); # 1 out(vmath.sigmoid(0.0)); # 0.5 out(vmath.relu(-3.0)); # 0 out(vmath.degrees(vmath.pi)); # 180

Two- and three-argument functions

FunctionResult
vmath.pow(base, exp)base ** exp
vmath.hypot(a, b)sqrt(a² + b²)
vmath.atan2(y, x)quadrant-aware arctangent
vmath.fmod(a, b)floating remainder; b == 0 yields 0
vmath.min(a, b) / vmath.max(a, b)numeric min/max
vmath.clamp(v, lo, hi)clamp; silently swaps lo/hi if reversed

Random

vmath exposes one process-global PCG32 stream shared by random and random_float.

FunctionResult
vmath.random(lo, hi)Int64 in [lo, hi]
vmath.random_float(lo, hi)Float64 in [lo, hi)
vmath.seed(n)Reset the stream state
 vyne snippetvyne
vmath.seed(42); dice := vmath.random(1, 6); x := vmath.random_float(-1.0, 1.0);

The state is process-global. Two independent streams require explicit state that has not landed yet. For reproducible simulations, call vmath.seed once at startup. On AVR, arduino.random / arduino.random_seed are separate bindings; the TinyML demo implements its own LCG in Vyne source for cross-boot reproducibility.

Unboxed variants

Every hot scalar function has a _f64 variant used by the emitter when every argument is provably Float64. The source spelling does not change: vmath.sqrt(x) lowers to vmath_sqrt or vmath_sqrt_f64 depending on the inferred type. Library kernels are written to keep the unboxed path.

AVR surface

The same names are available through arduino.* on the Uno target, with _f64 variants for the provable-native path. AVR double is 32-bit, so expect single-precision behavior.

See also