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 f0e9f6e9 for ; Sat, 21 Dec 2019 01:01:01 +0000 (UTC) Received: (qmail 22362 invoked by alias); 21 Dec 2019 01:00:55 -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: 45103 Received: (qmail 14486 invoked by uid 1010); 21 Dec 2019 01:00:55 -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 1.789727 secs); 21 Dec 2019 01:00:55 -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 02:00:18 +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: <20191221010018.GC767822@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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191220165824.ufvjtx37xt7dp2dt@chaz.gmail.com> 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 16:58:24 +0000, Stephane Chazelas wrote: > https://unix.stackexchange.com/questions/422122/why-does-0-1-expand-to-0-10000000000000001-in-zsh > > Reproduced below for convenience: > > ════════════════════════════════════════════════════════════════ > > TL;DR > > zsh chooses a decimal representation for the double binary > numbers that it uses for evaluating floating point arithmetics > that preserves their information fully, that is safe for reinput > into its arithmetic expressions. But there are several possible decimal representations with this requirement. > And that is done at the expense > of cosmetic. For that, it needs 17 significant digits, and make > sure the expansion always includes a . or e so it's treated as > float on reinput. This is only one way to fulfill the requirement. Here, it was assumed that the output precision is chosen independently from the argument (it seems that zsh chooses printf "%.17g"). But it does not need to be like that. BTW, what zsh does is not documented. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)