math package for Edge Python, compiled to wasm32-unknown-unknown over the WASM module ABI. Scalar transcendentals run on libm (no platform libc), and a packed-f64 batch path keeps bulk work fast by crossing the host boundary once per call instead of once per element.
from math import sqrt, pi, factorial, hypot
print(sqrt(2)) # 1.4142135623730951
print(pi) # 3.141592653589793 (a value, not a call)
print(factorial(5)) # 120
print(hypot(3, 4, 12)) # 13.0| Group | Names |
|---|---|
| Constants | pi, e, tau, inf, nan |
| Power / log | sqrt, cbrt, exp, exp2, expm1, pow, log (optional base), log2, log10, log1p |
| Trigonometric | sin, cos, tan, asin, acos, atan, atan2, hypot (variadic), dist |
| Hyperbolic | sinh, cosh, tanh, asinh, acosh, atanh |
| Angular | degrees, radians |
| Special | erf, erfc, gamma, lgamma |
| Float ops | fabs, fmod, remainder, copysign, ldexp, modf, frexp, floor, ceil, trunc |
| Classification | isnan, isinf, isfinite |
| Reductions | fsum, prod |
| Integer | factorial, gcd (variadic), lcm (variadic), isqrt, comb, perm |
floor, ceil, and trunc return an int; modf and frexp return a tuple. Out-of-domain inputs raise ValueError("math domain error"), matching CPython.
For array workloads, the *_all functions take and return bytes holding little-endian f64 values. The whole buffer crosses the boundary once, so n elements cost two crossings instead of 2n.
from math import sqrt_all, fsum_all
import struct # any packer of little-endian f64
buf = struct.pack("<4d", 1.0, 4.0, 9.0, 16.0)
roots = sqrt_all(buf) # bytes -> bytes, element-wise sqrt
print(fsum_all(buf)) # 30.0, compensated sum over the bufferElement-wise (bytes -> bytes): sqrt_all, abs_all, exp_all, log_all, sin_all, cos_all. Reductions (bytes -> float): fsum_all, prod_all. A buffer length that is not a multiple of 8 raises ValueError.
These come from the Edge Python VM, not this package:
- Integers cap at
i128.factorial,comb,perm, andlcmraiseValueErrorwhen a result exceeds that range. - No complex numbers, so there is no
cmath-style surface. prodreturns afloat; integer inputs lose their int-ness.
cargo build --release --target wasm32-unknown-unknownLicense: MIT OR Apache-2.0