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=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,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 6fa0c8ab for ; Fri, 20 Dec 2019 03:39:00 +0000 (UTC) Received: (qmail 12430 invoked by alias); 20 Dec 2019 03:38:53 -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: 45094 Received: (qmail 15579 invoked by uid 1010); 20 Dec 2019 03:38:53 -0000 X-Qmail-Scanner-Diagnostics: from mail-io1-f52.google.com 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(209.85.166.52):SA:0(-2.0/5.0):. Processed in 2.250899 secs); 20 Dec 2019 03:38:53 -0000 X-Envelope-From: mikachu@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.166.52 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=FFPaQMpVnSVSFSn0wYMyfofQJixG728HbJleETyxwyI=; b=SEc3gYGQ08ud8VduecVSGayI7tzIBjPtKv01aKg3wXERC6YSHXFW6dFg8LH1ETalgH Vi6gwN1T5UdojvaE2YOgQDtHPWVIeuVx0K6MHQVqUALsHLKI3SPr65mZhA80QMgn992t nfQs9ckiB6+O+yykbiYKd3h1L3u+RMrX14BOYNkHGjlOYbpivyJJrE1rqXBZuhny+FCo WlNbEDJS2I8pxAjUh3KaVcOyzoz1kLU9TFdDMWsB752wuU4U/1FGpa9R/gGoooZegw/F DdISJueib7osECr/JrP0VY16Z6dzbM7qKQG3ErZKl2l9yXI6t3pbnicvr70tnWgDHvKp OU5g== X-Gm-Message-State: APjAAAUCPmIxhBEXChjBU0H1Dx43cxCXWc1nSY/Wq+AdvPESZsTL8MiI 5IQX4oPBSpd5vXfoxWtmFOJ5xxg/SgBo8Wzf0LtwusMx X-Google-Smtp-Source: APXvYqzFUCLnOY+8O4d8pO2ZPv6/0edvYCkpmMN4YzEC5qSBvbx7vHQMxpH5fgIA+gwQlA551DahYYdh+6MijochZcQ= X-Received: by 2002:a6b:fe0f:: with SMTP id x15mr8157258ioh.219.1576813097749; Thu, 19 Dec 2019 19:38:17 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <20191220013711.GA708801@zira.vinc17.org> References: <20191220013711.GA708801@zira.vinc17.org> From: Mikael Magnusson Date: Fri, 20 Dec 2019 04:38:16 +0100 Message-ID: Subject: Re: zsh converts a floating-point number to string with too much precision To: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" On 12/20/19, Vincent Lefevre wrote: > With zsh 5.7.1, I get: > > zira% echo $((1.1)) > 1.1000000000000001 > > because zsh seems to first select the precision independently > from the value, i.e. 17 to be able to convert the string back > to floating point, preserving the original value, then it > outputs the closest number in this precision. > > Instead, zsh should select the minimum precision so that the > inverse conversion can give the original value, i.e. it should > output 1.1 here. You can use typeset -F1 one=1.1 to specify the output precision of a parameter (note that this doesn't affect the float value stored, you can change to -F20 later to display more decimals without reassignment). So in your case you could count the number of digits in the string after the . and then pass that to -F if you wanted to. -- Mikael Magnusson