Andrej
Andrej

Reputation: 3839

Exponentiation with negative base

So, the R expression and its output is as follows:

> (4-7)^1.3
[1] NaN

Any ideas how to solve this in R?

Upvotes: 6

Views: 1314

Answers (2)

Paul Hiemstra
Paul Hiemstra

Reputation: 60924

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.

Upvotes: 6

Spacedman
Spacedman

Reputation: 94182

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...

Upvotes: 10

Related Questions