Commit da6b2e7
committed
fix: avoid u64 overflow in solve_itp for large nmax values
When epsilon is very small (e.g. 1e-24), nmax can exceed 63.
The expression `(1u64 << nmax) as f64` then overflows: debug
builds panic, release builds silently produce the wrong value
because x86 masks the shift amount to 6 bits (so << 64 wraps
to << 0 = 1).
Replace with `(nmax as f64).exp2()` which is mathematically
identical (2^nmax) but uses f64 arithmetic, handling nmax up
to ~1023 before saturating to +inf — well beyond any practical
epsilon.
Add a regression test with epsilon=1e-24 (nmax≈79) that panics
on the original code in debug mode.1 parent 838b69e commit da6b2e7
1 file changed
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
710 | 710 | | |
711 | 711 | | |
712 | 712 | | |
713 | | - | |
| 713 | + | |
714 | 714 | | |
715 | 715 | | |
716 | 716 | | |
| |||
1097 | 1097 | | |
1098 | 1098 | | |
1099 | 1099 | | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
1100 | 1108 | | |
1101 | 1109 | | |
1102 | 1110 | | |
| |||
0 commit comments