From owner-freebsd-hackers@FreeBSD.ORG Fri Oct 15 12:27:55 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2001:4f8:fff6::35]) by hub.freebsd.org (Postfix) with ESMTP id E81281065670 for ; Fri, 15 Oct 2010 12:27:55 +0000 (UTC) (envelope-from cperciva@freebsd.org) Received: from xps.daemonology.net (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx2.freebsd.org (Postfix) with SMTP id 992F914EC81 for ; Fri, 15 Oct 2010 12:27:55 +0000 (UTC) Received: (qmail 1569 invoked from network); 15 Oct 2010 12:27:55 -0000 Received: from unknown (HELO xps.daemonology.net) (127.0.0.1) by localhost with SMTP; 15 Oct 2010 12:27:55 -0000 Message-ID: <4CB848CB.9090502@freebsd.org> Date: Fri, 15 Oct 2010 05:27:55 -0700 From: Colin Percival User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.1.11) Gecko/20100803 Thunderbird/3.0.6 MIME-Version: 1.0 To: freebsd-hackers@freebsd.org References: <20101014120030.938F6106571F@hub.freebsd.org> In-Reply-To: <20101014120030.938F6106571F@hub.freebsd.org> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PATCH] Bug with powerof2 macro in sys/param.h X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Oct 2010 12:27:56 -0000 Garrett Cooper 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