Jump to content
  • Advertisement
Sign in to follow this  
Raeldor

Get exponent from number and base?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to get an exponent from a number and a base. For example, passing 32 and 2 would result in 5 because 2 to the power of 5=32. Thanks

Share this post


Link to post
Share on other sites
Advertisement
this works it seems

#include <iostream>
#include <math.h>
using namespace std;

int main(){

int tot = //number you want to find exponent of
int curr = 0; //keeps track of values
int x;
for(x = 0; curr <= tot; x++){
curr += pow(2,x);
}
x = x - 1;
cout << x << endl;

}

Share this post


Link to post
Share on other sites
Quote:
Original post by load_bitmap_file
Simple algebra: log(x)/log(y) or ln(x)/ln(y) if you'd prefer :P

So your example would be log(32)/log(2) = 5


Log returns base-10 logarithm?

Share this post


Link to post
Share on other sites
Quote:
Original post by Raeldor
Log returns base-10 logarithm?


Doesn't matter, as long as you do log(x)/log(y), it will work.

Share this post


Link to post
Share on other sites
Quote:
Original post by chaosgame
Quote:
Original post by Raeldor
Log returns base-10 logarithm?


Doesn't matter, as long as you do log(x)/log(y), it will work.


Is this one of these mathematical mysteries like PI? :P

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!