Skip to content
Prev 200388 / 398506 Next

Odp: ^ operator

Hi

r-help-bounces at r-project.org napsal dne 16.11.2009 13:27:03:
And that is a right answer
No. With all constructions like above you compute a cube root of 
***positive*** number and then you put *-* sign before the result, hence 
the same result.

Try instead to make a cube root of negative number.

 (-6.108576e-05)^(1/3)
[1] NaN

This is what you exactly do by the first call. Beware also that 1/3 is not 
exactly representable in binary arithmetic and so you actually do not 
compute cube root but some root which is quite near to cube root.
[1] -1.776357e-15

If you want cube root and have negative numbers you need probably 
something like

sign(tmp) * abs(tmp)^(1/3)
You need to use parentheses on correct places. To see what is the 
precedence of operators see

?Syntax 

Regards
Petr
http://www.R-project.org/posting-guide.html