Skip to content

Commit 8313a32

Browse files
committed
more edge values
1 parent 97d2f52 commit 8313a32

File tree

3 files changed

+83
-15
lines changed

3 files changed

+83
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
Cargo.lock
3+
cpython

src/math/integer.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ mod tests {
715715
use pyo3::prelude::*;
716716

717717
/// Edge i64 values for testing integer math functions (gcd, lcm, isqrt, factorial, comb, perm)
718-
const EDGE_I64: [i64; 24] = [
718+
const EDGE_I64: [i64; 44] = [
719719
// Zero and small values
720720
0,
721721
1,
@@ -726,27 +726,50 @@ mod tests {
726726
7,
727727
13,
728728
97,
729-
// Powers of 2
729+
127, // table boundary in comb/perm
730+
128, // Table boundary + 1
731+
// Powers of 2 and boundaries
730732
64,
733+
63, // 2^6 - 1
734+
65, // 2^6 + 1
731735
1024,
732-
65536,
736+
65535, // 2^16 - 1
737+
65536, // 2^16
738+
65537, // 2^16 + 1 (Fermat prime)
733739
// Factorial-relevant
740+
12, // 12! = 479001600 fits in u32
741+
13, // 13! overflows u32
734742
20, // 20! fits in u64
735743
21, // 21! overflows u64
744+
170, // factorial(170) is the largest that fits in f64
745+
171, // factorial(171) overflows f64
746+
// Comb/perm algorithm switching points
747+
34, // FAST_COMB_LIMITS1 boundary
748+
35,
736749
// Large values
737750
1_000_000,
738751
-1_000_000,
739752
i32::MAX as i64,
753+
i32::MAX as i64 + 1,
740754
i32::MIN as i64,
755+
i32::MIN as i64 - 1,
741756
// Near i64 bounds
742757
i64::MAX,
743758
i64::MIN,
744759
i64::MAX - 1,
745760
i64::MIN + 1,
746761
// Square root boundaries
747-
(1i64 << 31) - 1, // sqrt fits in u32
748-
1i64 << 32, // sqrt boundary
762+
(1i64 << 15) - 1, // 32767, sqrt = 181
763+
1i64 << 16, // 65536, sqrt = 256 (exact)
764+
(1i64 << 31) - 1, // sqrt fits in u16
765+
1i64 << 32, // sqrt boundary (exact power of 2)
766+
(1i64 << 32) - 1, // near sqrt boundary
767+
(1i64 << 32) + 1, // just above sqrt boundary
749768
(1i64 << 62) - 1, // large but valid for isqrt
769+
1i64 << 62, // exact power of 2
770+
// Near perfect squares
771+
99, // sqrt(99) = 9.949...
772+
101, // sqrt(101) = 10.049...
750773
];
751774

752775
fn test_gcd_impl(args: &[i64]) {

src/test.rs

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use pyo3::{Python, prelude::*};
33

44
/// Edge values for testing floating-point functions.
55
/// Includes: zeros, infinities, various NaNs, subnormals, and values at different scales.
6-
pub(crate) const EDGE_VALUES: [f64; 30] = [
6+
pub(crate) const EDGE_VALUES: [f64; 64] = [
77
// Zeros
88
0.0,
99
-0.0,
@@ -15,35 +15,79 @@ pub(crate) const EDGE_VALUES: [f64; 30] = [
1515
-f64::NAN,
1616
// Additional NaN with different payload (quiet NaN with payload 1)
1717
f64::from_bits(0x7FF8_0000_0000_0001_u64),
18+
// Signaling NaN (sNaN) - may trigger FP exceptions on some platforms
19+
f64::from_bits(0x7FF0_0000_0000_0001_u64),
1820
// Subnormal (denormalized) values
19-
f64::MIN_POSITIVE * 0.5, // smallest subnormal
21+
f64::MIN_POSITIVE * 0.5,
2022
-f64::MIN_POSITIVE * 0.5,
23+
5e-324,
24+
-5e-324,
2125
// Boundary values
22-
f64::MIN_POSITIVE, // smallest positive normal
23-
f64::MAX, // largest finite
24-
f64::MIN, // most negative finite (not smallest!)
26+
f64::MIN_POSITIVE,
27+
f64::MAX,
28+
f64::MIN,
2529
// Near-infinity large values
2630
f64::MAX * 0.5,
2731
-f64::MAX * 0.5,
2832
1e308,
2933
-1e308,
34+
// Overflow/underflow thresholds for exp
35+
710.0,
36+
-745.0,
3037
// Small scale
3138
1e-10,
3239
-1e-10,
3340
1e-300,
41+
-1e-300,
3442
// Normal scale
3543
1.0,
3644
-1.0,
3745
0.5,
3846
-0.5,
3947
2.0,
40-
// Trigonometric special values (where sin/cos/tan have exact or near-zero results)
41-
std::f64::consts::PI, // sin(PI) ≈ 0
48+
-2.0,
49+
3.0, // for cbrt
50+
-3.0,
51+
// Values near 1.0 (log, expm1, log1p, acosh boundary)
52+
1.0 - 1e-15,
53+
1.0 + 1e-15,
54+
f64::EPSILON,
55+
1.0 - f64::EPSILON,
56+
1.0 + f64::EPSILON,
57+
// asin/acos domain boundaries [-1, 1]
58+
1.0000000000000002, // just outside domain (1 + eps)
59+
-1.0000000000000002,
60+
// atanh domain boundaries (-1, 1)
61+
0.9999999999999999, // just inside domain
62+
-0.9999999999999999,
63+
// log1p domain boundary (> -1)
64+
-0.9999999999999999, // just above -1
65+
-1.0 + 1e-15, // very close to -1
66+
// gamma/lgamma poles (negative integers)
67+
-1.0,
68+
-2.0,
69+
-3.0,
70+
-0.5, // gamma(-0.5) = -2*sqrt(pi)
71+
// Mathematical constants
72+
std::f64::consts::E,
73+
std::f64::consts::LN_2,
74+
std::f64::consts::LOG10_E,
75+
// Trigonometric special values
76+
std::f64::consts::PI,
4277
-std::f64::consts::PI,
43-
std::f64::consts::FRAC_PI_2, // cos(PI/2) ≈ 0
78+
std::f64::consts::FRAC_PI_2,
4479
-std::f64::consts::FRAC_PI_2,
45-
std::f64::consts::FRAC_PI_4, // tan(PI/4) = 1
46-
std::f64::consts::TAU, // sin(2*PI) ≈ 0, cos(2*PI) = 1
80+
std::f64::consts::FRAC_PI_4,
81+
std::f64::consts::TAU,
82+
1.5 * std::f64::consts::PI, // 3π/2
83+
// Large values for trig (precision loss)
84+
1e15,
85+
-1e15,
86+
// Near-integer values (ceil, floor, trunc, round)
87+
0.49999999999999994,
88+
0.50000000000000006,
89+
-0.49999999999999994,
90+
-0.50000000000000006,
4791
];
4892

4993
pub(crate) fn unwrap<'py>(

0 commit comments

Comments
 (0)