[PATCH 1/3] libm: Fix sign value returned from __ieee754_lgamma*_r(-0)
Keith Packard
keithp@keithp.com
Wed Aug 26 17:03:55 GMT 2020
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(-)
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
More information about the Newlib
mailing list