Index: Modules/mathmodule.c =================================================================== --- Modules/mathmodule.c (revision 81964) +++ Modules/mathmodule.c (working copy) @@ -453,8 +453,8 @@ static double m_erfc_contfrac(double x) { - double x2, a, da, p, p_last, q, q_last, b; - int i; + double x2, a, da, p, p_last, q, q_last, b, result; + int i, saved_errno; if (x >= ERFC_CONTFRAC_CUTOFF) return 0.0; @@ -472,7 +472,12 @@ temp = p; p = b*p - a*p_last; p_last = temp; temp = q; q = b*q - a*q_last; q_last = temp; } - return p / q * x * exp(-x2) / sqrtpi; + /* Issue #8986: On some platforms, exp sets errno on underflow to zero; + save the current errno value so that we can restore it later. */ + saved_errno = errno; + result = p / q * x * exp(-x2) / sqrtpi; + errno = saved_errno; + return result; } /* Error function erf(x), for general x */