public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Vincent Lefevre <vincent@vinc17.net>
To: Morten Welinder <mwelinder@gmail.com>
Cc: Alejandro Colomar <alx@kernel.org>,
	libc-alpha@sourceware.org,
	Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Subject: Re: [PATCH] manual: logb(x) is floor(log2(fabs(x)))
Date: Tue, 5 Mar 2024 16:01:31 +0100	[thread overview]
Message-ID: <20240305150131.GD3653@qaa.vinc17.org> (raw)
In-Reply-To: <CANv4PNm-Na7Q9en6tuc1UUAYqTSYqz098vKde7uqUCML=cbsxA@mail.gmail.com>

On 2024-03-05 08:16:09 -0500, Morten Welinder wrote:
> > 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.
> 
> Right you are.
> 
> However, the formula is meant as an explanation, not a C code
> substitute, so I think a bit of rewording can fix it.  Something like
> 
> ...works like "floor (log2 (fabs (x)))" if that formula is computed
> without rounding of intermediate values.

I don't think that giving an explanation as code is a good idea.
Giving a math formula is OK, though. Also note that a math formula
could be given for any radix, not just 2: floor(log_b |x|). I think
that this is important since there are 3 conventions to define an
exponent. So this must be explicit in any radix.

BTW, "These functions extract the exponent from the internal
floating-point representation of x and return it as a floating-point
value." should not use the word "representation", because this has
nothing to do with the representation (think of numbers that are not
normalized). And "extract" is misleading too, because for numbers
that are not normalized, the exponent is not extracted.

Something like

  These functions return the exponent of the floating-point number x
  (in radix FLT_RADIX) as a floating-point value.

> Same story as fma really.

No, not really. For fma, this is a math formula followed by rounding.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

      reply	other threads:[~2024-03-05 15:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <ZeZIVzJ_Wl42SnF2@debian>
2024-03-04 22:40 ` Alejandro Colomar
2024-03-05 10:02   ` Vincent Lefevre
2024-03-05 11:10     ` Alejandro Colomar
2024-03-05 11:37       ` Vincent Lefevre
2024-03-05 12:30         ` Alejandro Colomar
2024-03-05 13:16     ` Morten Welinder
2024-03-05 15:01       ` Vincent Lefevre [this message]

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=20240305150131.GD3653@qaa.vinc17.org \
    --to=vincent@vinc17.net \
    --cc=adhemerval.zanella@linaro.org \
    --cc=alx@kernel.org \
    --cc=libc-alpha@sourceware.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).