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

Re: arithmetic operator precedence



On 2008-06-17 11:38:29 +0100, Stephane Chazelas wrote:
> What I meant is that ^ reminds of the /human/ (as opposed to
> /computer/) representation as it indicates that follows must be
> raised up as in 3². So, one can understand that it should follow
> the same rules (that is -3^2 should be the same as -3², even
> though that's not what POSIX decided for bc). But given that **
> has more the shape of the * operator, I'm not sure we can tell
> the same thing.

Note that in math, -(a * b) and (-a) * b are equivalent (even in
the general case of a ring), and I'd say that most people regard
- a * b more like -(a * b) than (-a) * b. So, you can't really
compare to * without confusion.

Also ** is merely a replacement for the more conventional (and
shorter) ^ when ^ can't be used (e.g. because it already has
another meaning).

Math writing asside, the fact that -3**2 and 0-3**2 return different
results is quite confusing too.

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