lib/newMath.spl)
Pure SPL math: constants pi,
e, and ln2; transcendental
function.exp and function.ln (Chebyshev-fit
minimax-style Horner polynomials, no Python math.exp /
log in the interpreter); function.power uses
exact integer loops when b is integral and
exp(b * ln(a)) for fractional exponents. Also function.abs, GCD, etc. Load with
use newMath; (extensionless import is allowed because the file starts with
reqFileExtension.setVar(false);).
use newMath; print.number(pi); print.number(function.power(2, 8));
pi — double-precision π.e — Euler’s number (also used for scaling in exp).ln2 — ln(2); used when reducing ln(x) to [1,2).function.exp(x) — e^x: write x = n + f with n = round(x) and f ∈ [-0.5, 0.5], then e^x = e^n · e^f with a fixed polynomial for e^f.function.ln(x) — natural log for x > 0; returns null for x ≤ 0.function.power(a, b) — integer b: repeated multiply (exact for positive base; sign rule for negative a). Non-integer b and a > 0: exp(b·ln(a)).function.abs(a) — absolute value.function.isPrime(a) — trial division up to floor(sqrt(a)).function.gcd(a, b) — Euclidean GCD (recursive).function.factorial(n) — non-negative integers only; invalid input uses return.boolean(null).function.lcm(a, b) — via a*b/gcd(a,b).function.isInteger(a) — true when type.isNumber and value equals math.floor(a).
Implementation: someProgrammingLanguage/lib/newMath.spl