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

Re: arithmetic operator precedence



On Tue, Jun 17, 2008 at 11:19:40AM +0200, Richard Hartmann wrote:
[...]
> > That's an interesting point for C_PRECEDENCES since I was trying to get
> > it behave as much as possible like Perl.  What does anyone else think?
> 
> Being unsure myself, I did some somewhat extensive research. The only
> mathematically correct way of doing this is
> 
>   -3**2   = -9
>   (-3)**2 =  9
[...]

In which way is it more "mathematically" correct?

Is that because -3² is -9? 

But ** is not ^, it's a binary operator whose shape reminds that
of multiply, like a multiply++. And even then, POSIX's ^ in bc
is handled as -3^2 = 9.

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

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author