* Re: logb() vs floor(log2())
2024-03-04 17:52 ` logb() vs floor(log2()) (was: Man page issues: logb, significand, cbrt, log2, log10, exp10) Alejandro Colomar
@ 2024-03-04 18:47 ` Adhemerval Zanella Netto
2024-03-04 22:16 ` Alejandro Colomar
2024-03-04 23:23 ` logb() vs floor(log2()) (was: Man page issues: logb, significand, cbrt, log2, log10, exp10) Alejandro Colomar
1 sibling, 1 reply; 4+ messages in thread
From: Adhemerval Zanella Netto @ 2024-03-04 18:47 UTC (permalink / raw)
To: Alejandro Colomar, Morten Welinder; +Cc: linux-man, libc-help
On 04/03/24 14:52, Alejandro Colomar wrote:
> Hi Morten,
>
> On Thu, Feb 29, 2024 at 07:28:10PM -0500, Morten Welinder wrote:
>> I came across some minor issues in some math man pages.
>>
>> M.
>>
>>
>>
>> logb:
>> The formula "floor(log2(x))" should be "floor(log2(fabs(x)))". (Or
>> ...abs(...) if it's meant to be math and not C.)
>
> Confirmed. This is a bug in glibc too, BTW. That text seems to be
> copied from their manual.
>
> ISO C says this function is specified in ANSI/IEEE 854, but I don't have
> access to that document, so I'm not sure what's the specification of the
> function. I'm not sure if it should fail for negative values (like
> log2(3)) or not; although the standard mentions the behavior for
> negative infinity, so it probably is specified to work for negative
> values too.
>
> So, the behavior of the function seems to be correct, and it's just the
> manual that needs to be fixed.
>
> I've CCed glibc, in case they want to comment. But yeah, your
> suggestion seems correct.
It does seems to be an error on manual, could you send a patch to fix it?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: logb() vs floor(log2()) (was: Man page issues: logb, significand, cbrt, log2, log10, exp10)
2024-03-04 17:52 ` logb() vs floor(log2()) (was: Man page issues: logb, significand, cbrt, log2, log10, exp10) Alejandro Colomar
2024-03-04 18:47 ` logb() vs floor(log2()) Adhemerval Zanella Netto
@ 2024-03-04 23:23 ` Alejandro Colomar
1 sibling, 0 replies; 4+ messages in thread
From: Alejandro Colomar @ 2024-03-04 23:23 UTC (permalink / raw)
To: Morten Welinder; +Cc: linux-man, libc-help, Adhemerval Zanella Netto
[-- Attachment #1: Type: text/plain, Size: 1281 bytes --]
Hi Morten,
On Mon, Mar 04, 2024 at 06:52:10PM +0100, Alejandro Colomar wrote:
> > logb:
> > The formula "floor(log2(x))" should be "floor(log2(fabs(x)))". (Or
> > ...abs(...) if it's meant to be math and not C.)
I've applied thge following patch:
commit 1d83ce827aac984a26430b4f6107182f4b076874 (HEAD -> contrib, alx/contrib)
Author: Alejandro Colomar <alx@kernel.org>
Date: Tue Mar 5 00:20:09 2024 +0100
logb.3: logb(x) is floor(log2(fabs(x)))
log2(3) doesn't accept negative input, but it seems logb(3) does accept
it.
Link: <https://lore.kernel.org/linux-man/ZeYKUOKYS7G90SaV@debian/T/#u>
Reported-by: Morten Welinder <mwelinder@gmail.com>
Cc: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
diff --git a/man3/logb.3 b/man3/logb.3
index 7cbb2470a..7a1ad2f4a 100644
--- a/man3/logb.3
+++ b/man3/logb.3
@@ -58,7 +58,7 @@ .SH DESCRIPTION
is 2,
.BI logb( x )
is equal to
-.BI floor(log2( x ))\fR,
+.BI floor(log2(fabs( x )))\f[R],\f[]
except that it is probably faster.
.P
If
I'll push it tomorrow.
Have a lovely night!
Alex
--
<https://www.alejandro-colomar.es/>
Looking for a remote C programming job at the moment.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread