summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/modmath.c10
-rw-r--r--py/mpconfig.h5
2 files changed, 15 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
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 98893ceb6d..94fdca7d7a 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -1393,6 +1393,11 @@ typedef double mp_float_t;
#define MICROPY_PY_MATH_POW_FIX_NAN (0)
#endif
+// Whether to provide fix for gamma(-inf) to raise ValueError
+#ifndef MICROPY_PY_MATH_GAMMA_FIX_NEGINF
+#define MICROPY_PY_MATH_GAMMA_FIX_NEGINF (0)
+#endif
+
// Whether to provide "cmath" module
#ifndef MICROPY_PY_CMATH
#define MICROPY_PY_CMATH (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)