unofficial mirror of libc-alpha@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-alpha@sourceware.org,
	jsm-csl@polyomino.org.uk, newbie-02@gmx.de
Subject: Re: Man page issues: logb, significand, cbrt, log2, log10, exp10
Date: Sat, 2 Mar 2024 22:54:16 +0100	[thread overview]
Message-ID: <ZeOgFPCtzqY90kIR@debian> (raw)
In-Reply-To: <CANv4PNmMpiwfv5acr7U6VEVe7PE_AMTzkkpNoNN9jrtVzk_93Q@mail.gmail.com>

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

[CC += glibc, and those involved in the glibc bug report]

Hi Morten,

On Sat, Mar 02, 2024 at 04:17:36PM -0500, Morten Welinder wrote:
> I think what happens is that the compiler (not glibc) computes that
> exp10 for you and that the compiler happens to be more accurate.
> Here's what I get for the loop:
> 
>   for (int i = 1; i < 20; i++) {
>     printf ("%.20g\n", exp10 (i));
>   }
> 
> welinder@CarbonX1:~$ ./a.out
> 10
> 100
> 1000.0000000000001137
> 10000.000000000001819
> 100000
> 1000000
> 9999999.9999999981374
> 99999999.999999985099
> 999999999.99999988079
> 10000000000
> 100000000000
> 1000000000000
> 10000000000000
> 100000000000000
> 1000000000000000
> 10000000000000000
> 99999999999999984
> 1000000000000000000
> 10000000000000000000
> 
> Here's the bug report to go with this:
> https://sourceware.org/bugzilla/show_bug.cgi?id=28472
> Note comment 6.  It is clearly not a high-priority item for glibc.

Thanks for that link.

I agree with glibc that the standard specifies that these functions need
not be precise.  That lost precission probably results in better
performance.  Most programs won't care that these functions are
inaccurate.

If you need a correctly-rounded version of these functions, which is
perfectly reasonable, the right thing to ask is that libc implements
the cr_ version of these functions.

I also understand that adding functions to glibc isn't straightforward,
so glibc maintainers have reasons to not do it at the moment.  In fact,
lately I've been leaning towards thinking that libc is a huge monster to
which nothing more should be added, at all.

How about writing a new library --maybe call it libm-cr, maybe
libm-cr-pow, maybe libm-cr-exp10, depending on how extensive you want
it-- and add cr_exp10(3) to that library?  You could do that, and just
support the systems you need to support.  The effort would be certainly
smaller than adding the function to glibc.

Regarding the manual pages, I don't remember from the top of my head if
there's any page documenting that libm functions are imprecise.  I would
prefer documenting it in one place, rather than adding caveats to every
libm page.

> 
> M.

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 --]

       reply	other threads:[~2024-03-02 21:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CANv4PNkVv_0eLgiSP3L_KfC-eZJaVLZ5AP1AGfD0GNrR5M4Hrg@mail.gmail.com>
     [not found] ` <ZeEnJB96mMC5bfBz@debian>
     [not found]   ` <CANv4PNmMpiwfv5acr7U6VEVe7PE_AMTzkkpNoNN9jrtVzk_93Q@mail.gmail.com>
2024-03-02 21:54     ` Alejandro Colomar [this message]
2024-03-03  2:02       ` Man page issues: logb, significand, cbrt, log2, log10, exp10 Morten Welinder
2024-03-03  2:21         ` Alejandro Colomar
2024-03-03 11:46           ` Vincent Lefevre
2024-03-03 12:21             ` Alejandro Colomar
2024-03-03 22:26               ` Morten Welinder
2024-03-04 12:17         ` Adhemerval Zanella Netto
2024-03-05 16:12 ` [PATCH v2 0/3] manual/math.texi: logb(3) and cbrt(3) fixes Alejandro Colomar
2024-03-05 16:12   ` [PATCH v2 1/3] manual: logb(x) is floor(log2(fabs(x))) Alejandro Colomar
2024-03-29 22:08     ` DJ Delorie
2024-03-29 23:00       ` Alejandro Colomar
2024-03-05 16:12   ` [PATCH v2 2/3] manual: floor(log2(fabs(x))) has rounding errors Alejandro Colomar
2024-03-30  0:24     ` DJ Delorie
2024-03-30  9:27       ` Alejandro Colomar
2024-03-30  9:30         ` Alejandro Colomar
2024-03-30  9:47       ` Andreas Schwab
2024-03-05 16:12   ` [PATCH v2 3/3] manual: Cube roots are rarely representable Alejandro Colomar
2024-03-30  0:27     ` DJ Delorie
2024-03-30  7:07       ` Paul Zimmermann
2024-03-30 16:51         ` DJ Delorie
2024-03-30 18:42           ` Alejandro Colomar
2024-03-30 18:50             ` DJ Delorie
2024-03-30 19:07               ` Alejandro Colomar
2024-03-31 20:38   ` [PATCH v3 0/4] manual: arith.texi and math.texi fixes Alejandro Colomar
2024-03-31 20:38     ` [PATCH v3 1/4] manual: logb(x) is floor(log2(fabs(x))) Alejandro Colomar
2024-03-31 20:38     ` [PATCH v3 2/4] manual: floor(log2(fabs(x))) has rounding errors Alejandro Colomar
2024-03-31 20:38     ` [PATCH v3 3/4] manual: Clarify return value of cbrt(3) Alejandro Colomar
2024-04-01 18:57       ` DJ Delorie
2024-03-31 20:38     ` [PATCH v3 4/4] manual: significand() uses FLT_RADIX, not 2 Alejandro Colomar
2024-04-01 19:09       ` DJ Delorie
2024-03-04 15:29 Man page issues: logb, significand, cbrt, log2, log10, exp10 Wilco Dijkstra
2024-03-05  8:14 ` Paul Zimmermann

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

  List information: https://www.gnu.org/software/libc/involved.html

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

  git send-email \
    --in-reply-to=ZeOgFPCtzqY90kIR@debian \
    --to=alx@kernel.org \
    --cc=jsm-csl@polyomino.org.uk \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mwelinder@gmail.com \
    --cc=newbie-02@gmx.de \
    /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).