Date: Fri, 15 Oct 2010 05:27:55 -0700 From: Colin Percival <cperciva@freebsd.org> To: freebsd-hackers@freebsd.org Subject: Re: [PATCH] Bug with powerof2 macro in sys/param.h Message-ID: <4CB848CB.9090502@freebsd.org> In-Reply-To: <20101014120030.938F6106571F@hub.freebsd.org> References: <20101014120030.938F6106571F@hub.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Garrett Cooper <gcooper@FreeBSD.org> wrote:
> 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).
Integer arithmetic on all platforms FreeBSD supports is in
the ring Z_{2^n} for appropriate values of n; and in this
ring, 2^n is equal to 0.
If you arbitrarily declare that !powerof2(0), then you get
into the bizarre situation of powerof2(x) && !powerof2(2*x)
for x = 1 << (n - 1); this seems far more astonishing than
the well-understood fact that machine arithmetic operates
with a modular ring, so it seems to me that your proposed
patch would do more harm than good.
--
Colin Percival
Security Officer, FreeBSD | freebsd.org | The power to serve
Founder / author, Tarsnap | tarsnap.com | Online backups for the truly paranoid
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4CB848CB.9090502>
