Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: arithmetic operator precedence



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