[spambayes-dev] RE: [Spambayes] Question (or possibly a bug report)

Tim Peters tim.one at comcast.net
Thu Jul 24 00:43:39 EDT 2003

[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

>>> import math
>>> S = 1e200 * 1e200
>>> S
>>> 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).

More information about the spambayes-dev mailing list