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

Re: arithmetic operator precedence



On 2008-06-17 10:45:09 +0100, Stephane Chazelas wrote:
> But ** is not ^, it's a binary operator whose shape reminds that
> of multiply, like a multiply++.

So, why is ** right-associative while * is left-associative?

> And even then, POSIX's ^ in bc is handled as -3^2 = 9.

But note that bc is the only calculator with such an unfortunate
choice. And I doubt that bc has been designed by end users. Also,
perhaps those who wrote bc in the first place didn't think about
this problem and just wanted to privilege the precedence of
unary operators as it is often the case.

> It could be a good idea to ask ksh, POSIX/bc and perl authors for
> the rationale behind their choices.

I think that Perl authors would say something like conventional math
writing (that's what some of authors of calculators say and what users
often demand).

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