From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from joooj.vinc17.net (joooj.vinc17.net [IPv6:2001:4b99:1:3:216:3eff:fe20:ac98]) by sourceware.org (Postfix) with ESMTPS id DDB933858C41 for ; Tue, 5 Mar 2024 10:02:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDB933858C41 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vinc17.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vinc17.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DDB933858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4b99:1:3:216:3eff:fe20:ac98 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709632977; cv=none; b=wWLAVa8mbYwE+yLPL4c10+LG7hDyfmKL6zeEd1v1AOjoXxE5m1iL6qG6Z9pL8YIC9vAsgllfm9EnFT01YAgWoKETT7xqJ4hPmVQvwHZqY+e3ej3qwhw0LEBmaCoX4n5U2AayWjxZc3INg+AQ785jLhQvLM1x1lh6t8X14MEDt8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709632977; c=relaxed/simple; bh=GNT8C7yYuS9Y3nx5DgKjXKUnHxpCnRcpGuI9id78zNc=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=uW7eJXzBxmG1U9g6E0vC+SL54fTZEikz41F9IgvKUcYPMXi7pKMaWhRWxv3TMHinbG7y6LFI6uJJG/K4Jc3NQ66HsnXFrwFG0QqBwHuG2P9sBimk7XmkNg0fQu5o+u94CSI8IqY1seFntw/xHOYMCJSOLOJXCbYbFcXz1Do/Aok= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp-qaa.vinc17.net (135.197.67.86.rev.sfr.net [86.67.197.135]) by joooj.vinc17.net (Postfix) with ESMTPSA id 632D892; Tue, 5 Mar 2024 11:02:52 +0100 (CET) Received: by qaa.vinc17.org (Postfix, from userid 1000) id F0400CA00B1; Tue, 5 Mar 2024 11:02:51 +0100 (CET) Date: Tue, 5 Mar 2024 11:02:51 +0100 From: Vincent Lefevre To: Alejandro Colomar Cc: libc-alpha@sourceware.org, Morten Welinder , Adhemerval Zanella Netto Subject: Re: [PATCH] manual: logb(x) is floor(log2(fabs(x))) Message-ID: <20240305100251.GB3653@qaa.vinc17.org> Mail-Followup-To: Vincent Lefevre , Alejandro Colomar , libc-alpha@sourceware.org, Morten Welinder , Adhemerval Zanella Netto References: <20240304224051.4862-1-alx@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240304224051.4862-1-alx@kernel.org> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.2.12+69 (354c5b11) vl-149028 (2023-12-10) X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2024-03-04 23:40:59 +0100, Alejandro Colomar wrote: > log2(3) doesn't accept negative input, but it seems logb(3) does > accept it. Yes, but unrelated to that, there was an issue with the text before. > Link: > Reported-by: Morten Welinder > Cc: Adhemerval Zanella Netto > Signed-off-by: Alejandro Colomar > --- > manual/math.texi | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/manual/math.texi b/manual/math.texi > index 2f6ee253b9..bf4027c4ee 100644 > --- a/manual/math.texi > +++ b/manual/math.texi > @@ -561,7 +561,7 @@ These functions return the base-2 logarithm of @var{x}. > @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} > These functions extract the exponent of @var{x} and return it as a > floating-point value. If @code{FLT_RADIX} is two, @code{logb} is equal > -to @code{floor (log2 (x))}, except it's probably faster. > +to @code{floor (log2 (fabs ((x)))}, except it's probably faster. No, it isn't necessarily equal. The code floor (log2 (fabs ((x))) can give an incorrect result due to rounding if x is just before a power of 2, in particular if x is large. #include #include #include int main (void) { double x = DBL_MAX; printf ("x = %a\n", x); printf ("%a\n", log2 (fabs (x))); printf ("%a\n", floor (log2 (fabs (x)))); printf ("%a\n", logb (x)); return 0; } outputs x = 0x1.fffffffffffffp+1023 0x1p+10 0x1p+10 0x1.ff8p+9 on an x86_64 machine. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)