From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 08fafbca for ; Sat, 21 Dec 2019 00:50:52 +0000 (UTC) Received: (qmail 15745 invoked by alias); 21 Dec 2019 00:50:46 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45102 Received: (qmail 13067 invoked by uid 1010); 21 Dec 2019 00:50:46 -0000 X-Qmail-Scanner-Diagnostics: from joooj.vinc17.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25663. spamassassin: 3.4.2. Clear:RC:0(155.133.131.76):SA:0(-1.9/5.0):. Processed in 2.270639 secs); 21 Dec 2019 00:50:46 -0000 X-Envelope-From: vincent@vinc17.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at vinc17.net does not designate permitted sender hosts) Date: Sat, 21 Dec 2019 01:50:05 +0100 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: zsh converts a floating-point number to string with too much precision Message-ID: <20191221005005.GB767822@zira.vinc17.org> Mail-Followup-To: zsh-workers@zsh.org References: <20191220013711.GA708801@zira.vinc17.org> <20191220165824.ufvjtx37xt7dp2dt@chaz.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/1.12.1+33 (6a74e24e) vl-117499 (2019-06-23) 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 - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)