pymath-0.1.0 has been yanked.
pymath
0 ULP (bit-exact) compatibility with CPython's math and cmath modules.
Every function produces identical results to Python at the binary representation level - not just "close enough", but exactly the same bits.
Overview
pymath is a strict port of CPython's math library to Rust. Each function has been carefully translated from CPython's C implementation, preserving the same algorithms, constants, and corner case handling.
Compatibility Status
math (55/55)
-
ceil -
copysign -
fabs -
floor -
fmod -
frexp -
isclose -
isfinite -
isinf -
isnan -
ldexp -
modf -
nextafter -
remainder -
trunc -
ulp -
cbrt -
exp -
exp2 -
expm1 -
log -
log10 -
log1p -
log2 -
pow -
sqrt -
acos -
acosh -
asin -
asinh -
atan -
atan2 -
atanh -
cos -
cosh -
sin -
sinh -
tan -
tanh -
erf -
erfc -
gamma -
lgamma -
dist -
fsum -
hypot -
prod -
sumprod -
degrees -
radians -
pi -
e -
tau -
inf -
nan
math.integer (6/6, requires num-bigint or malachite-bigint feature)
-
comb -
factorial -
gcd -
isqrt -
lcm -
perm
cmath (24/24, requires complex feature)
-
abs -
isclose -
isfinite -
isinf -
isnan -
phase -
polar -
rect -
exp -
log -
log10 -
sqrt -
acos -
acosh -
asin -
asinh -
atan -
atanh -
cos -
cosh -
sin -
sinh -
tan -
tanh
Usage
use ;
Bit-exact verification
# Python 3.14
>>>
>>>
// Rust - identical bits
assert_eq!;
Bit representation may vary across platforms, but CPython and pymath built on the same environment will always produce identical results.
Features
complex(default) - Enable cmath module for complex number functionsnum-bigint- Enable integer functions using num-bigintmalachite-bigint- Enable integer functions using malachite-bigintmul_add- Use hardware FMA for bit-exact macOS compatibility
Module Structure
pymath::math- Real number math functions (Python'smathmodule)pymath::cmath- Complex number functions (Python'scmathmodule)pymath::m- Direct libm bindings