From p.dalgaard at biostat.ku.dk  Fri Jan  6 17:26:19 2006
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: 06 Jan 2006 17:26:19 +0100
Subject: [Rd] Multiplication (PR#8466)
In-Reply-To: <Pine.LNX.4.64.0601060712540.7293@homer24.u.washington.edu>
References: <20060106144345.5682219AC0@slim.kubism.ku.dk>
	<Pine.LNX.4.64.0601060712540.7293@homer24.u.washington.edu>
Message-ID: <x27j9dtj9w.fsf@viggo.kubism.ku.dk>

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

> On Fri, 6 Jan 2006, casella at 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 at biostat.ku.dk)                  FAX: (+45) 35327907



[Rd] Multiplication (PR#8466)
Peter Dalgaard