[PATCH] manual: logb(x) is floor(log2(fabs(x)))

Alejandro Colomar alx@kernel.org
Tue Mar 5 12:30:14 GMT 2024


Hi Vincent,

On Tue, Mar 05, 2024 at 12:37:38PM +0100, Vincent Lefevre wrote:
> > > > -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)))}

Oops!


> > 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";

Agree; I'll take it, with the "due to ..." too.

> or an example: ", e.g. on DBL_MAX".

I'll omit this.

Have a lovely day!
Alex

-- 
<https://www.alejandro-colomar.es/>
Looking for a remote C programming job at the moment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20240305/7a030899/attachment.sig>


More information about the Libc-alpha mailing list