• ### What is your GameDev Story?

Public Group

#### Archived

This topic is now archived and is closed to further replies.

# how do u take a number to the power of

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

## Recommended Posts

equal = (num1^num2); i get zero for the answer when i do this with any number combos why dont it work? what is the correct way to do powers of? thanks, dragon

##### Share on other sites
Try pow(num1, num2). Make sure to include math.h.

##### Share on other sites
oh yeaah, thanks! that is it lol i forgot i remember reading that in a tutorial somewhere any way thanks.

##### Share on other sites
now when i take the pow of some rather large powers, it gives me the same number but smaller pows work perfect. if u know this one let me know if not no big deal.

##### Share on other sites
perhaps the resulting big-ass number doesn''t fit in your data type? i think pow() returns a double, but are you putting it in an int or something?

##### Share on other sites
i used int for num1 num2 and equal
so i should use double now for equal right?

##### Share on other sites
ok that worked great now it says e+ some variable which is what i wanted. thanks again.

##### Share on other sites
you could always do a while loop, or even better, bitwise operators if your just doing a square, or square root

##### Share on other sites
You could create your own function for a little coding practice...
Example:
float ComputeExponent(float base, float exponent){   int index;   float endresult = base;   for(index = 0; index < exponent - 1; index++)       endresult *= base;   return endresult;}

Cheers,
-Jesse

| The Hitchhiker''''s Guide to Programming |
"That is not dead which can eternal lie,
And with strange aeons even death may die."
-H.P. Lovecraft

##### Share on other sites
thanks alot u guys u all are great help

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 15
• 11
• 9
• 38
• 16
• ### Forum Statistics

• Total Topics
634128
• Total Posts
3015694
×