# pow returning -1.#IND

This topic is 4325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Here's the relevant code:
const float t0 = c2 + sqrt(c3);
const float t1 = 1.0f/3.0f;
const float c4 = pow(t0, t1);


I print these later in the function and the output is: t0 = -12.1406 t1 = 0.333333 c4 = -1.#IND What's going on here? I'm using Visual C++ 2005 Express.

##### Share on other sites
Negative numbers can't be raised to a non-integral power, if you expect to get a real number as a result. I forget what happens if you remove the real number limitation, though. Imaginary numbers might be sufficient.

Think about it. What is (-1)1? (-1)2? (-1)3. If the exponent is odd, then it is -1, and if even, it is +1. But what if it's neither? What result is neither positive nor negative (nor zero)?

##### Share on other sites
Hmm, my calculator gives me a real number: (-12.1406)^(1/3) = -2.2983

Edit: but I get your point.. I don't know where it get the sign from

##### Share on other sites
That won't work for arbitrary non-integral powers, though. In this case, it happens to be equivelant to the cube root of -12.1406 which is a negative real number.

I'll hazard a guess that the floating point inaccuracy in 1.0f/3.0f is sufficient to mean that this is no longer the case and that the answer is a complex number.

EDIT: As in, you're really doing (-12.1406)^(0.99999998/3.000000001) or something like that (which, to continue the example, Google informs us is (1.14916766 + 1.99041668i) where i is the imaginary unit sqrt(-1)).

##### Share on other sites
Quote:
 Original post by TheUnbelieverI'll hazard a guess that the floating point inaccuracy in 1.0f/3.0f is sufficient to mean that this is no longer the case and that the answer is a complex number.

Even if floating point accuracy was good enough, it still wouldn't work. pow in C++ can't raise a negative number to a non-integral power because a very large range of these result in complex numbers. For instance if we can trust the data in your original post (debuggers sometimes round-off), then you tried to do:
(-12.1406)^(0.333333) = (-12.1406)^(333333/10^6) = the 10^6-th root of (-12.1406)^(333333)
That is an even root of a negative number, which results in a complex number since no real number when multiplied by itself an even amount of times gets negative (negative * negative = positive, positive*positive=positive). Your calculator may work with rational numbers or it may just force the power function to return a real number.

##### Share on other sites
Thank you guys, I've just pillaged a cube root function from somewhere for now.

##### Share on other sites
Quote:
 Original post by CTarpow in C++ can't raise a negative number to a non-integral power because a very large range of these result in complex numbers.

D'oh... Trying to be too smart for my own good.

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013652
×