diff mbox

Fix ldbl-128 j1l spurious underflows (bug 18612) [committed]

Message ID alpine.DEB.2.10.1506291752000.7278@digraph.polyomino.org.uk
State New
Headers show

Commit Message

Joseph Myers June 29, 2015, 5:52 p.m. UTC
The ldbl-128 implementation of j1l produces spurious underflow
exceptions for some small arguments, as a result of squaring the
argument.  This patch fixes it just to use a linear approximation for
sufficiently small arguments, and then to force an underflow exception
only in the cases where it is required.

Tested for mips64.  Committed.

(auto-libm-test-out diffs omitted below.)

2015-06-29  Joseph Myers  <joseph@codesourcery.com>

	[BZ #18612]
	* sysdeps/ieee754/ldbl-128/e_j1l.c (__ieee754_j1l): For small
	arguments, just return 0.5 times the argument, with underflow
	forced as needed.
	* math/auto-libm-test-in: Add more tests of j1.
	* math/auto-libm-test-out: Regenerated.
diff mbox

Patch

diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in
index 34b02c9..f4313a2 100644
--- a/math/auto-libm-test-in
+++ b/math/auto-libm-test-in
@@ -1812,6 +1812,9 @@  j1 0x1.ff00000000002p+840
 j1 0x1p1023
 j1 0x1p16382
 j1 0x1p16383
+j1 0x1p-100
+j1 0x1p-600
+j1 0x1p-10000
 # Bug 18611: errno setting may be missing.
 j1 min missing-errno
 j1 -min missing-errno
diff --git a/sysdeps/ieee754/ldbl-128/e_j1l.c b/sysdeps/ieee754/ldbl-128/e_j1l.c
index 958077d..591c38e 100644
--- a/sysdeps/ieee754/ldbl-128/e_j1l.c
+++ b/sysdeps/ieee754/ldbl-128/e_j1l.c
@@ -697,6 +697,16 @@  __ieee754_j1l (long double x)
   if (x == 0.0L)
     return x;
   xx = fabsl (x);
+  if (xx <= 0x1p-58L)
+    {
+      long double ret = x * 0.5L;
+      if (fabsl (ret) < LDBL_MIN)
+	{
+	  long double force_underflow = ret * ret;
+	  math_force_eval (force_underflow);
+	}
+      return ret;
+    }
   if (xx <= 2.0L)
     {
       /* 0 <= x <= 2 */