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

Re: arithmetic operator precedence



On Tue, Jun 17, 2008 at 12:38, Stephane Chazelas
<Stephane_Chazelas@xxxxxxxx> wrote:


> Not sure what you mean. ^ in bc is the power operator and
> there's no ** there. In shells, ** is the power operator and ^
> is the XOR operator.

I did not refer to the XOR interpretation of ^, of course.
What I thought you said is that ^ and ** as in

  3^2  = 9
  3**2 = 9

are not the same. Did not make sense to me, but did not want
to discard the idea entirely without checking.


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

I can see what you mean, but the operator, not its representation,
must be must stay the same. Do I understand you correctly that
you think this is the way to go:

  -3^2  = -9
  -3**2 =  9

If yes, that looks _really_ harmful to me.


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

See above for my question, requesting clarification.


Richard


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