Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Oct 2010 14:58:32 +0300
From:      Andriy Gapon <avg@icyb.net.ua>
To:        Garrett Cooper <gcooper@FreeBSD.org>
Cc:        freebsd-hackers@FreeBSD.org
Subject:   Re: [PATCH] Bug with powerof2 macro in sys/param.h
Message-ID:  <4CB6F068.1070406@icyb.net.ua>
In-Reply-To: <AANLkTi=0PSp2KpFTAHTAoosRYdcewiVAxweH4=ivYTLt@mail.gmail.com>
References:  <AANLkTi=0PSp2KpFTAHTAoosRYdcewiVAxweH4=ivYTLt@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4CB6F068.1070406>