[1/3] libm: Fix sign value returned from __ieee754_lgamma*_r(-0)

Message ID 20200826170357.2551683-2-keithp@keithp.com
State New
Headers show
Series
  • libm: Clean up gamma functions
Related show

Commit Message

Corinna Vinschen via Newlib Aug. 26, 2020, 5:03 p.m.
The sign of the INFINITY returned from these cases needs to match the
sign of the zero.

Signed-off-by: Keith Packard <keithp@keithp.com>

---
 newlib/libm/math/er_lgamma.c  | 6 +++++-
 newlib/libm/math/erf_lgamma.c | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

-- 
2.28.0

Patch

diff --git a/newlib/libm/math/er_lgamma.c b/newlib/libm/math/er_lgamma.c
index 386a8a73b..36408382f 100644
--- a/newlib/libm/math/er_lgamma.c
+++ b/newlib/libm/math/er_lgamma.c
@@ -225,7 +225,11 @@  static double zero=  0.00000000000000000000e+00;
 	*signgamp = 1;
 	ix = hx&0x7fffffff;
 	if(ix>=0x7ff00000) return x*x;
-	if((ix|lx)==0) return one/zero;
+	if((ix|lx)==0) {
+	    if(hx<0)
+	        *signgamp = -1;
+	    return one/zero;
+	}
 	if(ix<0x3b900000) {	/* |x|<2**-70, return -log(|x|) */
 	    if(hx<0) {
 	        *signgamp = -1;
diff --git a/newlib/libm/math/erf_lgamma.c b/newlib/libm/math/erf_lgamma.c
index 3c6ba02af..a45423949 100644
--- a/newlib/libm/math/erf_lgamma.c
+++ b/newlib/libm/math/erf_lgamma.c
@@ -160,7 +160,11 @@  static float zero=  0.0000000000e+00;
 	*signgamp = 1;
 	ix = hx&0x7fffffff;
 	if(ix>=0x7f800000) return x*x;
-	if(ix==0) return one/zero;
+	if(ix==0) {
+	    if(hx<0)
+	        *signgamp = -1;
+	    return one/zero;
+	}
 	if(ix<0x1c800000) {	/* |x|<2**-70, return -log(|x|) */
 	    if(hx<0) {
 	        *signgamp = -1;