Re: [Rd] minus: operator and sign (PR#7908)

2005-05-31 Thread ligges
[EMAIL PROTECTED] wrote:

 Full_Name: Allan Sims
 Version: 2.1.0
 OS: WinXP
 Submission from: (NULL) (193.40.25.254)
 
 
 This should not be correct. It seams that first power is applied and then 
 sign.
 
-2^2
 
 [1] -4
 
 __
 R-devel@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel


So you are telling us in a *bug* report that R works as expected???
The current R Language Definition manual tells us in Section Parser - 
Expressions - Infox and prefix operators (which is 10.4.2 in the 
current version) the details on the order of precendence (^ before 
unary -!).

Please read the docs before submitting bug reports!

Uwe Ligges

__
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] minus: operator and sign (PR#7908)

2005-05-31 Thread Uwe Ligges

Uwe Ligges wrote:


[EMAIL PROTECTED] wrote:


Full_Name: Allan Sims
Version: 2.1.0
OS: WinXP
Submission from: (NULL) (193.40.25.254)


This should not be correct. It seams that first power is applied and 
then sign.



-2^2



[1] -4

__
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel




So you are telling us in a *bug* report that R works as expected???
The current R Language Definition manual tells us in Section Parser - 
Expressions - Infox and prefix operators (which is 10.4.2 in the 
current version) the details on the order of precendence (^ before 
unary -!).


Please read the docs before submitting bug reports!

Uwe Ligges




BTW: ?Syntax should have told you as well.

Uwe Ligges

__
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


RE: [Rd] minus: operator and sign (PR#7908)

2005-05-31 Thread Ted Harding
On 31-May-05 [EMAIL PROTECTED] wrote:
 Full_Name: Allan Sims
 Version: 2.1.0
 OS: WinXP
 Submission from: (NULL) (193.40.25.254)
 
 
 This should not be correct. It seams that first power is applied and
 then sign.
 -2^2
 [1] -4

Rule 1: Know your enemy!

?Syntax --

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

   ...

   '^'exponentiation (right to left)
   '- +'  unary minus and plus

   ...

   '+ -'  (binary) add, subtract

   ...

So ^ takes precedence over unary -, which takes precedence
over binary + and -.

But it is always safe (and often prudent) to force precedence
with parentheses -- at least you yourself are then absolutely
sure of exactly what is going to happen, which is the really
important thing (and this is Rule 2, which takes precedence
over Rule 1).

So if you want to force -2^2 and similar to be the square
of -2 then do (-2)^2. And it adds clarity to things like

  2 - - - 2^2

Best wishes,
Ted.



E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 31-May-05   Time: 11:06:58
-- XFMail --

__
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


RE: [Rd] minus: operator and sign (PR#7908)

2005-05-31 Thread Ted Harding
On 31-May-05 Ted Harding wrote:
 [...]
 But it is always safe (and often prudent) to force precedence
 with parentheses -- at least you yourself are then absolutely
 sure of exactly what is going to happen, which is the really
 important thing (and this is Rule 2, which takes precedence
 over Rule 1).
 
 So if you want to force -2^2 and similar to be the square
 of -2 then do (-2)^2. And it adds clarity to things like
 
   2 - - - 2^2

PS: And will also avoid typopathological events such as

   x-y

when what you really meant was

   x -y
  [1] FALSE

Ted.



E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 31-May-05   Time: 11:50:07
-- XFMail --

__
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel