问题
So, the R expression and its output is as follows:
> (4-7)^1.3
[1] NaN
Any ideas how to solve this in R?
回答1:
The answer is a complex number, so you need to give it a complex argument:
> (4-7+0i)^1.3
[1] -2.451751-3.374545i
but remember this is only one root...
回答2:
I quote from Wikipedia, especially the bold text (http://en.wikipedia.org/wiki/Exponentiation):
The IEEE 754-2008 floating point standard is used in the design of most > floating point libraries. It recommends a number of different functions for computing a power:[19]
- pow treats 00 as 1. This is the oldest defined version. If the power is an exact integer the result is the same as for pown, otherwise the result is as for powr (except for some exceptional cases).
- pown treats 00 as 1. The power must be an exact integer. The value is defined for negative bases, e.g. pown(−3,5) is −243.
- powr treats 00 as NaN (Not-a-Number - undefined). The value is also NaN for cases like powr(−3,2) where the base is less than zero. The value is defined by epower×log(base).
So I think R is showing standard behavior according to international standards.
来源:https://stackoverflow.com/questions/8166988/exponentiation-with-negative-base