From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6141 invoked from network); 17 Jun 2008 10:55:04 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 Jun 2008 10:55:04 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 54877 invoked from network); 17 Jun 2008 10:55:01 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Jun 2008 10:55:01 -0000 Received: (qmail 23441 invoked by alias); 17 Jun 2008 10:54:58 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25179 Received: (qmail 23432 invoked from network); 17 Jun 2008 10:54:58 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 17 Jun 2008 10:54:58 -0000 Received: from prunille.vinc17.org (vinc17.pck.nerim.net [213.41.242.187]) by bifrost.dotsrc.org (Postfix) with ESMTP id 200798028AC3 for ; Tue, 17 Jun 2008 12:54:54 +0200 (CEST) Received: by prunille.vinc17.org (Postfix, from userid 501) id 4983C234FE85; Tue, 17 Jun 2008 12:54:54 +0200 (CEST) Date: Tue, 17 Jun 2008 12:54:54 +0200 From: Vincent Lefevre To: "Zsh hackers list" Subject: Re: arithmetic operator precedence Message-ID: <20080617105454.GD10734@prunille.vinc17.org> Mail-Followup-To: "Zsh hackers list" References: <20080612095723.GF5113@sc.homeunix.net> <20080616080726.GP10734@prunille.vinc17.org> <20080616144211.276fb0e3@pws-pc> <2d460de70806170219k12ff4cadn441b52c48bf8076f@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2d460de70806170219k12ff4cadn441b52c48bf8076f@mail.gmail.com> X-Mailer-Info: http://www.vinc17.org/mutt/ User-Agent: Mutt/1.5.18-vl-r22984 (2008-06-11) X-Virus-Scanned: ClamAV 0.92.1/7494/Tue Jun 17 06:46:03 2008 on bifrost X-Virus-Status: Clean On 2008-06-17 11:19:40 +0200, Richard Hartmann wrote: > Being unsure myself, I did some somewhat extensive research. The only > mathematically correct way of doing this is > > -3**2 = -9 > (-3)**2 = 9 > > On the other hand, compability with the other shells is A Good Thing, > especially as this is the kind of syntax change that can break a script > in a very, very evil and hard-to-debug way. ** is a non-portable feature. Portable scripts should not be based on it. And it is an even more idea to base a script on the precedence of the unary - over **, since this rule doesn't follow conventional math writing. For interoperability with other software, it is advised to put parentheses in both cases anyway. Such writings without explicit parentheses are useful mainly for the end user, in particular when typing expressions interactively, and conventional math writing is important here. > Still, all things considered, I would say the only possible way to > go is to use the mathematically correct syntax. Both options are > bad, in a way, but this is the better one. Yes. There would also be the option to force parentheses. For instance, this is the case with Maple and the associativity of ^: the user cannot write 2^3^2 (Maple returns an error), he must use parentheses: 2^(3^2) or (2^3)^2. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)