Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: arithmetic operator precedence
- X-seq: zsh-workers 25179
- From: Vincent Lefevre <vincent@xxxxxxxxxx>
- To: "Zsh hackers list" <zsh-workers@xxxxxxxxxx>
- Subject: Re: arithmetic operator precedence
- Date: Tue, 17 Jun 2008 12:54:54 +0200
- In-reply-to: <2d460de70806170219k12ff4cadn441b52c48bf8076f@xxxxxxxxxxxxxx>
- Mail-followup-to: "Zsh hackers list" <zsh-workers@xxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20080612095723.GF5113@xxxxxxxxxxxxxxx> <20080616080726.GP10734@xxxxxxxxxxxxxxxxxxx> <20080616144211.276fb0e3@pws-pc> <2d460de70806170219k12ff4cadn441b52c48bf8076f@xxxxxxxxxxxxxx>
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