From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17321 invoked from network); 19 Jun 2008 16:27:37 -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; 19 Jun 2008 16:27:37 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 19553 invoked from network); 19 Jun 2008 16:27:32 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 19 Jun 2008 16:27:32 -0000 Received: (qmail 10768 invoked by alias); 19 Jun 2008 16:27:30 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25220 Received: (qmail 10755 invoked from network); 19 Jun 2008 16:27:29 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 19 Jun 2008 16:27:29 -0000 Received: from mail.o2.co.uk (jabba.london.02.net [82.132.130.169]) by bifrost.dotsrc.org (Postfix) with ESMTP id 5961D8084FA1 for ; Thu, 19 Jun 2008 18:27:23 +0200 (CEST) Received: from sc.homeunix.net (78.105.216.138) by mail.o2.co.uk (8.0.013.3) (authenticated as stephane.chazelas) id 4851DD950135C94A; Thu, 19 Jun 2008 17:27:19 +0100 Received: from chazelas by sc.homeunix.net with local (Exim 4.69) (envelope-from ) id 1K9Myk-0006oN-Ne; Thu, 19 Jun 2008 17:27:18 +0100 Date: Thu, 19 Jun 2008 17:27:18 +0100 From: Stephane Chazelas To: Mikael Magnusson Cc: zsh-workers@sunsite.dk Subject: Re: arithmetic operator precedence Message-ID: <20080619162718.GG5016@sc.homeunix.net> Mail-Followup-To: Mikael Magnusson , zsh-workers@sunsite.dk References: <2d460de70806170324o5a44609x9383cc2445d67dd6@mail.gmail.com> <20080617103829.GD5016@sc.homeunix.net> <20080617114340.398c731f@news01> <20080617112815.GF10734@prunille.vinc17.org> <200806171146.m5HBkhfR013230@news01.csr.com> <200806190958.m5J9w7BJ006695@news01.csr.com> <2d460de70806190529p1255b8b5mfe2fb2c1e1d7ba35@mail.gmail.com> <20080619160433.GL10734@prunille.vinc17.org> <237967ef0806190910q70c0d0d7y2466938b547a8ee4@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <237967ef0806190910q70c0d0d7y2466938b547a8ee4@mail.gmail.com> User-Agent: Mutt/1.5.16 (2007-09-19) X-Virus-Scanned: ClamAV 0.92.1/7506/Thu Jun 19 16:51:14 2008 on bifrost X-Virus-Status: Clean On Thu, Jun 19, 2008 at 06:10:56PM +0200, Mikael Magnusson wrote: > 2008/6/19 Vincent Lefevre : > > On 2008-06-19 14:29:03 +0200, Richard Hartmann wrote: > >> On Thu, Jun 19, 2008 at 11:58, Peter Stephenson wrote: > >> > That seems a good idea in any case. > >> > >> Can you add that this is done to remain both backwards and shell- > >> compatible and that this is not what a 'real' language/calculator > >> will do? > > > > This isn't shell-compatible. AFAIK, only bash and ksh93 support **. > > > >> Perhaps even include a reference to the POSIX argument. > > > > There's no POSIX argument. ** is just an extension. > > I've followed this discussion, and I'm left wondering only one thing. > If it's decided that $(( -1 ** 2 )) == 1, then what's the point? Why > would anyone ever write that? Why require everyone to write -(1**2) when > the expression makes no sense at all without the parentheses? Ie you would > just write 1**2 without the - at all, nobody would ever write (-1)**2. [...] Think of: double() { REPLY=$(($1 * 2)) } square() { REPLY=$(($1 ** 2)) } Where those functions are meant to be passed a number, positive or negative, not any random arithmetic expression. If you make ** have higher precedence than unary "-", then square -1 returns -1 while double -1 returns -2 as expected. -- Stéphane