Skip to content
Prev 200561 / 398503 Next

Calculating the power of a negative number

Zhiyuan Jason ZHENG wrote:
Well,

mycuberoot <- function(x) sign(x)*abs(x)^(1/3)

but in general there is just no solution. The problem is that for the
solution to be even defined, the power needs to be a fraction with an
odd denominator. With floating point arithmetic and roundoff and what
not, there is just no way to know whether that is the case or not. In
fact, the machine representation of ANY number with a fractional part
will be a fraction with an EVEN denominator (2^{p} for some p).