It's order of operations, and a good reason to always use parentheses: which is evaluated first, the unary minus or the raising-to-powers?
(-4)^0.5 -(4^0.5) sqrt(-4) -sqrt(4) Sarah On Wed, Mar 21, 2012 at 7:09 PM, Mike Williamson <this.is....@gmail.com> wrote: > Hi Everyone, > > I did a search through the archives and did not find an answer, > although I must admit it is a hard search to do ( ^0.5 is tough to > explicitly search for ). > > I am sure there is some mathematically accurate reason to explain the > following, but I guess I either never learned it or have since forgotten it. > > In 'R', when I type (for instance): > > sqrt(-4) > > I get > > NaN > > but if I type in: > > -4 ^ 0.5 > > I get > > -2 > > I presume this is on purpose and correct, but it's the first time I've > come across any theoretical difference between ^0.5 and sqrt. What is the > theoretical difference / meaning between these two operations? > > Thanks! > Mike > -- Sarah Goslee http://www.functionaldiversity.org ______________________________________________ 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.