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

Re: arithmetic operator precedence



On 2008-06-17 11:19:40 +0200, Richard Hartmann wrote:
> Being unsure myself, I did some somewhat extensive research. The only
> mathematically correct way of doing this is
> 
>   -3**2   = -9
>   (-3)**2 =  9
> 
> On the other hand, compability with the other shells is A Good Thing,
> especially as this is the kind of syntax change that can break a script
> in a very, very evil and hard-to-debug way.

** is a non-portable feature. Portable scripts should not be based on
it. And it is an even more idea to base a script on the precedence of
the unary - over **, since this rule doesn't follow conventional math
writing. For interoperability with other software, it is advised to
put parentheses in both cases anyway.

Such writings without explicit parentheses are useful mainly for the
end user, in particular when typing expressions interactively, and
conventional math writing is important here.

> Still, all things considered, I would say the only possible way to
> go is to use the mathematically correct syntax. Both options are
> bad, in a way, but this is the better one.

Yes. There would also be the option to force parentheses. For instance,
this is the case with Maple and the associativity of ^: the user cannot
write 2^3^2 (Maple returns an error), he must use parentheses: 2^(3^2)
or (2^3)^2.

-- 
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