about summary refs log tree commit diff
path: root/sysdeps/ieee754/ldbl-128
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2013-12-22 20:50:16 +0000
committerJoseph Myers <joseph@codesourcery.com>2013-12-22 20:50:16 +0000
commit4f40e4b30754c678b7f93cfb9a545deb534f7e4e (patch)
tree7663c28ef56895f2228dda4b94c7d8d9dc36f0be /sysdeps/ieee754/ldbl-128
parentef7344f09c5ce00eb519ed14598b2a8e39c68387 (diff)
downloadglibc-4f40e4b30754c678b7f93cfb9a545deb534f7e4e.tar.gz
glibc-4f40e4b30754c678b7f93cfb9a545deb534f7e4e.tar.xz
glibc-4f40e4b30754c678b7f93cfb9a545deb534f7e4e.zip
Fix ldbl-128 lgammal for small negative arguments (bug 16337).
This patch fixes bug 16337, ldbl-128 lgammal spurious overflows for
small negative arguments (the arguments in question are already in the
testsuite).  The implementation uses the reflection formula to compute
lgamma of negative x from lgamma of -x, effectively resulting in a
calculation -log(x^2) + log(-x); cancellation isn't problematic in
this case (bugs for problematic cancellation in lgamma are 2542, 2543,
2558), but the x^2 calculation can underflow (in which case there is
spurious logic to return an overflowing value - lgamma can only ever
correctly overflow for large positive arguments, though tgamma can
overflow for small arguments of either sign as well as large positive
arguments).  The fix is simply to calculate the result directly with
logl when the argument is a small enough negative number.

Tested mips64.

	* sysdeps/ieee754/ldbl-128/e_lgammal_r.c (__ieee754_lgammal_r):
	Calculate results for small negative arguments directly rather
	than using reflection formula with special underflow handling.
Diffstat (limited to 'sysdeps/ieee754/ldbl-128')
-rw-r--r--sysdeps/ieee754/ldbl-128/e_lgammal_r.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sysdeps/ieee754/ldbl-128/e_lgammal_r.c b/sysdeps/ieee754/ldbl-128/e_lgammal_r.c
index 2b44afb759..23ab9b9a43 100644
--- a/sysdeps/ieee754/ldbl-128/e_lgammal_r.c
+++ b/sysdeps/ieee754/ldbl-128/e_lgammal_r.c
@@ -782,6 +782,8 @@ __ieee754_lgammal_r (long double x, int *signgamp)
 	*signgamp = -1;
       else
 	*signgamp = 1;
+      if (q < 0x1p-120L)
+	return -__logl (q);
       z = q - p;
       if (z > 0.5L)
 	{
@@ -789,8 +791,6 @@ __ieee754_lgammal_r (long double x, int *signgamp)
 	  z = p - q;
 	}
       z = q * __sinl (PIL * z);
-      if (z == 0.0L)
-	return (*signgamp * huge * huge);
       w = __ieee754_lgammal_r (q, &i);
       z = __logl (PIL / z) - w;
       return (z);