[R] Problems raised to 1/3 power and NaN

Thomas Lumley tlumley at u.washington.edu
Wed Apr 28 01:47:17 CEST 2004

On Tue, 27 Apr 2004, Bock, Michael wrote:
> I though you could take the cubed root of negative numbers (basic
> algebra) but perhaps this does not hold true for computer math due to
> rounding of the exponents.

Yes. All the representable floating point numbers are fractions whose
denominator is a power of two, and so none of them give exactly
real-valued roots of negative numbers.

You could use complex numbers, but then you have the problem of getting
the correct cube root.

> (-1+0i)^(1/3)
[1] 0.5+0.8660254i


More information about the R-help mailing list