← Winnitude! Search  ·  Reader Mode (832 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 42 LINKS

GitHub - RustPython/pymath

Repository navigation

pymath
Public

About

No description, website, or topics provided.

Resources

Readme License Activity Custom properties

Stars

13 stars

Watchers

2 watching

Forks

4 forks Report repository
Branches

Tags
Go to Branches page Go to Tags page

Latest commit

 

History


34 Commits
View commit history for this file.

Folders and files

Name Name Last commit message Last commit date
.github/ workflows .github/ workflows    
benches benches    
proptest-regressions proptest-regressions    
src src    
.gitignore .gitignore    
.python-version .python-version    
AGENTS.md AGENTS.md    
Cargo.toml Cargo.toml    
LICENSE LICENSE    
README.md README.md    

Repository files navigation

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 (61/61)

  • acos
  • acosh
  • asin
  • asinh
  • atan
  • atan2
  • atanh
  • cbrt
  • ceil
  • copysign
  • cos
  • cosh
  • degrees
  • dist
  • e
  • erf
  • erfc
  • exp
  • exp2
  • expm1
  • fabs
  • floor
  • fma
  • fmax
  • fmin
  • fmod
  • frexp
  • fsum
  • gamma
  • hypot (n-dimensional)
  • inf
  • isclose
  • isfinite
  • isinf
  • isnan
  • isnormal
  • issubnormal
  • ldexp
  • lgamma
  • log
  • log10
  • log1p
  • log2
  • modf
  • nan
  • nextafter
  • pi
  • pow
  • prod (prod, prod_int)
  • radians
  • remainder
  • sin
  • signbit
  • sinh
  • sqrt
  • sumprod (sumprod, sumprod_int)
  • tan
  • tanh
  • tau
  • trunc
  • ulp

math.integer (6/6, requires num-bigint or malachite-bigint feature)

  • comb
  • factorial
  • gcd
  • isqrt
  • lcm
  • perm

cmath (31/31, requires complex feature)

  • abs
  • acos
  • acosh
  • asin
  • asinh
  • atan
  • atanh
  • cos
  • cosh
  • e
  • exp
  • inf
  • infj
  • isclose
  • isfinite
  • isinf
  • isnan
  • log
  • log10
  • nan
  • nanj
  • phase
  • pi
  • polar
  • rect
  • sin
  • sinh
  • sqrt
  • tan
  • tanh
  • tau

Usage

use pymath::math::{sqrt, gamma, lgamma};

fn main() {
    let sqrt_result = sqrt(2.0).unwrap();
    let gamma_result = gamma(4.5).unwrap();
    let lgamma_result = lgamma(4.5).unwrap();
}

Bit-exact verification

# Python 3.14
>>> import math
>>> math.gamma(0.5).hex()
'0x1.c5bf891b4ef6ap+0'
// Rust - identical bits
assert_eq!(
    pymath::math::gamma(0.5).unwrap().to_bits(),
    0x3ffc5bf891b4ef6a
);

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 functions
  • num-bigint - Enable integer functions using num-bigint
  • malachite-bigint - Enable integer functions using malachite-bigint
  • mul_add - Use hardware FMA for bit-exact macOS compatibility

Module Structure

  • pymath::math - Real number math functions (Python's math module)
  • pymath::cmath - Complex number functions (Python's cmath module)
  • pymath::m - Direct libm bindings

Important Note

This library guarantees compatibility with Python's math module , not mathematical correctness.

About

No description, website, or topics provided.

Resources

Readme License Activity Custom properties

Stars

13 stars

Watchers

2 watching

Forks

4 forks Report repository

Releases

Packages

Used by

Contributors

Languages