Re: [Rd] Multiplication (PR#8466)

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Fri 06 Jan 2006 - 16:26:19 GMT

Thomas Lumley <tlumley@u.washington.edu> writes:

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

Pretty much standard too, for languages that have an exponentiation operator. AFAICS Fortran, Perl, SAS all have ** at higher precedence than unary minus (or equal, but evaluate right to left). Stata seems like it might be the exception.

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sat Jan 07 03:33:09 2006

This archive was generated by hypermail 2.1.8 : Fri 06 Jan 2006 - 20:04:17 GMT