G'day Bill,

On Wed, 27 Oct 2010 10:34:27 +1100
<bill.venab...@csiro.au> wrote:

[...]
> It is no surprise that this does not work when working in the real
> domain, except "by fluke" with something like 
> 
> > -4^(1/3)
> [1] -1.587401
> > 
> 
> where the precedence of the operators is not what you might expect.
> Now that could be considered a bug, since apparently
> 
> > -4^(1/2)
> [1] -2
> 
> which comes as rather a surprise!
[...]

Mate, you must have been using Excel (or bc) too much recently if this
takes you by surprise. :)

This is exactly the behaviour that I would expect as I was always
taught that exponentiation was the operator with the highest priority.  

The discussion at
    http://en.wikipedia.org/wiki/Order_of_operations
points out that "there exist differing conventions concerning the unary
operator -" but gives only Excel and bc as examples of
programs/languages who give the unary operator the higher precedence.
Moreover,
        http://www.burns-stat.com/pages/Tutor/spreadsheet_addiction.html
points out that in Excel "the precedence of unary minus is different
than many other languages (including VBA which is often used with
Excel)".

Cheers,

        Berwin

______________________________________________
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