Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: arithmetic operator precedence
- X-seq: zsh-workers 25148
- From: "Mikael Magnusson" <mikachu@xxxxxxxxx>
- To: "Zsh hackers list" <zsh-workers@xxxxxxxxxx>
- Subject: Re: arithmetic operator precedence
- Date: Thu, 12 Jun 2008 15:12:34 +0200
- 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=
- In-reply-to: <20080612095723.GF5113@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20080612095723.GF5113@xxxxxxxxxxxxxxx>
2008/6/12 Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>:
> $ 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author