zsh-workers
 help / color / mirror / code / Atom feed
From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-workers@zsh.org
Subject: Re: zsh converts a floating-point number to string with too much precision
Date: Sat, 21 Dec 2019 01:50:05 +0100	[thread overview]
Message-ID: <20191221005005.GB767822@zira.vinc17.org> (raw)
In-Reply-To: <CAN=4vMqh7UH00wH6YE2DtnwqUcoH4+uoChEKr1W4hsZiq1A36A@mail.gmail.com>

On 2019-12-20 18:12:18 +0100, Roman Perepelitsa wrote:
> I think what Vincent meant is that zsh should produce the shortest
> string that, when parsed, results in a value equal to the original.
> 
> For your example, "1.1" is the shortest string that parses into
> floating point value equal to the original, hence this (according to
> Vincent) is what zsh should produce.

Yes, this is exactly what I meant, and what Java's System.out.println
seems to do. This is also specified like that in XPath.

I think that's the best compromise in practice.

> Many languages and libraries do this sort of thing. The roundtrip
> guarantee is sometimes limited to the same machine. That is, some
> implementation don't guarantee that you can serialize a floating point
> value on one machine, parse it on another and get the same value.

The roundtrip guarantee is associated with the floating-point format.
If you don't know what format will be used when parsing the string,
then you need to store the exact value (this is always possible for
binary numbers written in decimal, but can take many digits, up to
something around the absolute value of the minimum exponent).

-- 
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:[~2019-12-21  0:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-20  1:37 Vincent Lefevre
2019-12-20  3:38 ` Mikael Magnusson
2019-12-20 16:58 ` Stephane Chazelas
2019-12-20 17:12   ` Roman Perepelitsa
2019-12-21  0:50     ` Vincent Lefevre [this message]
2019-12-21  8:47       ` Stephane Chazelas
2019-12-21  9:43         ` Roman Perepelitsa
2019-12-21 17:56           ` Stephane Chazelas
2019-12-21 18:11             ` Stephane Chazelas
2019-12-21 18:20               ` Roman Perepelitsa
2019-12-21 21:28         ` Vincent Lefevre
2019-12-21  1:00   ` Vincent Lefevre

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=20191221005005.GB767822@zira.vinc17.org \
    --to=vincent@vinc17.net \
    --cc=zsh-workers@zsh.org \
    /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/zsh/

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).