[R] sqrt(-x) vs. -x^0.5
Rolf Turner
rolf.turner at xtra.co.nz
Thu Mar 22 00:37:06 CET 2012
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
More information about the R-help
mailing list