#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# problems w/ pow() function

Member Posts: 237
When I use pow(), I'm getting results that aren't close to right. I know pow() requires a floating point number and am using one but am still getting wrong results. The following code works:

double i = 4;
double j;
j = (2,i)

j will have 16.

But if I use a larger number (I'm trying to get 21 to the power of 2) it won't work correctly.

double i = 21;
double j;
j = pow(2,i);

j now holds 2.09715e+06

I'm not clear on why this is happening. Am I using the wrong data type? How do I get the right value out of this ( j = 441 )?

• Member Posts: 1,666
: When I use pow(), I'm getting results that aren't close to right. I know pow() requires a floating point number and am using one but am still getting wrong results. The following code works:
:
: double i = 4;
: double j;
: j = (2,i)
:
: j will have 16.
:
: But if I use a larger number (I'm trying to get 21 to the power of 2) it won't work correctly.
:
: double i = 21;
: double j;
: j = pow(2,i);
:
: j now holds 2.09715e+06
:
: I'm not clear on why this is happening. Am I using the wrong data type? How do I get the right value out of this ( j = 441 )?
:

This should be obvious, pow(x,y) is x^y, it reads in order (why do you think it's y^x?) Anyways, you should easily be able to tell that instead of 21^2 you are getting 2^21 which is 2 million some as it says.

"We can't do nothing and think someone else will make it right."

• Member Posts: 237
Simple enough. Thanks.
: : When I use pow(), I'm getting results that aren't close to right. I know pow() requires a floating point number and am using one but am still getting wrong results. The following code works:
: :
: : double i = 4;
: : double j;
: : j = (2,i)
: :
: : j will have 16.
: :
: : But if I use a larger number (I'm trying to get 21 to the power of 2) it won't work correctly.
: :
: : double i = 21;
: : double j;
: : j = pow(2,i);
: :
: : j now holds 2.09715e+06
: :
: : I'm not clear on why this is happening. Am I using the wrong data type? How do I get the right value out of this ( j = 441 )?
: :
:
: This should be obvious, pow(x,y) is x^y, it reads in order (why do you think it's y^x?) Anyways, you should easily be able to tell that instead of 21^2 you are getting 2^21 which is 2 million some as it says.
:
: "We can't do nothing and think someone else will make it right."