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

Re: arithmetic operator precedence



On 2008-06-12 16:01:26 +0100, Stephane Chazelas wrote:
> I find the zsh precedence more intuitive but that's not of much

ditto

> help given that I get to use those binary operators mostly only
> in C/perl, so I have to know the C precedence anyway.
> 
> And having zsh behaving differently doesn't help at all.

I agree. POSIX even requires C-like behavior:

http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_04

  2.6.4 Arithmetic Expansion

  Arithmetic expansion provides a mechanism for evaluating an
  arithmetic expression and substituting its value. The format for
  arithmetic expansion shall be as follows:

    $((expression))

  The expression shall be treated as if it were in double-quotes,
  except that a double-quote inside the expression is not treated
  specially. The shell shall expand all tokens in the expression for
  parameter expansion, command substitution, and quote removal.

  Next, the shell shall treat this as an arithmetic expression and
  substitute the value of the expression. The arithmetic expression
  shall be processed according to the rules given in Arithmetic
                                                     ^^^^^^^^^^
  Precision and Operations , with the following exceptions:
  ^^^^^^^^^^^^^^^^^^^^^^^^

(the exceptions are not about precedence), where the link to
Arithmetic Precision and Operations is:

http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap01.html#tag_01_07_02_01

which corresponds to the ISO C operators.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)



Messages sorted by: Reverse Date, Date, Thread, Author