From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2899 invoked from network); 7 Apr 2022 15:04:17 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Apr 2022 15:04:17 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1649343857; b=N2TIeg6tKjqU/fPxpYZ964fuuESvKInWRIvIgNdWDyiu8IzPQKmpSooyfPIMs40RuhUJuk/A8l reCHTzis16FtiFNyo540yeORMPCDYEQLx0GSXs6j5HM4HWoJR3bDfK5QoJ0DeEyMoLNXvfUqdy Y1MPzplN/BotzMbFfyDJifsLQNGMUZXKX13oLwGO0Ks9D7XEMcOaOUZfkaE+CBttmz4QNN3l4m Lpb9atwReZHJ6LooSHh75mi9DN+6v7sKT0M5MJz6+1PxmNa3L3L8XzY7l1nrjODUsYJCy9pJMq z7x5b8TTTmLLfpTJTKEGkZkNtm2K/N/y1fCW5mHjEru+2A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (joooj.vinc17.net) smtp.remote-ip=155.133.131.76; dmarc=none header.from=vinc17.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1649343857; bh=KhMyi3Rwp5++x6iW2Ms+uzYSn5ap81SK4cCTKs93uQM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:To:From:Date:DKIM-Signature; b=N10D2KvBiZEQo9dSiEClrg/kD6AzuGLt14M5O2+4XSiQ/sZP1AOr2Ua66Jl70yggXCfEdnoQDl dd/Tjbnk9R1F7tzu9Q+f0gErbzD9suIlwey378o2Z5jiA9oLqF9kqPfQc1+tPLXp5n0g0XVuBE +JYfCaGU4JnUKF3H665nzCe4l4X1vSU+SBux64kkm+9ZUoQKg++nfUjoZ4jjtzO3ooz+iW6aid zDC9Pbk0Cnz+PX/is/1sPDgoWWoe0ONYoHnpeIVQ7U+Ayf/lw/g5uMFtODXDefOC0o1CsTeUoj EDbpE6/pyozy7+PSx95q+vhypshHn/sWXME+uGSKGc0Egg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=f04Vjq3C018QDawQHDCXsEFeozBcYabd8bUvXbf44zA=; b=p3ba3H01aMgZTnuDp4/cLI+0M7 EaS8yfoHtvoVN1HjDBqJ/3hGZWKFTMOj8/BfHFbfUN6Y6s11rcB1eMGVoLd54j9Fd9Vepz3Vtq6vG +8r6+mTHmo3Ff6Avz5zo2f8LFuYEOgHXGXKlnWQrWF/j9A4a20Ah6+qfnxUAwvJsB99Rz5H/8dJD/ nf/V878r+APdz6Y2bPps/3FQf2RSE7PKnTF41DVd/7isau2vqiE/BvdT5O1rCGnY/HUOzpXuIgu7W HTzbHaND3ISJZLexxeF2m707J3uiaMeMnRHWMlOqlLbuYgKqEb6iSWUpQTPLGg9mkMA5FuOZ34YfY lu0x7yEg==; Received: from authenticated user by zero.zsh.org with local id 1ncTgG-000NTN-VA; Thu, 07 Apr 2022 15:04:16 +0000 Authentication-Results: zsh.org; iprev=pass (joooj.vinc17.net) smtp.remote-ip=155.133.131.76; dmarc=none header.from=vinc17.net; arc=none Received: from joooj.vinc17.net ([155.133.131.76]:54996) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1ncTfm-000N2s-DT; Thu, 07 Apr 2022 15:03:46 +0000 Received: from smtp-zira.vinc17.net (128.119.75.86.rev.sfr.net [86.75.119.128]) by joooj.vinc17.net (Postfix) with ESMTPSA id 8FB92183; Thu, 7 Apr 2022 17:03:45 +0200 (CEST) Received: by zira.vinc17.org (Postfix, from userid 1000) id C6E4228001DB; Thu, 7 Apr 2022 17:03:44 +0200 (CEST) Date: Thu, 7 Apr 2022 17:03:44 +0200 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: floating-point precision and zsh vs ksh93 and coreutils Message-ID: <20220407150344.GA1179089@zira.vinc17.org> Mail-Followup-To: zsh-workers@zsh.org References: <20220323163646.GB1190496@cventin.lip.ens-lyon.fr> <20220327082652.fg6uef5munymssm6@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220327082652.fg6uef5munymssm6@chazelas.org> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.2.2+9 (f082dd14) vl-138565 (2022-03-25) X-Seq: 50014 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On 2022-03-27 09:26:52 +0100, Stephane Chazelas wrote: > 2022-03-23 17:36:46 +0100, Vincent Lefevre: > [...] > > Shouldn't zsh switch to long double? > [...] > > I'm not convinced it's a good idea. I had made a long write-up > related to that some time ago at > https://unix.stackexchange.com/questions/422122/why-does-0-1-expand-to-0-10000000000000001-in-zsh > that we did discussed it here about the artefacts whereby echo > $((0.1)) outputs 0.10000000000000001 for instance. > > Several problems: > - double is still the most commonly used float representation > used by default in other languages (perl, python, most if not > all awks...) > - long double precision varies with the system/compiler/CPU > (64bit, 80bit, 128bit), whilst double is more consistently > 64bit on Unix systems at least. > - so to preserve the precision upon round-trip to/from decimal, > we'd need 17, 21 or 36 digit precision making for even uglier > artefacts (and very long numbers), and if we give up on > preserving precision, we get the same problems as affect > yash/ksh93 described at that link above. > > $ ksh -c 'if (( $((1. / 3)) == 1./3 )); then echo yes; else echo no; fi' > no > $ ksh -c 'echo $(( $((1. / 3)) - 1./3 ))' > -3.52365706057788941e-19 OK, I forgot that ksh was actually buggy. I thought that it output the minimum number of digits that preserves the round trip back to binary. Now, given that ksh doesn't even use a "long double compatible" format for its output, I don't see any reason why coreutils uses long double by default (IMHO, it should use a length modifier for that, as in C). -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)