[spambayes-dev] Mozilla SpamBayes "porting"
Kenny Pitt
kennypitt at hotmail.com
Thu Feb 19 12:52:43 EST 2004
Miguel wrote:
> Tim Peters wrote:
>>> 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. Also, I don't understand what the assert does, what does
> the function return if v is odd?
floor(x) takes a floating point value x and finds the largest integer
that is <= x. If x is >= 0, this is equivalent to truncating the
fractional part. If v above is an int then C++ will use integer
arithmetic when computing v/2, which will always truncate the fractional
part. The floor() function is therefore unnecessary and can be removed
from the code.
--
Kenny Pitt
More information about the spambayes-dev
mailing list