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 aa5d808a for ; Sat, 21 Dec 2019 21:07:23 +0000 (UTC) Received: (qmail 16208 invoked by alias); 21 Dec 2019 18:20: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: 45122 Received: (qmail 24027 invoked by uid 1010); 21 Dec 2019 18:20:53 -0000 X-Qmail-Scanner-Diagnostics: from mail-io1-f41.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.41):SA:0(-2.0/5.0):. Processed in 1.838204 secs); 21 Dec 2019 18:20:53 -0000 X-Envelope-From: roman.perepelitsa@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.41 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:references:in-reply-to:from:date :message-id:subject:to; bh=GZQC41jiyXQ2JD8jmQw2nryHVA/KPCG6jF5A6M/yWGA=; b=mxpiVHIwOA0aeRgKC3gDpHSOapWzaI3qugAIRZPphFk9lImpHZagqdGACyioQdJbHL egEfrs7rQ1WD4kjntdWApewFYygSW2GVcnePnHtyWg6cnArm8mjqjXLPOqfqQLAVBf2w TLKrj4hGc4erq9pHgnrPZjGwO6po1ppUaB99nl/1y/nClnWMSg8VYM5Nhvv3BDvHPYth EbqGLCnKl4h6EC4+HsmYnr3dyZvlLefyb+F77mFzGeW5DwmEbo5CAZmZbFcO+zCwmBmc ZIdlNokg6h3XIlLXb/r/QchZbBj/M8/pyy/7FzAJMNY1wTvOYeQTiarn99KIeatTYfLD 71TQ== X-Gm-Message-State: APjAAAUkaDFhF6bWKEERRfmopAHl2qtvzcx+iwH2jdIvzZ0Fr6pX2E63 s9ziFZlAYuLlOHp+ySrj69lzrBTpr3uyCo2Z6n4= X-Google-Smtp-Source: APXvYqwa/XhI+ws6we7fO4shSvWXupEFkj2CQav2/zGp0JJnKoKkr5r3agt97J5VaFfYIgbBkQV2u6/k8J1DLQZaDRc= X-Received: by 2002:a02:838b:: with SMTP id z11mr17700721jag.127.1576952418567; Sat, 21 Dec 2019 10:20:18 -0800 (PST) MIME-Version: 1.0 References: <20191220013711.GA708801@zira.vinc17.org> <20191220165824.ufvjtx37xt7dp2dt@chaz.gmail.com> <20191221005005.GB767822@zira.vinc17.org> <20191221084736.bokldw7tzxw3thn3@chaz.gmail.com> <20191221175618.oolvw72n26tir2wg@chaz.gmail.com> <20191221181141.wy4ndiq6qyznod22@chaz.gmail.com> In-Reply-To: <20191221181141.wy4ndiq6qyznod22@chaz.gmail.com> From: Roman Perepelitsa Date: Sat, 21 Dec 2019 19:20:07 +0100 Message-ID: Subject: Re: zsh converts a floating-point number to string with too much precision To: Roman Perepelitsa , Zsh hackers list Content-Type: text/plain; charset="UTF-8" On Sat, Dec 21, 2019 at 7:11 PM Stephane Chazelas wrote: > > 2019-12-21 17:56:18 +0000, Stephane Chazelas: > > 2019-12-21 10:43:43 +0100, Roman Perepelitsa: > > [...] > > > There is no simple algorithm that achieves this. I recall reading long > > > papers a few years back that were describing various inventions in > > > this field. They were pretty scary. > > > > https://github.com/openjdk/jdk/blob/f4af0eadb6eaf9d9614431110ab7fc9c1588966d/src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java#L424 > > is not exactly trivial. I enjoyed reading the comments even if I > > have not clue what the the code is doing. > [...] > > Microsoft's STL implementation (to_chars) looks about as hairy: > https://github.com/microsoft/STL/blob/264b0d4a167daa9e5499af6d783c9ff22f7af03f/stl/inc/charconv Note that different implementations can have different behavior in some cases. I believe the C++ spec unambiguously defines string representation for every number but Java may not be following that spec (it has no reason to). I recall lengthy discussions when to_chars was being standardized. I don't remember the details but I think there was more than one reasonable specification and judgement call had to be made. I pointed to to_chars from the C++ standard not because it's the best but because it's precise and recent enough to take into account experience from other languages. It's always nice when you can piggyback on a standard. Roman.