1. ## Roots??

Yeah, I'm a pest.

Why do I get such bizarre results with

Code:
`std::cout<<pow(16, -2);`
??

If I want the 12th root of 2 for musical applications (I already know it but that's beside the point) how do I calculate it in C++??

Thanks again, I'll stop now, I'm over my quota of questions for the day!

2. Bizarre results?

16^-2 = 1/(16*16) = 1/256

Comes out to about .0039, which is what I get with that code (after resolving the ambiguity error)

And for the 12th root, I think this works:
Code:
```#include <iostream>
#include <cmath>
using namespace std;

int main()
{
float result = pow(2,1.0f/12);
cout<<"12th root of 2: "<<result<<endl;
cout<<pow(result,12);
}```

3. Yeah, that does work, thanks -

I don't get this, though:

Code:
`float result = pow(2,1.0f/12);`
What's with 1.0f/12? I thought that raising to the power of a negative number would yield the root. I thought wrong.

Where could I find out more about using pow() correctly?

4. power (type a, type b);

a is the base number
b is the power

1.0f = 1.0(float)

5. So if you want the 12th root, its just plain math from here.

x^(1/12) = 12root(x^1)

---->

12root(x)

= 12th root of x

6. Originally Posted by -JM
Yeah, that does work, thanks -

I don't get this, though:

Code:
`float result = pow(2,1.0f/12);`
What's with 1.0f/12? I thought that raising to the power of a negative number would yield the root. I thought wrong.

Where could I find out more about using pow() correctly?
Rasing a number to x to a power -y is equivalent to (1/x)^y which is not the yth root.

The yth root of x is defined to be x^(1/y).

You can see why if you consider for example the square of the square root of a number (which is the number again). If the root was a negative power you would get: (x^-2)^2 = x^(-2*2) = x^-4 != x (chaining powers is equivalent to multypling the exponents).
Since the root is a fractional power though you get: (x^1/2)^2 = x^(1/2*2) = x

If you want more information about powers and roots any high school level math textbook should have everything you need. From the looks of it pow(x,y) just returns x^y.

7. Thanks guys, I get it now!

So, I should have paid attention in high school math?

-JM

8. I didn't