This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix ldbl-128/ldbl-128ibm lgamma spurious "invalid", incorrect signgam (bug 18952) [committed]


The ldbl-128 / ldbl-128ibm implementation of lgammal converts (the
floor of minus) non-integer negative arguments to int to determine the
value of signgam.  When those values are outside the range of int,
this produces spurious "invalid" exceptions and incorrect values of
signgam.  This patch fixes this by instead determining signgam through
comparing half the integer in question to floor of half the integer.

Tested for mips64, x86_64 and x86.  Committed.

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

2015-09-11  Joseph Myers  <joseph@codesourcery.com>

	[BZ #18952]
	* sysdeps/ieee754/ldbl-128/e_lgammal_r.c (__ieee754_lgammal_r): Do
	not convert non-integer negative arguments to int to determine the
	value of signgam.
	* math/auto-libm-test-in: Add more tests of lgamma.
	* math/auto-libm-test-out: Regenerated.

diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in
index 84b3df0..83eb4cf 100644
--- a/math/auto-libm-test-in
+++ b/math/auto-libm-test-in
@@ -2047,6 +2047,9 @@ lgamma -0xffffffffffffffffp-1
 lgamma -0x3ffffffffffffffffffffffffffp-1
 lgamma -0x1ffffffffffffffffffffffffffffp-1
 
+lgamma -0x100000000.8p0
+lgamma -0x100000001.8p0
+
 lgamma -0.25
 lgamma -0.5
 lgamma -0.75
diff --git a/sysdeps/ieee754/ldbl-128/e_lgammal_r.c b/sysdeps/ieee754/ldbl-128/e_lgammal_r.c
index abf0f15..500aacc 100644
--- a/sysdeps/ieee754/ldbl-128/e_lgammal_r.c
+++ b/sysdeps/ieee754/ldbl-128/e_lgammal_r.c
@@ -787,8 +787,8 @@ __ieee754_lgammal_r (long double x, int *signgamp)
       p = __floorl (q);
       if (p == q)
 	return (one / (p - p));
-      i = p;
-      if ((i & 1) == 0)
+      long double halfp = p * 0.5L;
+      if (halfp == __floorl (halfp))
 	*signgamp = -1;
       else
 	*signgamp = 1;

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]