Skip to content

Commit 80013fb

Browse files
committed
more edge values
1 parent 97d2f52 commit 80013fb

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
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: 30 additions & 6 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; 49] = [
77
// Zeros
88
0.0,
99
-0.0,
@@ -15,9 +15,13 @@ 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
1921
f64::MIN_POSITIVE * 0.5, // smallest subnormal
2022
-f64::MIN_POSITIVE * 0.5,
23+
5e-324, // smallest positive subnormal
24+
-5e-324,
2125
// Boundary values
2226
f64::MIN_POSITIVE, // smallest positive normal
2327
f64::MAX, // largest finite
@@ -27,23 +31,43 @@ pub(crate) const EDGE_VALUES: [f64; 30] = [
2731
-f64::MAX * 0.5,
2832
1e308,
2933
-1e308,
34+
// Values near overflow threshold for common operations
35+
1e154, // sqrt of this is ~1e77, exp of this overflows
36+
-1e154,
37+
710.0, // exp(710) ≈ overflow threshold
38+
-745.0, // exp(-745) ≈ underflow threshold
3039
// Small scale
3140
1e-10,
3241
-1e-10,
3342
1e-300,
43+
-1e-300,
3444
// Normal scale
3545
1.0,
3646
-1.0,
3747
0.5,
3848
-0.5,
3949
2.0,
40-
// Trigonometric special values (where sin/cos/tan have exact or near-zero results)
41-
std::f64::consts::PI, // sin(PI) ≈ 0
50+
-2.0,
51+
// Values near 1.0 (important for log, expm1, log1p)
52+
1.0 - 1e-15, // just below 1
53+
1.0 + 1e-15, // just above 1
54+
f64::EPSILON,
55+
1.0 - f64::EPSILON,
56+
1.0 + f64::EPSILON,
57+
// Mathematical constants
58+
std::f64::consts::E,
59+
std::f64::consts::LN_2,
60+
std::f64::consts::LOG10_E,
61+
// Trigonometric special values
62+
std::f64::consts::PI,
4263
-std::f64::consts::PI,
43-
std::f64::consts::FRAC_PI_2, // cos(PI/2) ≈ 0
64+
std::f64::consts::FRAC_PI_2,
4465
-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
66+
std::f64::consts::FRAC_PI_4,
67+
std::f64::consts::TAU,
68+
// Near-integer values (important for ceil, floor, trunc, round)
69+
0.49999999999999994, // rounds to 0
70+
0.50000000000000006, // rounds to 1
4771
];
4872

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

0 commit comments

Comments
 (0)