Fastest way to test if a number is a power of n?

Started by
30 comments, last by TangentZ 22 years, 2 months ago
I have a very quick function, but it only works for powers of 1.


int PowerOfOne(x)
{

return(1);

};


Hope that helps.

---signature---
People get ready.
I''m ready to play.
---signature---People get ready.I'm ready to play.
Advertisement
I hate to burst your bubble (actually, I don't), but that's incorrect... It should be:

      int PowerOfOne(x){  return x == 1;};    


Because the only thing that is a power of 1 is 1 itself.




Edited by - Kippesoep on February 13, 2002 1:43:00 AM
Kippesoep

This topic is closed to new replies.

Advertisement