Lynxer

Documentation

math

Integer, floating-point, number-theory, rounding, logarithmic and trigonometric helpers.

Backend: native — stdlib/math.so, built from stdlib/math.cpp over <cmath>. Import: import("math") → global.math.*

Integers and number theory

FunctionSignatureNotes
abs(int value) -> intSaturates at maxInt for the minimum integer
max / min(int, int) -> intLarger / smaller of two integers
clamp(int value, int low, int high) -> intInclusive clamp
pow(int base, int exponent) -> intInteger exponentiation; 0 for negative exponents
sign(int value) -> int-1, 0 or 1
isEven / isOdd(int value) -> boolParity
factorial(int value) -> int0 for negative input
gcd / lcm(int, int) -> intGreatest common divisor / least common multiple
isPrime(int value) -> boolValues below two are not prime
nextPrime(int value) -> intFirst prime strictly greater than value
binomial(int n, int k) -> intn choose k; 0 for invalid k
sumRange(int low, int high) -> intInclusive sum; 0 when low > high
isqrt(int value) -> intInteger square root; 0 for negatives

Floating point

FunctionSignatureNotes
absFloat(float value) -> floatAbsolute value
maxFloat / minFloat(float, float) -> floatLarger / smaller (NaN-aware)
clampFloat(float value, float low, float high) -> floatInclusive clamp
powFloat(float base, float exponent) -> floatstd::pow
sqrt, cbrt(float value) -> floatSquare / cube root
hypot(float x, float y) -> floatsqrt(x² + y²)
signFloat(float value) -> float-1.0, 0.0 or 1.0
fmod / remainder(float, float) -> floatRemainder operations
truncate(float value) -> intTruncates toward zero
floor, ceil, round, trunc(float value) -> floatRounding
roundNum(float value) -> floatAlias of round
roundTo(float value, int decimals) -> floatRounds to decimals places
lerp(float low, float high, float t) -> floatLinear interpolation
mapRange(float value, float inLo, float inHi, float outLo, float outHi) -> floatRe-maps between ranges; returns outLo when the input range is empty
degrees / radians(float value) -> floatAngle conversion
isFinite, isNaN, isInfinite(float value) -> boolFloating-point classification

Exponential, logarithmic and trigonometric

exp, exp2, log, log10, log2, sin, cos, tan, asin, acos, atan, atan2(y, x), sinh, cosh, tanh — all (float) -> float (plus atan2(float y, float x)), and the aliases arcsin, arccos, arctan, arctan2.

Constants and randomness

FunctionSignature
pi()-> float
e()-> float
tau()-> float
randInt(int low, int high) -> intUniform integer in [low, high]
randFloat(float low, float high) -> floatUniform float in [low, high]

maxInt and minInt are exposed as functions returning the largest and smallest 64-bit integers: global.math.maxInt() / global.math.minInt().

Statistics and vector helpers

These were previously a separate mathPlus module; they now live in math. These were originally implemented with NumPy, which Lynxer does not need — the results match NumPy's defaults. List arguments cross the native ABI as a bytes buffer of little-endian f64 (the listToBytes / bytesToList encoding), and list results come back as Lynxer lists of float.

FunctionSignatureNotes
mean(list values) -> floatArithmetic mean
median(list values) -> floatAverages the two middle values for even lengths
std(list values) -> floatPopulation standard deviation (ddof = 0)
variance(list values) -> floatPopulation variance
percentile(list values, float p) -> floatLinear interpolation between order statistics
prod(list values) -> floatProduct of the elements
norm(list values) -> floatEuclidean norm
dot(list a, list b) -> floatDot product; 0.0 when lengths differ
corrcoef(list a, list b) -> floatPearson correlation; 0.0 on a length mismatch or a constant series
argmax / argmin(list values) -> intIndex of the largest / smallest element
linspace(float start, float stop, int n) -> listn evenly spaced values including both ends; empty for n <= 0
cumsum(list values) -> listRunning sums
diff(list values) -> listConsecutive differences (one shorter)
clip(list values, float lo, float hi) -> listElement-wise clamp
normalize(list values) -> listScales to unit norm; returns the input when the norm is 0

Empty input yields 0.0 for the scalar helpers and an empty list for the list-returning helpers.

Example

global setup(){ import("math"); }

global main(){
    println(global.math.pi());
    println(global.math.mean(seqFromTo(1, 5, 1)));   // [1,2,3,4] -> 2.5
    println(global.math.linspace(0.0, 1.0, 5));
    println(global.math.cumsum(seqFromTo(1, 4, 1)));
}

seqFromTo and range exclude their stop value, so seqFromTo(1, 5, 1) is [1, 2, 3, 4].


See also