[spambayes-dev] Mozilla SpamBayes "porting"
Tim Peters
tim.one at comcast.net
Sat Feb 21 12:19:10 EST 2004
[Miguel Vargas]
> In chi2Q you have
>
> for i in range(1, v//2):
>
> I thought // was floor division, that's why I had written floor(v/2).
Ah. // in Python is primarily integer division (as opposed to /, which is
float division). It so happens that integer division in Python returns the
floor of the mathematical quotient, and as an integer (unlike the floor()
function, which maps float to float) , but that's secondary. In any case,
this secondary distinction makes no difference when the mathematical
quotient is exactly representable as an integer, and v divided by 2 is
exactly representable as an integer when v is an even integer.
IOW, an experienced Pythoneer sees "v//2" and first reads it as "OK, v is an
integer and we want an integer result too". Since Python doesn't have type
declarations, Pythoneers can't guess the intended semantics by looking for
v's declaration, so Python uses different operator symbols for integer and
float division. That way the intent is immediately clear (as it will be for
you too the *next* time <wink> you see // in Python code).
More information about the spambayes-dev
mailing list