⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
cpython
33 changes: 28 additions & 5 deletions src/math/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ mod tests {
use pyo3::prelude::*;

/// Edge i64 values for testing integer math functions (gcd, lcm, isqrt, factorial, comb, perm)
const EDGE_I64: [i64; 24] = [
const EDGE_I64: [i64; 44] = [
// Zero and small values
0,
1,
Expand All @@ -726,27 +726,50 @@ mod tests {
7,
13,
97,
// Powers of 2
127, // table boundary in comb/perm
128, // Table boundary + 1
// Powers of 2 and boundaries
64,
63, // 2^6 - 1
65, // 2^6 + 1
1024,
65536,
65535, // 2^16 - 1
65536, // 2^16
65537, // 2^16 + 1 (Fermat prime)
// Factorial-relevant
12, // 12! = 479001600 fits in u32
13, // 13! overflows u32
20, // 20! fits in u64
21, // 21! overflows u64
170, // factorial(170) is the largest that fits in f64
171, // factorial(171) overflows f64
// Comb/perm algorithm switching points
34, // FAST_COMB_LIMITS1 boundary
35,
// Large values
1_000_000,
-1_000_000,
i32::MAX as i64,
i32::MAX as i64 + 1,
i32::MIN as i64,
i32::MIN as i64 - 1,
// Near i64 bounds
i64::MAX,
i64::MIN,
i64::MAX - 1,
i64::MIN + 1,
// Square root boundaries
(1i64 << 31) - 1, // sqrt fits in u32
1i64 << 32, // sqrt boundary
(1i64 << 15) - 1, // 32767, sqrt = 181
1i64 << 16, // 65536, sqrt = 256 (exact)
(1i64 << 31) - 1, // sqrt fits in u16
1i64 << 32, // sqrt boundary (exact power of 2)
(1i64 << 32) - 1, // near sqrt boundary
(1i64 << 32) + 1, // just above sqrt boundary
(1i64 << 62) - 1, // large but valid for isqrt
1i64 << 62, // exact power of 2
// Near perfect squares
99, // sqrt(99) = 9.949...
101, // sqrt(101) = 10.049...
];

fn test_gcd_impl(args: &[i64]) {
Expand Down
64 changes: 54 additions & 10 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pyo3::{Python, prelude::*};

/// Edge values for testing floating-point functions.
/// Includes: zeros, infinities, various NaNs, subnormals, and values at different scales.
pub(crate) const EDGE_VALUES: [f64; 30] = [
pub(crate) const EDGE_VALUES: [f64; 64] = [
// Zeros
0.0,
-0.0,
Expand All @@ -15,35 +15,79 @@ pub(crate) const EDGE_VALUES: [f64; 30] = [
-f64::NAN,
// Additional NaN with different payload (quiet NaN with payload 1)
f64::from_bits(0x7FF8_0000_0000_0001_u64),
// Signaling NaN (sNaN) - may trigger FP exceptions on some platforms
f64::from_bits(0x7FF0_0000_0000_0001_u64),
// Subnormal (denormalized) values
f64::MIN_POSITIVE * 0.5, // smallest subnormal
f64::MIN_POSITIVE * 0.5,
-f64::MIN_POSITIVE * 0.5,
5e-324,
-5e-324,
// Boundary values
f64::MIN_POSITIVE, // smallest positive normal
f64::MAX, // largest finite
f64::MIN, // most negative finite (not smallest!)
f64::MIN_POSITIVE,
f64::MAX,
f64::MIN,
// Near-infinity large values
f64::MAX * 0.5,
-f64::MAX * 0.5,
1e308,
-1e308,
// Overflow/underflow thresholds for exp
710.0,
-745.0,
// Small scale
1e-10,
-1e-10,
1e-300,
-1e-300,
// Normal scale
1.0,
-1.0,
0.5,
-0.5,
2.0,
// Trigonometric special values (where sin/cos/tan have exact or near-zero results)
std::f64::consts::PI, // sin(PI) ≈ 0
-2.0,
3.0, // for cbrt
-3.0,
// Values near 1.0 (log, expm1, log1p, acosh boundary)
1.0 - 1e-15,
1.0 + 1e-15,
f64::EPSILON,
1.0 - f64::EPSILON,
1.0 + f64::EPSILON,
// asin/acos domain boundaries [-1, 1]
1.0000000000000002, // just outside domain (1 + eps)
-1.0000000000000002,
// atanh domain boundaries (-1, 1)
0.9999999999999999, // just inside domain
-0.9999999999999999,
// log1p domain boundary (> -1)
-0.9999999999999999, // just above -1
-1.0 + 1e-15, // very close to -1
// gamma/lgamma poles (negative integers)
-1.0,
-2.0,
-3.0,
-0.5, // gamma(-0.5) = -2*sqrt(pi)
// Mathematical constants
std::f64::consts::E,
std::f64::consts::LN_2,
std::f64::consts::LOG10_E,
// Trigonometric special values
std::f64::consts::PI,
-std::f64::consts::PI,
std::f64::consts::FRAC_PI_2, // cos(PI/2) ≈ 0
std::f64::consts::FRAC_PI_2,
-std::f64::consts::FRAC_PI_2,
std::f64::consts::FRAC_PI_4, // tan(PI/4) = 1
std::f64::consts::TAU, // sin(2*PI) ≈ 0, cos(2*PI) = 1
std::f64::consts::FRAC_PI_4,
std::f64::consts::TAU,
1.5 * std::f64::consts::PI, // 3π/2
// Large values for trig (precision loss)
1e15,
-1e15,
// Near-integer values (ceil, floor, trunc, round)
0.49999999999999994,
0.50000000000000006,
-0.49999999999999994,
-0.50000000000000006,
];

pub(crate) fn unwrap<'py>(
Expand Down
Loading