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

Re: arithmetic operator precedence



On 2008-06-17 11:43:40 +0100, Peter Stephenson wrote:
> On Tue, 17 Jun 2008 11:38:29 +0100
> Stephane Chazelas <Stephane_Chazelas@xxxxxxxx> wrote:
> > Anyway, I was just curious about Peter's statement. I'm most
> > probably not as versed in maths as he is, so was curious about
> > the rationale behind his statement about -3**2 = 9 not being
> > mathematically correct.
> 
> That was Vincent.  I'm inclined to leave the shell the way it is since
> there seems to be no widespread agreement on having C_PRECEDENCES (which
> probably few people will set explicitly) different from other shells (for
> which it will automatically be used in the appropriate emulation).

Well, the C language doesn't have a power operator (there's a power
function, with prefix notation, so no precedence problem with it).

Concerning the precedence of & and |, I'd say that zsh should do what
POSIX requires in sh emulation mode.

Also, when people don't agree about the precedence of operators, a
solution could be to require parentheses (but I don't know if this
is easy to implement such rules). At least ambiguity is avoided.

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