立方根行为 R

Cubic Root Behaviour R

在 R 中,为什么

(-27)^(1/3)

return NaN

(27)^(1/3)

returns 3?

据我了解,(-27)^(1/3)有三种解法-3, 1.5+2.5971i, 1.5-2.5971i(27)^(1/3)有三种解法3, -1.5+2.5971i, -1.5-2.5971i。那么,为什么 return 没有 -27 的解而只有 27 的实数?

help('^')

Users are sometimes surprised by the value returned, for example why (-8)^(1/3) is NaN. For double inputs, R makes use of IEC 60559 arithmetic on all platforms, together with the C system function pow for the ^ operator. The relevant standards define the result in many corner cases. In particular, the result in the example above is mandated by the C99 standard. On many Unix-alike systems the command man pow gives details of the values in a large number of corner cases.