From 0cba5165a7f6cd69aca95bf82a9f1437bfa144dc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 25 Aug 2020 09:32:35 -0700 Subject: [PATCH] libm: Fix sign value returned from __ieee754_lgamma*_r(-0) The sign of the INFINITY returned from these cases needs to match the sign of the zero. Signed-off-by: Keith Packard --- newlib/libm/math/er_lgamma.c | 6 +++++- newlib/libm/math/erf_lgamma.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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; -- 2.28.0