[Python-Dev] RE: [Spambayes] Question (or possibly a bug report)

Tim Peters tim.one@comcast.net
Wed, 23 Jul 2003 23:43:39 -0400


[Mark Hammond]
> Hrm - OK - I bit the bullet, and re-booted as German locale.  If I
> remove all calls to setlocale(), I can provoke come *very* strange
> math errors.
> Both:
>
>  File "E:\src\spambayes\Outlook2000\manager.py", line 664, in score
>   return self.bayes.spamprob(bayes_tokenize(email), evidence)
>  File "E:\src\spambayes\spambayes\classifier.py", line 236, in
>               chi2_spamprob
>    S = ln(S) + Sexp * LN2
> exceptions.OverflowError: math range error

Can you investigate this one a bit deeper?  My guess is that

            S *= 1.0 - prob

in the loop before is treating 1.0 as 10.0 due to the .pyc-file
locale-dependent loading problem I detailed earlier, and that S is
overflowing to infinity as a result.  Printing S inside the loop would shed
best light on this, and printing S when the OverflowError occurs would nail
it:

>>> import math
>>> S = 1e200 * 1e200
>>> S
1.#INF
>>> math.log(S)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OverflowError: math range error
>>>

Not all platforms will raise OverflowError on log(infinity), but Windows
Python does.  No platform other than Windows displays infinity as 1.#INF, by
the way (that's what MS C produces).