Message-ID: <68b1e2610911160513j30c2e36w8f51264dae526337@mail.gmail.com>
Date: 2009-11-16T13:13:27Z
From: Liviu Andronic
Subject: Odp: ^ operator
In-Reply-To: <XFMail.091116125530.Ted.Harding@manchester.ac.uk>
On 11/16/09, Ted Harding <Ted.Harding at manchester.ac.uk> wrote:
> Not in this case (see below), though of course in general "-" takes
> precedence over "^", so, for example, in the expression
>
> -2^(1/3)
>
> the "-" is applied first, giving (-2); and then "^" is applied
> next, giving (-2)^(1/3). There is a work-round (see below).
>
Hmm.. I may be doing something wrong, but from here it looks to be the
opposite.
> -2^(1/3); -(2)^(1/3); -(2^(1/3));
[1] -1.2599
[1] -1.2599
[1] -1.2599
> (-2)^(1/3)
[1] NaN
The results don't change when switching from the unary minus.
> 0-2^(1/3); 0-(2)^(1/3); 0-(2^(1/3));
[1] -1.2599
[1] -1.2599
[1] -1.2599
It seems to me that in this example "^" is applied first, and "-"
second. There is also this fortune entry.
> fortune("unary")
Thomas Lumley: The precedence of ^ is higher than that of unary minus.
It may be surprising,
[...]
Herv? Pag?s: No, it's not surprising. At least to me... In the country
where I grew up, I've
been teached that -x^2 means -(x^2) not (-x)^2.
-- Thomas Lumley and Herv? Pag?s (both explaining that operator
precedence is working
perfectly well)
R-devel (January 2006)
Liviu