[R] sqrt(-x) vs. -x^0.5

Bert Gunter gunter.berton at gene.com
Thu Mar 22 01:46:12 CET 2012


On Wed, Mar 21, 2012 at 5:21 PM, Mike Williamson <this.is.mvw at gmail.com> wrote:
> Thanks Sarah, All,
>
>    I guess I never thought of a negative sign as an "operation", but
> knowing that it is considered an operation explains everything nicely.
>  Somewhere in it's underbelly, I suppose -4 is represented as "0 - 4"?

Sheesh! And why do you suppose that?! Read up on floating point
arithmetic to find out how it is done.

-- Bert

>  Either way, I'm glad it is consistent & accurate, so that I didn't find
> myself in another pickle like "weak" typing and attempts to use time /date
> classes in 'R' have brought me.
>
>                               Thanks!
>                                      Mike
>
>
> ---
> [The theory of gravity] is to me so great an absurdity that I believe no
> Man who has in philosophical matters a competent faculty of thinking can
> ever fall into it.  -- Isaac Newton
>
>
>
> On Wed, Mar 21, 2012 at 4:37 PM, Rolf Turner <rolf.turner at xtra.co.nz> wrote:
>
>> On 22/03/12 12:17, Sarah Goslee wrote:
>>
>>> 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)
>>>
>>
>> If the OP *really* wants the square root of -4 he could do
>> sqrt(-4+0i) or (-4+0i)^0.5 (and get 0+2i in either case).
>>
>>    cheers,
>>
>>        Rolf Turner
>>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list