Skip to content

Commit 100ab2d

Browse files
ViralBShahclaude
andcommitted
ld128: fix coshl returning 1+x instead of 1 for tiny |x|
The early-exit branch in coshl for tiny |x| returned `w = 1 + expm1l(x)`, which is ~1+x for representable small x, not 1. Reproduced on AArch64 (112-bit mantissa) per #285: coshl(0x1p-72) = 0x1.000000000000000001p+0 (should be 1.0) cosh(x) = 1 + x^2/2 + O(x^4); for any |x| < 2^-71 the x^2/2 term is below ulp(1) = 2^-112, so returning exactly 1 is correctly rounded. Also fix the threshold comment: 0x3fb80000 is exp 0x3fb8 - bias 0x3fff = -71, not -116. Closes #285. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent aeef4da commit 100ab2d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

ld128/e_coshl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ coshl(long double x)
7575
{
7676
t = expm1l (u.value);
7777
w = one + t;
78-
if (ex < 0x3fb80000) /* |x| < 2^-116 */
79-
return w; /* cosh(tiny) = 1 */
78+
if (ex < 0x3fb80000) /* |x| < 2^-71 */
79+
return one; /* cosh(tiny) = 1 */
8080

8181
return one + (t * t) / (w + w);
8282
}

0 commit comments

Comments
 (0)