Fix ldbl-128ibm atanl spurious underflows (bug 14871)

Joseph S. Myers joseph@codesourcery.com
Thu Nov 22 17:29:00 GMT 2012


This patch fixes spurious underflows for atanl for ldbl-128ibm, bug
14871, in a similar way to the ldbl-128 fix.  Since there were such
underflows for small inputs, not shown by the testsuite, as well as
for large inputs, shown by existing tests, this patch adds new tests
to the testsuite for small inputs to atan.

Tested that this eliminates the spurious underflow exceptions on
powerpc, and that no new ulps are needed for the new tests on x86_64 /
x86.

2012-11-22  Joseph Myers  <joseph@codesourcery.com>

	[BZ #14871]
	* sysdeps/ieee754/ldbl-128ibm/s_atanl.c (__atanl): Return the
	input for small inputs.  Return +/- pi/2 for large inputs.
	* math/libm-test.inc (atan_test): Add more tests.

diff --git a/math/libm-test.inc b/math/libm-test.inc
index b96f1bf..cae2de4 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -1195,6 +1195,14 @@ atan_test (void)
 
   TEST_f_f (atan, 0.75L, 0.643501108793284386802809228717322638L);
 
+  TEST_f_f (atan, 0x1p-100L, 0x1p-100L);
+#ifndef TEST_FLOAT
+  TEST_f_f (atan, 0x1p-600L, 0x1p-600L);
+#endif
+#if defined TEST_LDOUBLE && LDBL_MIN_EXP <= -16381
+  TEST_f_f (atan, 0x1p-10000L, 0x1p-10000L);
+#endif
+
   END (atan);
 }
 
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_atanl.c b/sysdeps/ieee754/ldbl-128ibm/s_atanl.c
index 779209d..2a36d16 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_atanl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_atanl.c
@@ -199,6 +199,22 @@ __atanl (long double x)
 	return atantbl[83];
     }
 
+  if (k <= 0x3c800000) /* |x| <= 2**-55.  */
+    {
+      /* Raise inexact.  */
+      if (1e300L + x > 0.0)
+	return x;
+    }
+
+  if (k >= 0x46c00000) /* |x| >= 2**109.  */
+    {
+      /* Saturate result to {-,+}pi/2.  */
+      if (sign)
+	return -atantbl[83];
+      else
+	return atantbl[83];
+    }
+
   if (sign)
       x = -x;
 

-- 
Joseph S. Myers
joseph@codesourcery.com



More information about the Libc-alpha mailing list