Commit 9a7d997
fix(math): nextafter/nextafterf raise FE_OVERFLOW/FE_UNDERFLOW (glibc parity)
Differential probe of over/underflow exception cases found nextafter/nextafterf
omit the C99/IEEE F.10.8.3 flags glibc raises (scalbn/ldexp were already correct):
nextafter(MAX, INF) -> FE_OVERFLOW (finite x, infinite result)
nextafter(0, ±1) -> FE_UNDERFLOW (result smallest subnormal)
nextafter(MIN_POSITIVE, 0) -> FE_UNDERFLOW (result subnormal)
(+ f32 nextafterf, same)
Per the spec: nextafter raises OVERFLOW(+INEXACT) when x is finite and the result
is infinite, and UNDERFLOW(+INEXACT) when the result is subnormal or zero and
differs from x. libm returns the correct value but omits the flags. Fix: re-raise
via a hardware op (MAX*MAX -> inf+OVERFLOW; MIN_POSITIVE^2 -> 0+UNDERFLOW) on the
boundary results only; x==y and normal results raise nothing.
Gate: conformance_diff_fp_exceptions extended with the nextafter cases (flags
exact vs host glibc). Value unchanged (libm's result returned as-is). All 155
math lib tests pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 563d99d commit 9a7d997
3 files changed
Lines changed: 43 additions & 2 deletions
File tree
- crates
- frankenlibc-abi/tests
- frankenlibc-core/src/math
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
92 | 111 | | |
93 | 112 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
178 | 190 | | |
179 | 191 | | |
180 | 192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
577 | 577 | | |
578 | 578 | | |
579 | 579 | | |
580 | | - | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
581 | 591 | | |
582 | 592 | | |
583 | 593 | | |
| |||
0 commit comments