這是因爲C99標準下實施了pow
。
別說OP的例子:(-50.61828)^(-67.421587)
,數學上合理(-8)^(1/3) = -2
沒有R中工作:
(-8)^(1/3)
# [1] NaN
從?"^"
報價:
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.
我在Ubuntu Linux操作系統,所以可以幫助獲得man power
的相關部分印在這裏:
If x is a finite value less than 0, and y is a finite noninteger, a
domain error occurs, and a NaN is returned.
@warmoverflow,你是對的,我抄了錯誤的代碼。我編輯了這個問題。 –
[HelpLink1](http://r.789695.n4.nabble.com/8-1-3-NaN-td895638.html)[HelpLink2](http://stackoverflow.com/questions/19437701/how-to -calculate-any-negative-number-of-the-power-of-some-fraction-in-r)[HelpLink3](http://stackoverflow.com/questions/8166988/exponentiation-with-negative-base)好運氣。 – user5249203