Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.14
3.14.2
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "pymath"
author = "Jeong, YunWon <jeong@youknowone.org>"
repository = "https://github.com/RustPython/pymath"
description = "A binary representation compatible Rust implementation of Python's math library."
version = "0.1.1"
version = "0.1.2"
edition = "2024"
license = "PSF-2.0"

Expand Down
102 changes: 55 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,64 @@ Every function produces identical results to Python at the binary representation

## Compatibility Status

### math (55/55)
### math (56/56)

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

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

Expand All @@ -78,20 +79,9 @@ Every function produces identical results to Python at the binary representation
- [x] `lcm`
- [x] `perm`

### cmath (24/24, requires `complex` feature)
### cmath (31/31, requires `complex` feature)

- [x] `abs`
- [x] `isclose`
- [x] `isfinite`
- [x] `isinf`
- [x] `isnan`
- [x] `phase`
- [x] `polar`
- [x] `rect`
- [x] `exp`
- [x] `log`
- [x] `log10`
- [x] `sqrt`
- [x] `acos`
- [x] `acosh`
- [x] `asin`
Expand All @@ -100,10 +90,28 @@ Every function produces identical results to Python at the binary representation
- [x] `atanh`
- [x] `cos`
- [x] `cosh`
- [x] `e`
- [x] `exp`
- [x] `inf`
- [x] `infj`
- [x] `isclose`
- [x] `isfinite`
- [x] `isinf`
- [x] `isnan`
- [x] `log`
- [x] `log10`
- [x] `nan`
- [x] `nanj`
- [x] `phase`
- [x] `pi`
- [x] `polar`
- [x] `rect`
- [x] `sin`
- [x] `sinh`
- [x] `sqrt`
- [x] `tan`
- [x] `tanh`
- [x] `tau`

## Usage

Expand Down
1 change: 1 addition & 0 deletions proptest-regressions/cmath/trigonometric.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cc 409f359905a7e77eacdbd4643c3a1483cc128e46a1c06795c246f3d57a2e61b9 # shrinks to
cc 5acbcf76c3bcbaf0b2b89a987e38c75265434f96fdc11598830e2221df72fc53 # shrinks to re = 0.00010260965539526095, im = 4.984721877290597e-19
cc ac04191f916633de0408e071f5f6ada8f7fe7a1be02caca7a32f37ecb148a5ac # shrinks to re = 3.049837651806167e74, im = -2.222842222335753e-166
cc 77ec3c08d2e057fb9467eb13c3b953e4e30f2800259d3653f7bcdfcbaf53614f # shrinks to re = 7.812038268590211e52, im = -2.623972069152808e-109
cc c8fa2873ca664202a38d40ef3766b0f9f07dc82c1d5cd08dcd6d180564a013a1 # shrinks to re = -0.0016106222874309162, im = 0.10954881424244108
7 changes: 7 additions & 0 deletions proptest-regressions/math/integer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 79031914da5204bfc75b0d7cf66e7f76d2e455d6c2837b66cbd11ebf7225be4a # shrinks to n = 32, k = 30
7 changes: 7 additions & 0 deletions proptest-regressions/math/misc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 46166a18f59569bb11107fd280e53c8f37902760e15afbe67d6951dcd3032c72 # shrinks to x = 0.0, y = 0.0, z = 0.0
29 changes: 25 additions & 4 deletions src/cmath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,34 @@ pub use exponential::{exp, log, log10, sqrt};
pub use misc::{abs, isclose, isfinite, isinf, isnan, phase, polar, rect};
pub use trigonometric::{acos, acosh, asin, asinh, atan, atanh, cos, cosh, sin, sinh, tan, tanh};

use num_complex::Complex64;

// Public constants (matching Python's cmath module)

/// The mathematical constant e = 2.718281...
pub const E: f64 = std::f64::consts::E;

/// The mathematical constant π = 3.141592...
pub const PI: f64 = std::f64::consts::PI;

/// The mathematical constant τ = 6.283185...
pub const TAU: f64 = std::f64::consts::TAU;

/// Positive infinity.
pub const INF: f64 = f64::INFINITY;

/// A floating point "not a number" (NaN) value.
pub const NAN: f64 = f64::NAN;

/// Complex number with zero real part and positive infinity imaginary part.
pub const INFJ: Complex64 = Complex64::new(0.0, f64::INFINITY);

/// Complex number with zero real part and NaN imaginary part.
pub const NANJ: Complex64 = Complex64::new(0.0, f64::NAN);

#[cfg(test)]
use crate::Result;
use crate::m;
#[cfg(test)]
use num_complex::Complex64;

// Shared constants

Expand All @@ -25,8 +48,6 @@ const M_LN2: f64 = core::f64::consts::LN_2;
const CM_LARGE_DOUBLE: f64 = f64::MAX / 4.0;
const CM_LOG_LARGE_DOUBLE: f64 = 709.0895657128241; // log(CM_LARGE_DOUBLE)

const INF: f64 = f64::INFINITY;

// Special value table constants
const P: f64 = core::f64::consts::PI;
const P14: f64 = 0.25 * core::f64::consts::PI;
Expand Down
Loading
Loading