[PATCH] Bug with powerof2 macro in sys/param.h

Andriy Gapon avg at icyb.net.ua
Thu Oct 14 11:58:36 UTC 2010


on 14/10/2010 00:30 Garrett Cooper said the following:
>     I was talking to someone today about this macro, and he noted that
> the algorithm is incorrect -- it fails the base case with ((x) == 0 --
> which makes sense because 2^(x) cannot equal 0 (mathematically
> impossible, unless you consider the limit as x goes to negative
> infinity as log (0) / log(2) is undefined). I tested out his claim and
> he was right:

That's kind of obvious given the code.
I think that this might be an intentional optimization.
I guess that it doesn't really make sense to apply powerof2 to zero and the users
of the macro should do the check on their own if they expect zero as input (many
places in the do not allow that).

-- 
Andriy Gapon


More information about the freebsd-hackers mailing list