From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27187 invoked from network); 12 Jun 2008 13:12:51 -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; 12 Jun 2008 13:12:51 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 10877 invoked from network); 12 Jun 2008 13:12:45 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 Jun 2008 13:12:45 -0000 Received: (qmail 27412 invoked by alias); 12 Jun 2008 13:12:43 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25148 Received: (qmail 27397 invoked from network); 12 Jun 2008 13:12:42 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 12 Jun 2008 13:12:42 -0000 Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.235]) by bifrost.dotsrc.org (Postfix) with ESMTP id 432F68028AC3 for ; Thu, 12 Jun 2008 15:12:35 +0200 (CEST) Received: by rv-out-0506.google.com with SMTP id g37so3599073rvb.21 for ; Thu, 12 Jun 2008 06:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=f086N+xzqNaS7PVor5f3OaqPm26kVeVGinFpasKwsaI=; b=G8ItBAohQagqQREX3hmysAVKBFFE1qUlxE/5n+PplyiEcvvdtOR4dTq5XRNatW68/B X0oYTt4obhVnl4JcbnJrWc92Csoz77s2GMAtCS23ZyoO7niLaluFo6BnJsnc2pBAiHy/ /PrCyX0J+kupqWM98eO7evWUnQl3Pr8btYbXA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=kxgNixCd2U5bmfZIvTgCfloLAi8dyzXdKGLOOex6aRh/l4ZX0OmxWMaRvYz8hembGE xnA27Vii4nVvObjD8z1dv+yBBRJ5IaygTVyqQ3Wxpkjru4BigoAvJblGLrXWoGq7mTyc rflzwX+hO1GR8dkhHpFeoynDq4RwYLAylTQP0= Received: by 10.141.197.21 with SMTP id z21mr771005rvp.233.1213276354628; Thu, 12 Jun 2008 06:12:34 -0700 (PDT) Received: by 10.141.153.6 with HTTP; Thu, 12 Jun 2008 06:12:34 -0700 (PDT) Message-ID: <237967ef0806120612k222d0ddel87058765bcf31e0c@mail.gmail.com> Date: Thu, 12 Jun 2008 15:12:34 +0200 From: "Mikael Magnusson" To: "Zsh hackers list" Subject: Re: arithmetic operator precedence In-Reply-To: <20080612095723.GF5113@sc.homeunix.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080612095723.GF5113@sc.homeunix.net> X-Virus-Scanned: ClamAV 0.92.1/7448/Thu Jun 12 13:23:26 2008 on bifrost X-Virus-Status: Clean 2008/6/12 Stephane Chazelas : > $ zsh -c 'echo $(( 1 & 2 == 2 ))' > 0 > > "==" is meant to have precedence over &, so the above should > give 1 as in C I think. All other shells do. >>From the manual: An arithmetic expression uses nearly the same syntax, precedence, and associativ- ity of expressions in C. The following operators are supported (listed in decreasing order of precedence): + - ! ~ ++ -- unary plus/minus, logical NOT, complement, {pre,post}{in,de}crement << >> bitwise shift left, right & bitwise AND ^ bitwise XOR | bitwise OR ** exponentiation * / % multiplication, division, modulus (remainder) + - addition, subtraction < > <= >= comparison == != equality and inequality && logical AND || ^^ logical OR, XOR ? : ternary operator = += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^= **= assignment , comma operator The operators `&&', `||', `&&=', and `||=' are short-circuiting, and only one of the latter two expressions in a ternary operator is evaluated. Note the prece- dence of the bitwise AND, OR, and XOR operators. -- Mikael Magnusson