mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: newbie nullzwei <newbie-02@gmx.de>
Cc: musl@lists.openwall.com
Subject: Re: Re: [musl] DTOA: question about rendering / code pointer
Date: Wed, 17 May 2023 09:09:18 -0400	[thread overview]
Message-ID: <20230517130918.GN4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <trinity-ed37f7ac-283e-4b00-a39f-fcae8d83ee80-1684309263348@3c-app-gmx-bap41>

On Wed, May 17, 2023 at 09:41:03AM +0200, newbie nullzwei wrote:
> 
> @Rich: thank you for fast comment,
> 
> > musl always, and very intentionally, performs correct rounding
> according to the current rounding direction for all conversions
> to/from decimal.
> 
> yes, there is a tension if and where 'correctly rounded' is still or
> no longer useful. From a decimal point of view, and thus that of
> many users, it loses usefulness at the point where it prefers the
> inaccuracy of the binary representation over the decimal 'equivalent'.

There is no inaccuracy of the binary representation. It's an exact
number. The calculation that led to it might have been exact, but
floating point represents particular exact diadic rational numbers.
The musl list is not really the venue to argue over a philosophy that
they should be interpreted differently than how they're specified.

> I have also considered and researched alternatives, but it would
> be a bigger change, and brings new, e.g. licensing difficulties.
> The current best SRT solutions are not simpler, see ryu, Schubfach,
> SwiftDtoa ... they are really clobbering to be accurate and fast,
> I was positively surprised that musl added with trial and error
> afterburner can keep up well.
> If there is a version of your code with more comments, or if you can
> explain to me where the last digit is constructed / rounded and which
> variables mean what there, I would like to try to patch it. ( I know,
> professionals read such like a shopping list, I unfortunately do not ).

I don't have particular knowledge/experience with the algorithms to
get shortest-round-trip forms. The implementations we have for
conversion are largely straightforward decimal (base-1-billion) bignum
with only a scaling operation (by powers of two) implemented on each.
The decimal to binary direction in particular has comments explaining
the steps.

Identifying what changes you would have to make to code like this to
get the behavior you want seems like a nontrivial math problem. You're
welcome to pursue it for your purposes in reusing the code, but I
still think you'd be better off finding a suitably-licensed and
suitable-language implementation of a known-good algorithm for what
you want, or reading some of the literature to figure out how to write
your own.

Rich

      reply	other threads:[~2023-05-17 13:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 18:49 newbie nullzwei
2023-05-16 19:36 ` Rich Felker
2023-05-16 19:46   ` alice
2023-05-17  7:41   ` Aw: " newbie nullzwei
2023-05-17 13:09     ` Rich Felker [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=20230517130918.GN4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).