← SPL reference

newMath (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 exponentiation by squaring when b is integral and exp(b · ln(a)) for fractional exponents. function.isPrime uses a built-in table for primes below 100 (lookup and trial divisors), an LRU hash cache for repeated tests, and 6k ± 1 trial division from 101 onward when sqrt(a) > 97. Pure-SPL trigonometry (sin, cos, tan, inverses, and reciprocals) uses Maclaurin / Horner series with range reduction — no Python C math.sin / cos (only interpreter math.sqrtR in asin). Load with use newMath; (extensionless import is allowed because the file starts with reqFileExtension.setVar(false);).

Import

use newMath;
print.number(pi);
print.number(function.power(2, 8));
test.assertTrue(function.isPrime(1009));

Constants

Functions

Trigonometry (pure SPL)

All trig helpers are radians. Arguments are range-reduced to a small interval, then evaluated with Horner-form Maclaurin series. Call via function.call(function.ref(sin), x) or directly inside other newMath functions after use newMath;.

Constants (trig)

Primary trig

Reciprocal trig

Inverse trig

Inverse reciprocal trig

Example — trig

use newMath;

print.number(function.call(function.ref(sin), 0));
print.number(function.call(function.ref(cos), 0));
print.number(function.call(function.ref(tan), 1));
print.number(function.call(function.ref(atan), 1));
print.number(function.call(function.ref(asin), 0.5));

Prime testing

function.isPrimeCompute (used internally on cache miss) applies these steps:

Prime cache (LRU)

After use newMath;, each integer function.isPrime call stores its result in newMath_primeCache (hash map). The next call with the same integer returns the cached value immediately and marks that entry as most recently used.

Example — cache and capacity

use newMath;

#comment: First call computes; second call hits the cache.
test.assertTrue(function.isPrime(10007));
test.assertTrue(function.isPrime(10007));

#comment: Raise capacity to 100 (evicts oldest if current size > 100).
function.setPrimeCacheCap(100);

#comment: Or assign the variable directly (trim with setPrimeCacheCap when shrinking).
newMath_primeCacheCap.setVar(75);

function.clearPrimeCache();

Implementation: someProgrammingLanguage/lib/newMath.spl