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

Re: arithmetic operator precedence



Speaking of precedence, the following one is nasty:

vin% zsh -c 'echo $((-3**2))'
9
vin% bash -c 'echo $((-3**2))'
9
vin% ksh93 -c 'echo $((-3**2))'
9

IMHO these shells should be fixed to give -9, i.e. ** should have
the precedence over the unary -, like conventional math writing.
Nowadays most modern software does it right, the main exception
being MS Excel and other spreadsheet software that mimics its
behavior (current versions of OpenOffice and Gnumeric, despite
the users' complaints).

See http://www.macnauchtan.com/pub/precedence.html for the behavior
of various software on that. This page is incomplete. One can add:
Qalculate/qalc, calc, wcalc, GP/PARI and MuPAD as doing it right,
ditto for the future version of Abakus (that will be released for
KDE 4).

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