Re: [R] [Rd] Multiplication

From: Barry Rowlingson <>
Date: Sat 07 Jan 2006 - 02:26:10 EST

[crossed over to r-help since its not a bug and not a devel thing any more]

Thomas Lumley wrote:

> So is -2^2. The precedence of ^ is higher than that of unary minus. It
> may be surprising, but it *is* documented and has been in S for a long
> time.

And just about every other programming language:


 >> -2^2

ans =



(C1) -2^2;
(D1) - 4


       print *,-2**2


$ perl -e 'print -2^2'

  Oops. I mean:

$ perl -e 'print -2**2'

  The precendence of operators is remarkably consistent over programming languages over time. It seems natural for me now that ^ is done before unary minus, but I don't know if that's because I've been doing that for 25 years or because its really more natural.

  Anyone got a counter example where unary minus is higher than power?

Barry mailing list PLEASE do read the posting guide! Received on Sat Jan 07 03:35:16 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:54 EST