Created
July 11, 2012 12:19
-
-
Save jmbr/3090021 to your computer and use it in GitHub Desktop.
Next power of two
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
inline unsigned next_power_of_two(unsigned x) { | |
return unsigned(exp2f(ceilf(log2f(float(x))))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, ola-ct. I too was aware of that solution, which can be found in Chapter 3 of the book Hacker's Delight.