diff mbox

Fix ldbl-128 expm1l spurious underflow (bug 16539)

Message ID Pine.LNX.4.64.1406301642040.29755@digraph.polyomino.org.uk
State Committed
Headers show

Commit Message

Joseph Myers June 30, 2014, 4:42 p.m. UTC
This patch fixes spurious underflows from ldbl-128 expm1l, as reported
in <https://sourceware.org/ml/libc-alpha/2014-06/msg00835.html> and
exposed by the tests added for such a bug in the x86 / x86-64
version.  The bug and fix are essentially the same, so no separate bug
is filed in Bugzilla.

Tested for mips64.

2014-06-30  Joseph Myers  <joseph@codesourcery.com>

	[BZ #16539]
	* sysdeps/ieee754/ldbl-128/s_expm1l.c: Include <float.h>.
	(__expm1l): Return argument unchanged when small but not
	subnormal.

Comments

Andreas Jaeger June 30, 2014, 5:15 p.m. UTC | #1
On 06/30/2014 06:42 PM, Joseph S. Myers wrote:
> This patch fixes spurious underflows from ldbl-128 expm1l, as reported
> in <https://sourceware.org/ml/libc-alpha/2014-06/msg00835.html> and
> exposed by the tests added for such a bug in the x86 / x86-64
> version.  The bug and fix are essentially the same, so no separate bug
> is filed in Bugzilla.
> 
> Tested for mips64.

Thanks,
Andreas
diff mbox

Patch

diff --git a/sysdeps/ieee754/ldbl-128/s_expm1l.c b/sysdeps/ieee754/ldbl-128/s_expm1l.c
index 1c12109..f708af5 100644
--- a/sysdeps/ieee754/ldbl-128/s_expm1l.c
+++ b/sysdeps/ieee754/ldbl-128/s_expm1l.c
@@ -54,6 +54,7 @@ 
 
 
 #include <errno.h>
+#include <float.h>
 #include <math.h>
 #include <math_private.h>
 
@@ -136,6 +137,10 @@  __expm1l (long double x)
   if (x < minarg)
     return (4.0/big - 1.0L);
 
+  /* Avoid internal underflow when result does not underflow.  */
+  if (fabsl (x) < 0x1p-113L && fabsl (x) >= LDBL_MIN)
+    return x;
+
   /* Express x = ln 2 (k + remainder), remainder not exceeding 1/2. */
   xx = C1 + C2;			/* ln 2. */
   px = __floorl (0.5 + x / xx);