[spambayes-dev] Mozilla SpamBayes "porting"

Tim Peters tim.one at comcast.net
Thu Feb 19 12:32:46 EST 2004


[Miguel]
> Adding the "unsure" category to Mozilla is going to be expensive
> resource-wise, so we've decided to put it off for now.
>   We're going to lump the "unsures" in with the hams.  I'm thinking
> that we'll set the default cutoff at 0.9.

That's OK.  "Unsure" turned out to be a valuable concept for most people, so
don't put it off forever <wink>.

>>> Here's the chi2Q funcition:
>>> static double chi2Q (double x2, double v) {

>> v should be int (OK), or unsigned int (better).

>>>         for (i=1;i<=floor(v/2);i++) {

>> If v is int or unsigned int, you'll also get to skip the relatively
>> expensive floor() call on each loop trip.  You should put in the
>> original code's assert that v is even (this algorithm is dead wrong
>> if v is odd).

> I don't understand how making v an int will make it skip the floor
> function.

v must be an even integer >= 0, therefore there's no need to compute floors;
plain v/2 is always exactly correct when v is even.

> Also, I don't understand what the assert does,

Well, assert() is a standard C function.  If you do

    assert((v & 1) == 0);

then, provided you haven't compiled with NDEBUG #define'd, your program
should die if you ever pass an odd integer for v.

> what does the function return if v is odd?

It shouldn't return anything then:  the program should die!  It's as
senseless to use this function for odd v as it is, e.g., to try to
dereference a NULL pointer.  If the rest of your code is correct, it will
never try to call this function with odd v.  An assert() is a way to catch
this error if the rest of the code isn't correct.  As the comments in the
original code said:

        v must be even.

That's a precondition for using chi2Q; an assert would catch violations of
the precondition; the assert() should never fail; if it does, the code
*calling* chi2Q is in error.




More information about the spambayes-dev mailing list