-
Notifications
You must be signed in to change notification settings - Fork 0
Scalar Math
ExodusCoder9 edited this page Jun 20, 2026
·
1 revision
ScalarMath is a comprehensive scalar math utility with 80+ methods across 20+ categories. Use it directly or via the MathLib facade.
| Constant | Value |
|---|---|
PI |
π |
E |
e |
TAU |
2π |
PHI |
Golden ratio (1.618…) |
LN2 |
ln(2) |
LN10 |
ln(10) |
LOG2E |
log₂(e) |
LOG10E |
log₁₀(e) |
SQRT2 |
√2 |
SQRT3 |
√3 |
EPSILON |
Double.MIN_NORMAL |
FLT_EPSILON |
Float.MIN_NORMAL |
ScalarMath.sin(x); ScalarMath.cos(x); ScalarMath.tan(x);
ScalarMath.asin(x); ScalarMath.acos(x); ScalarMath.atan(x); ScalarMath.atan2(y, x);
// Reciprocal
ScalarMath.sec(x); ScalarMath.csc(x); ScalarMath.cot(x);
ScalarMath.asec(x); ScalarMath.acsc(x); ScalarMath.acot(x);
// Historical
ScalarMath.versin(x); // 1 - cos(x)
ScalarMath.haversin(x); // (1 - cos(x))/2
ScalarMath.exsec(x); // sec(x) - 1
ScalarMath.excsc(x); // csc(x) - 1
ScalarMath.vercosin(x); // 1 + cos(x)
ScalarMath.covercosin(x); // 1 + sin(x)
ScalarMath.chord(x); // 2*sin(x/2)
ScalarMath.sinc(x); // sin(x)/x
Hyperbolic Functions
ScalarMath.sinh(x); ScalarMath.cosh(x); ScalarMath.tanh(x);
ScalarMath.sech(x); ScalarMath.csch(x); ScalarMath.coth(x);
ScalarMath.asinh(x); ScalarMath.acosh(x); ScalarMath.atanh(x);
Exponential & Logarithmic
ScalarMath.exp(x); ScalarMath.exp2(x); ScalarMath.expm1(x);
ScalarMath.log(x); ScalarMath.log10(x); ScalarMath.log2(x);
ScalarMath.log1p(x); ScalarMath.logb(x); ScalarMath.pow(a, b);
Roots & Powers
ScalarMath.sqrt(x); ScalarMath.invSqrt(x);
ScalarMath.cbrt(x); ScalarMath.pow(a, b);
Rounding
ScalarMath.floor(x); ScalarMath.ceil(x);
ScalarMath.round(x); ScalarMath.trunc(x); ScalarMath.frac(x);
ScalarMath.roundTo(value, multiple);
ScalarMath.floorTo(value, multiple);
ScalarMath.ceilTo(value, multiple);
ScalarMath.snap(value, grid);
Interpolation
ScalarMath.lerp(a, b, t); // linear
ScalarMath.lerpAngle(a, b, t); // angular lerp
ScalarMath.inverseLerp(a, b, value);
ScalarMath.bilinear(tl, tr, bl, br, tx, ty);
ScalarMath.map(value, inLow, inHigh, outLow, outHigh);
ScalarMath.smoothstep(edge0, edge1, x);
ScalarMath.smootherstep(edge0, edge1, x);
ScalarMath.cosineInterpolation(a, b, t);
ScalarMath.catmullRom(a, b, c, d, t);
ScalarMath.hermite(a, b, t, tension, bias);
ScalarMath.bezier(a, b, c, d, t);
Activation Functions
ScalarMath.relu(x); // max(0, x)
ScalarMath.leakyRelu(x, a); // max(ax, x)
ScalarMath.elu(x, a); // x≥0 ? x : a*(eˣ-1)
ScalarMath.gelu(x); // Gaussian error linear unit
ScalarMath.selu(x); // scaled ELU
ScalarMath.sigmoid(x); // 1/(1+e⁻ˣ)
ScalarMath.softplus(x); // ln(1+eˣ)
ScalarMath.softsign(x); // x/(1+|x|)
ScalarMath.swish(x); // x*sigmoid(x)
ScalarMath.hardSigmoid(x);
ScalarMath.gaussian(x, mean, sigma);
ScalarMath.logistic(x);
ScalarMath.logit(p);
Special Functions
ScalarMath.erf(x); // error function
ScalarMath.erfc(x); // complementary error function
ScalarMath.invErf(x);
ScalarMath.gamma(x);
ScalarMath.lgamma(x);
ScalarMath.beta(a, b);
ScalarMath.riemannZeta(s);
ScalarMath.lambertW0(x);
ScalarMath.fresnelC(x);
ScalarMath.fresnelS(x);
Combinatorics
ScalarMath.factorial(n); // double (supports larger n)
ScalarMath.factorialLong(n); // long (up to 20!)
ScalarMath.binomial(n, k);
ScalarMath.permutations(n, k);
ScalarMath.stirlingFirstKind(n, k);
ScalarMath.stirlingSecondKind(n, k);
Number Theory
ScalarMath.gcd(a, b);
ScalarMath.lcm(a, b);
ScalarMath.isPrime(n);
ScalarMath.isCoprime(a, b);
ScalarMath.nextPrime(n);
ScalarMath.totient(n);
Statistics
ScalarMath.mean(array);
ScalarMath.median(array);
ScalarMath.mode(array);
ScalarMath.variance(array);
ScalarMath.populationVariance(array);
ScalarMath.stddev(array);
ScalarMath.populationStddev(array);
ScalarMath.covariance(a, b);
ScalarMath.correlation(a, b);
ScalarMath.skewness(array);
ScalarMath.kurtosis(array);
ScalarMath.standardError(array);
ScalarMath.zScore(value, mean, stddev);
ScalarMath.entropy(probabilities);
ScalarMath.percentile(array, p);
ScalarMath.movingAverage(data, window);
ScalarMath.exponentialMovingAverage(data, alpha);
ScalarMath.normalizeData(data);
ScalarMath.standardize(data);
Distance Metrics
ScalarMath.distanceManhattan(a, b);
ScalarMath.distanceChebyshev(a, b);
ScalarMath.distanceMinkowski(a, b, p);
ScalarMath.haversineDistance(lat1, lon1, lat2, lon2, radius);
Utility
ScalarMath.clamp(value, min, max);
ScalarMath.saturate(value); // clamp to [0,1]
ScalarMath.lerp(a, b, t);
ScalarMath.step(edge, x);
ScalarMath.pulse(start, end, x);
ScalarMath.ramp(x);
ScalarMath.pingPong(t, length);
ScalarMath.sawtooth(t);
ScalarMath.triangle(t);
ScalarMath.square(t);
ScalarMath.toRadians(degrees);
ScalarMath.toDegrees(radians);
ScalarMath.normalizeAngle(angle);
MathLib Facade
MathLib re-exports every ScalarMath method. Use whichever you prefer:
MathLib.sin(x);
MathLib.exp(x);
MathLib.erf(x);