diff mbox series

[libquadmath,pr68686] tgammaq(x) is always negative for noninteger x < 0

Message ID ade57a24-aa87-e990-b2fc-0d9211c7284c@verizon.net
State New
Headers show
Series [libquadmath,pr68686] tgammaq(x) is always negative for noninteger x < 0 | expand

Commit Message

Ed Smith-Rowland Nov. 13, 2017, 6:27 p.m. UTC
Here is a patch for tammaq for negative argument pr68686.

I know about depending on ports from upstream but this was done recently 
and this (tgammaq) was left out.

This patch is basically a one-liner.

I have test cases but libquadmath doesn't have a testsuite.

One test just shows alternating signs for -0.5Q, -1.5Q, -2.5Q, etc.

Another test verifies the Gamma reflection formula:

  tgamma(1-x) * tgamma(x) - pi / sinq(pi*x) is tiny.

Builds on x86_64-linux and tests correctly offline.


OK?
2017-11-10  Edward Smith-Rowland  <3dw4rd@verizon.net>

	PR libquadmath/68686
	* math/tgammaq.c: Correct sign for negative argument.

Comments

Steve Kargl Nov. 14, 2017, 6:10 p.m. UTC | #1
Ed,

gfortran uses libquadmath for support of its REAL(16)
intrinsic subprograms.  I checked the list of intrinsics
and tgamma is current not in the list.  I don't have
time to try Fortran's C interop feature to see if an
ordinary user can access __float128.  While your patch
is probably useful for GCC, I doubr that gfortran in
its current state will use tgammal.  You'll need either
Jakub or Joseph (jsm28) to give an OK.
diff mbox series

Patch

diff --git a/libquadmath/math/tgammaq.c b/libquadmath/math/tgammaq.c
index a07d583..3080094 100644
--- a/libquadmath/math/tgammaq.c
+++ b/libquadmath/math/tgammaq.c
@@ -47,7 +47,9 @@  tgammaq (__float128 x)
     /* x == -Inf.  According to ISO this is NaN.  */
     return x - x;
 
-  /* XXX FIXME.  */
   res = expq (lgammaq (x));
-  return signbitq (x) ? -res : res;
+  if (x > 0.0Q || ((int)(-x) & 1) == 1)
+    return res;
+  else
+    return -res;
 }