From: Gabor Grothendieck <ggrothendieck_at_gmail.com>

Date: Fri 06 Jan 2006 - 16:09:10 GMT

R-devel@r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Jan 07 03:13:33 2006

Date: Fri 06 Jan 2006 - 16:09:10 GMT

Precedence rules are tricky, in general, and the usual advice with most programming languages is to liberally use parentheses when in doubt. Its actually not that surprising in this case but consider 0-1:3 and -1:3 which give different results since one uses binary minus and the other uses unary minus and the order of precedence from highest to lowest is unary minus, : and binary minus. If one used parentheses in these cases it would be clear even without detailed knowledge of the precedence rules (which likely no one can remember anyways).

On 1/6/06, roger bos <roger.bos@gmail.com> wrote:

> How do people even notice stuff like this. You would never hard-coding

*> (-2)^2 or -2^2 anyway. The part being squared would be a variable, in which
**> case it works correctly:
**>
**> > a<- -2
**> > a
**> [1] -2
**> > a^2
**> [1] 4
**>
**> Sometimes it seems that people go looking for bugs... and therefore see bugs
**> all around them.
**>
**> On 1/6/06, ggrothendieck@gmail.com <ggrothendieck@gmail.com> wrote:
**> >
**> > On 1/6/06, Thomas Lumley <tlumley@u.washington.edu> wrote:
**> > > 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.
**> >
**> > See ?Syntax
**> >
**> > ______________________________________________
**> > R-devel@r-project.org mailing list
**> > https://stat.ethz.ch/mailman/listinfo/r-devel
**> >
**>
**> [[alternative HTML version deleted]]
**>
**> ______________________________________________
**> R-devel@r-project.org mailing list
**> https://stat.ethz.ch/mailman/listinfo/r-devel
**>
*

R-devel@r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Jan 07 03:13:33 2006

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