From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from joooj.vinc17.net (joooj.vinc17.net [155.133.131.76]) by sourceware.org (Postfix) with ESMTPS id 0823F3858C56 for ; Tue, 5 Mar 2024 11:37:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0823F3858C56 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 0823F3858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=155.133.131.76 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709638663; cv=none; b=c15JmmWP+U4nyKfnecfcXypW/59kQwzuzdkvFivR0zkfsL8PoDulAA27926LHP70GomKjTPT4UN5qk9REbKaHn2zaeljnoAR0Udcw+6NIRQxOTZa1hE/lrD8QlEcza5HNVPxlA1pKPa93g6uQMEyJcxtpl+ZSWs14XIt+Cqjndw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709638663; c=relaxed/simple; bh=oQwmNSvhJg0dro7j8sEFwqeEBH48YyvdHW5o4APUHqA=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=AT+ldyuLIz+aUa1hSQFgWofNBrLqg3U0bBQqunhCzinNrGytlxBkHJnhCchUcPJXMVjsss96Zo2I75jkDTrXdEVpEYlaolDAoYfcFD1VaAQZXNI8aszwvFvRyIXeKC7gUYOGG2CqvF9W7bJLTk9NDCKYgj6E4VlCd2DKI51iz/o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp-qaa.vinc17.net (2a02-8428-1b1d-4d01-96a9-491d-7b48-ba31.rev.sfr.net [IPv6:2a02:8428:1b1d:4d01:96a9:491d:7b48:ba31]) by joooj.vinc17.net (Postfix) with ESMTPSA id 67B7D92; Tue, 5 Mar 2024 12:37:40 +0100 (CET) Received: by qaa.vinc17.org (Postfix, from userid 1000) id 9EF1ECA00B1; Tue, 5 Mar 2024 12:37:38 +0100 (CET) Date: Tue, 5 Mar 2024 12:37:38 +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: <20240305113738.GC3653@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> <20240305100251.GB3653@qaa.vinc17.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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=-9.1 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,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-05 12:10:23 +0100, Alejandro Colomar wrote: > Hi Vincent! > > On Tue, Mar 05, 2024 at 11:02:51AM +0100, Vincent Lefevre wrote: > > On 2024-03-04 23:40:59 +0100, Alejandro Colomar wrote: > > > 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. BTW, note that there is a missing closing parenthesis, or actually, an opening parenthesis that could be removed, i.e. @code{floor (log2 (fabs (x)))} > > 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. > > Hmmm, the bug is different, so how about a second patch for fixing that? Yes. > For that, I'd do s/equal/similar/ and s/faster/more accurate/. Does it > sound good to you? I think that "more accurate" is misleading because this is actually much more than "more accurate": logb is guaranteed to give the exact result (the result is a small integer, thus exactly representable), while floor (log2 (fabs (x))) may give an incorrect integer (there is a small inaccuracy up to log2, but this becomes a much more important problem due to the fact that floor is mathematically a discontinuous function). I would suggest: @code{logb} is similar to @code{floor (log2 (fabs (x)))}, except that the latter code may give an incorrect integer. If needed, one can add an explanation: "due to intermediate rounding"; or an example: ", e.g. on DBL_MAX". Regards, -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)