From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15364 invoked by alias); 13 Jan 2015 16:18:52 -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: 34268 Received: (qmail 1760 invoked from network); 13 Jan 2015 16:18:50 -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: Tue, 13 Jan 2015 17:18:48 +0100 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: Floating point modulus - the "why not" Message-ID: <20150113161848.GC12079@ypig.lip.ens-lyon.fr> Mail-Followup-To: zsh-workers@zsh.org References: <150112213852.ZM19384@torch.brasslantern.com> <20150113101016.05d6c2a8@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20150113101016.05d6c2a8@pwslap01u.europe.root.pri> X-Mailer-Info: http://www.vinc17.net/mutt/ User-Agent: Mutt/1.5.23-6392-vl-r75100 (2015-01-06) On 2015-01-13 10:10:16 +0000, Peter Stephenson wrote: > On Mon, 12 Jan 2015 21:38:52 -0800 > Bart Schaefer wrote: > > I think we did the right thing, but just as a counter-point: > > > > torch% print $(( 91 % 13 )) > > 0 > > torch% print $(( 9.1 % 1.3 )) > > 1.2999999999999994 > > That's the same problem with floating point division as everywhere else; > if you need to round it, you need to decide what you're rounding to and > add half of that before you truncate downwards. I don't think that's a > fundamentally new effect in this one case. The problem actually comes from the decimal to binary conversions, not with the division (or modulo) itself: 9.1 and 1.3 are not exactly representable. While 91 is a multiple of 13, 9.1 converted to binary is not a multiple of 1.3 converted to binary. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)