public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx@kernel.org>
To: Morten Welinder <mwelinder@gmail.com>
Cc: linux-man@vger.kernel.org, libc-help@sourceware.org
Subject: logb() vs floor(log2()) (was: Man page issues: logb, significand, cbrt, log2, log10, exp10)
Date: Mon, 4 Mar 2024 18:52:10 +0100	[thread overview]
Message-ID: <ZeYKUOKYS7G90SaV@debian> (raw)
In-Reply-To: <CANv4PNkVv_0eLgiSP3L_KfC-eZJaVLZ5AP1AGfD0GNrR5M4Hrg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1085 bytes --]

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.

Have a lovely day!
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 --]

       reply	other threads:[~2024-03-04 17:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CANv4PNkVv_0eLgiSP3L_KfC-eZJaVLZ5AP1AGfD0GNrR5M4Hrg@mail.gmail.com>
2024-03-04 17:52 ` Alejandro Colomar [this message]
2024-03-04 18:47   ` logb() vs floor(log2()) 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZeYKUOKYS7G90SaV@debian \
    --to=alx@kernel.org \
    --cc=libc-help@sourceware.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mwelinder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).