[PATCH 2/2] Add a missing default case in lgamma
Andoni Arregi
andoni.arregui@gtd-gmbh.de
Thu Feb 10 16:12:40 GMT 2022
The missing default case leads to large errors for |x| in range
[2.0, 3.0[.
In case of i=2, i.e., in the range between [2,3[, the computation
"r += logf(z)" is not performed and hence the result was wrong.
The added default case resolves this issue.
(Courtesy of Andreas Jung, ESA)
---
newlib/libm/math/er_lgamma.c | 1 +
newlib/libm/math/erf_lgamma.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/newlib/libm/math/er_lgamma.c b/newlib/libm/math/er_lgamma.c
index 5c88548fb..65727c6ab 100644
--- a/newlib/libm/math/er_lgamma.c
+++ b/newlib/libm/math/er_lgamma.c
@@ -302,6 +302,7 @@ static double zero= 0.00000000000000000000e+00;
case 5: z *= (y+4.0); /* FALLTHRU */
case 4: z *= (y+3.0); /* FALLTHRU */
case 3: z *= (y+2.0); /* FALLTHRU */
+ default:
r += __ieee754_log(z); break;
}
/* 8.0 <= x < 2**58 */
diff --git a/newlib/libm/math/erf_lgamma.c b/newlib/libm/math/erf_lgamma.c
index 84d02159b..e7311cacf 100644
--- a/newlib/libm/math/erf_lgamma.c
+++ b/newlib/libm/math/erf_lgamma.c
@@ -238,6 +238,7 @@ static float zero= 0.0000000000e+00;
case 5: z *= (y+(float)4.0); /* FALLTHRU */
case 4: z *= (y+(float)3.0); /* FALLTHRU */
case 3: z *= (y+(float)2.0); /* FALLTHRU */
+ default:
r += __ieee754_logf(z); break;
}
/* 8.0 <= x < 2**58 */
--
2.35.1
More information about the Newlib
mailing list