math.erfc OverflowError

G

geremy condra

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?

Geremy Condra
 
S

Steven D'Aprano

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?


Geremy, I know that as a general rule, whenever a person finds what seems
to be a bug in Python (or the standard library) they should suspect their
own mistake rather than a bug, but I think this is taking caution to
extremes. The domain of erfc is the set of all real numbers, and the
result is bounded by [0, 2]. So asking if OverflowError is desired
behaviour is a bit like the fellow who bought a new car and then asked if
it's supposed to catch fire when starting the engine...

:)
 
G

geremy condra

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?


Geremy, I know that as a general rule, whenever a person finds what seems
to be a bug in Python (or the standard library) they should suspect their
own mistake rather than a bug, but I think this is taking caution to
extremes. The domain of erfc is the set of all real numbers, and the
result is bounded by [0, 2]. So asking if OverflowError is desired
behaviour is a bit like the fellow who bought a new car and then asked if
it's supposed to catch fire when starting the engine...

:)

Well, that was more or less my feeling on it, but as a general rule
my opinion on math in python doesn't seem to be shared, so I
thought I'd ask.

Geremy Condra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top