summaryrefslogtreecommitdiffstatshomepage
path: root/py/modmath.c
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2024-08-06 09:59:22 +1000
committerDamien George <damien@micropython.org>2024-08-07 14:10:46 +1000
commitb0c89377d0f0a4624577da8ca956f7c33d6b1882 (patch)
treec1562067c8e084dccd38f6b9398696d76c0713b9 /py/modmath.c
parentafba3e054041bbad961fad61df7c4797ab35d9e3 (diff)
downloadmicropython-b0c89377d0f0a4624577da8ca956f7c33d6b1882.tar.gz
micropython-b0c89377d0f0a4624577da8ca956f7c33d6b1882.zip
py/modmath: Add option to work around -inf bug in a port's tgamma.
This is needed for a workaround on esp32 port (in child commit), which produces incorrect results otherwise. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'py/modmath.c')
-rw-r--r--py/modmath.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/py/modmath.c b/py/modmath.c
index db30f0e625..4d51a28d0b 100644
--- a/py/modmath.c
+++ b/py/modmath.c
@@ -196,7 +196,17 @@ MATH_FUN_1(erf, erf)
// erfc(x): return the complementary error function of x
MATH_FUN_1(erfc, erfc)
// gamma(x): return the gamma function of x
+#if MICROPY_PY_MATH_GAMMA_FIX_NEGINF
+static mp_float_t MICROPY_FLOAT_C_FUN(tgamma_func)(mp_float_t x) {
+ if (isinf(x) && x < 0) {
+ math_error();
+ }
+ return MICROPY_FLOAT_C_FUN(tgamma)(x);
+}
+MATH_FUN_1(gamma, tgamma_func)
+#else
MATH_FUN_1(gamma, tgamma)
+#endif
// lgamma(x): return the natural logarithm of the gamma function of x
MATH_FUN_1(lgamma, lgamma)
#endif