math.erfc OverflowError

Mark Dickinson dickinsm at gmail.com
Sun Jun 13 16:08:38 EDT 2010


On Jun 13, 12:56 am, geremy condra <debat... at gmail.com> wrote:
> On Sat, Jun 12, 2010 at 4:40 PM, Robert Kern <robert.k... at gmail.com> wrote:
> > On 2010-06-12 17:49 , geremy condra wrote:
>
> >> In Python3.2, calling math.erfc with a value in [-27.2, -30) raises
> >> an OverflowError: math range error. This is inconsistent with the
> >> erfc function from scipy (scipy.special.erfc) as well as with the C99
> >> function by the same name, both of which return 2. I suspect that
> >> this is the result of the cutoff for the use of the continuing fraction
> >> approximation of erfc beginning when abs(x)>  30, but I'm not sure.
> >> Is this desired behavior or should I file a bug report?
>
> > Bug, I think.
>
> Bug filed,http://bugs.python.org/issue8986.

A bug indeed.  Many thanks for catching and reporting this, Geremy;
it would have been embarrassing for Python 2.7 to be released with
this bug in it.  (Well, I would have been embarrassed, anyway; not
sure about anyone else.)

In case anyone cares, the bug was due to a misinterpreted "errno"
value:  there's an "exp(-x*x)" term in the formulas for erf(x) and
erfc(x), and that term underflows to zero at abs(x) =
sqrt(1075*log(2)), which is around 27.297.  Some system math libraries
(unfortunately not including the ones I tested on;  I *did* test,
honest!) set errno on underflow to zero;  this errno value was then
being misinterpreted as an indication of overflow by Python's general
libm wrappings.

Anyway, it's fixed now.

--
Mark



More information about the Python-list mailing list