diff -r 32a4e7b337c9 Modules/mathmodule.c --- a/Modules/mathmodule.c Fri Jan 15 02:37:21 2016 +0000 +++ b/Modules/mathmodule.c Fri Jan 15 13:38:51 2016 +0200 @@ -66,6 +66,8 @@ static const double pi = 3.1415926535897 static const double sqrtpi = 1.772453850905516027298167483341145182798; static const double logpi = 1.144729885849400174143427351353058711647; +#if !defined(HAVE_TGAMMA) || !defined(HAVE_LGAMMA) + static double sinpi(double x) { @@ -222,6 +224,7 @@ lanczos_sum(double x) } return num/den; } +#endif /* !defined(HAVE_TGAMMA) || !defined(HAVE_LGAMMA) */ /* Constant for +infinity, generated in the same way as float('inf'). */ @@ -255,6 +258,14 @@ m_nan(void) static double m_tgamma(double x) { +#ifdef HAVE_TGAMMA + if (x == 0.0) { + errno = EDOM; + /* tgamma(+-0.0) = +-inf, divide-by-zero */ + return copysign(Py_HUGE_VAL, x); + } + return tgamma(x); +#else double absx, r, y, z, sqrtpow; /* special cases */ @@ -346,6 +357,7 @@ m_tgamma(double x) if (Py_IS_INFINITY(r)) errno = ERANGE; return r; +#endif } /* @@ -356,7 +368,17 @@ m_tgamma(double x) static double m_lgamma(double x) { - double r, absx; + double r; + +#ifdef HAVE_LGAMMA + r = lgamma(x); + if (errno == ERANGE && x == floor(x) && x <= 0.0) { + errno = EDOM; /* lgamma(n) = inf, divide-by-zero for */ + return Py_HUGE_VAL; /* integers n <= 0 */ + } + return r; +#else + double absx; /* special cases */ if (!Py_IS_FINITE(x)) { @@ -394,8 +416,11 @@ m_lgamma(double x) if (Py_IS_INFINITY(r)) errno = ERANGE; return r; +#endif } +#if !defined(HAVE_ERF) || !defined(HAVE_ERFC) + /* Implementations of the error function erf(x) and the complementary error function erfc(x). @@ -506,11 +531,16 @@ m_erfc_contfrac(double x) return result; } +#endif /* !defined(HAVE_ERF) || !defined(HAVE_ERFC) */ + /* Error function erf(x), for general x */ static double m_erf(double x) { +#ifdef HAVE_ERF + return erf(x); +#else double absx, cf; if (Py_IS_NAN(x)) @@ -522,6 +552,7 @@ m_erf(double x) cf = m_erfc_contfrac(absx); return x > 0.0 ? 1.0 - cf : cf - 1.0; } +#endif } /* Complementary error function erfc(x), for general x. */ @@ -529,6 +560,9 @@ m_erf(double x) static double m_erfc(double x) { +#ifdef HAVE_ERFC + return erfc(x); +#else double absx, cf; if (Py_IS_NAN(x)) @@ -540,6 +574,7 @@ m_erfc(double x) cf = m_erfc_contfrac(absx); return x > 0.0 ? cf : 2.0 - cf; } +#endif } /*