Please post to only one of

r-help@r-project.org
r-h...@stat.math.ethz.ch

not to both, as the same list then got two copies.

On Sat, 3 Jan 2009, rkevinbur...@charter.net wrote:

I had a question about the basic power functions in R.

For example from the R console I enter:

-1 ^ 2
[1] -1

but also

-1^3
[1] -1

-0.1^2
[1]  -0.01

Normally pow(-1, 2) return either -Infinity or NaN. Has R taken over
the math functions? If so I would think that -1^2 is 1 not -1 and -0.1^2 is 0.01 not -0.01.

See ?Syntax, linked from ?`^` :

     The following unary and binary operators are defined.  They are
     listed in precedence groups, from highest to lowest.

       '[ [['             indexing
       ':: :::'           access variables in a name space
       '$ @'              component / slot extraction
       '^'                exponentiation (right to left)
       '- +'              unary minus and plus

so -1^2 is -(1^2) not (-1)^2.

--
Brian D. Ripley,                  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to