From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 715 invoked by alias); 12 Jan 2015 11:36:26 -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: X-Seq: 34254 Received: (qmail 5037 invoked from network); 12 Jan 2015 11:36:24 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Date: Mon, 12 Jan 2015 12:36:18 +0100 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: Floating point modulus Message-ID: <20150112113617.GA13104@ypig.lip.ens-lyon.fr> Mail-Followup-To: zsh-workers@zsh.org References: <20150109223028.6e003bff@ntlworld.com> <54B066C5.3010008@eastlink.ca> <54B0D893.4080202@eastlink.ca> <510FB8E2-EA0C-4582-BD31-527E9755F0FB@larryv.me> <54B1ACA3.1050001@eastlink.ca> <150110175849.ZM21774@torch.brasslantern.com> <54B20E23.8090900@eastlink.ca> <150110231017.ZM24021@torch.brasslantern.com> <150111113601.ZM29941@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <150111113601.ZM29941@torch.brasslantern.com> X-Mailer-Info: http://www.vinc17.net/mutt/ User-Agent: Mutt/1.5.23-6392-vl-r75100 (2015-01-06) On 2015-01-11 11:36:01 -0800, Bart Schaefer wrote: > On Jan 10, 11:10pm, Bart Schaefer wrote: > } > } The following patch would instead silently substitute the fmod() call > } when using the % operator on a float. > > Incidentally, what's a reliable test for this that could be added to > C01arith.ztst? I worry about rounding error differing by platform: > > torch% print $(( 29.1 % 13.0 )) > 3.1000000000000014 The rounding error is due to the decimal-to-binary conversions, not to the % operation, which, if I'm not mistaken, is necessarily exact in a floating-point system: considering x % y, if |x| < |y|, then the result is x, which is exact; otherwise the result is a multiple of ulp(y) and less than |y| in absolute value, thus exactly representable. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)