From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 14 11:58:36 2010 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 509FA1065675; Thu, 14 Oct 2010 11:58:36 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 6927A8FC1B; Thu, 14 Oct 2010 11:58:34 +0000 (UTC) Received: from odyssey.starpoint.kiev.ua (alpha-e.starpoint.kiev.ua [212.40.38.101]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id OAA02566; Thu, 14 Oct 2010 14:58:32 +0300 (EEST) (envelope-from avg@icyb.net.ua) Message-ID: <4CB6F068.1070406@icyb.net.ua> Date: Thu, 14 Oct 2010 14:58:32 +0300 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.9) Gecko/20100920 Lightning/1.0b2 Thunderbird/3.1.4 MIME-Version: 1.0 To: Garrett Cooper References: In-Reply-To: X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@FreeBSD.org 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: Thu, 14 Oct 2010 11:58:36 -0000 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