Commit 62d3ef1
Fix powl() returning NaN on extreme underflow (#334)
In the ld80 (x86 80-bit) powl(), when |y*log2(x)| is enormous the
extended-precision reduction reducl(G) computes ldexpl(G, LNXT), which
overflows to +-Inf. The following Inf-Inf / Inf+(-Inf) arithmetic
(Gb = G - Ga, Ha = reducl(Fb + Gb), Ga + Ha) yields NaN, so the
w > MEXP / w < MNEXP over/underflow tests both fail and powl() returns
NaN instead of Inf (overflow) or +0 (underflow).
Reproducer:
powl(0x1.98p-3072l, 0xa.ab43b6dba9a6383p+16364l)
returned NaN; glibc correctly returns +0 (underflow).
This is a latent bug shared with upstream FreeBSD msun / OpenBSD; there
is no upstream fix to import. G already holds y*log2(x) in 1/NXT units,
so the final exponent is ldexpl(G, LNXT) to within O(1). Test G for
over/underflow before reducl(G) can overflow. A generous 2*MEXP/NXT
margin keeps the early guard far from the genuine over/underflow
boundary, so borderline values still fall through to the original
precise test on w = ldexpl(Ga+Ha, LNXT); only the pathological huge-|G|
case is short-circuited.
Verified the reproducer now returns +0 and a battery of normal,
overflow, underflow, negative-base, non-integer-exponent and boundary
cases all match glibc. Full suite (test-double, test-float,
regression) passes.
Adds test/regression/test-334.c (skips with status 77 when
LDBL_MANT_DIG < 64, since the ld80 path is unused there); it fails on
the pre-fix code and passes after.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent aeef4da commit 62d3ef1
2 files changed
Lines changed: 68 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
407 | 428 | | |
408 | 429 | | |
409 | 430 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
0 commit comments