How do people even notice stuff like this.  You would never hard-coding
(-2)^2 or -2^2 anyway. The part being squared would be a variable, in which
case it works correctly:

> a<- -2
> a
[1] -2
> a^2
[1] 4

Sometimes it seems that people go looking for bugs... and therefore see bugs
all around them.

On 1/6/06, ggrothendieck@gmail.com <ggrothendieck@gmail.com> wrote:
>
> On 1/6/06, Thomas Lumley <tlumley@u.washington.edu> wrote:
> > On Fri, 6 Jan 2006, casella@stat.ufl.edu wrote:
> >
> > > hi - in version 2.1 the command
> > >
> > > >-2^2
> > >
> > > gives
> > >
> > > -4
> > >
> > > as the answer.  (-2)^2 is evaluated correctly.
> >
> > 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.
>
> See ?Syntax
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]

