[math_utils] Add is_power_of_two()

This commit is contained in:
Ming-Hung Tsai 2020-06-15 14:10:07 +08:00
parent 5260a87c0b
commit a345b894d3
1 changed files with 5 additions and 0 deletions

View File

@ -34,6 +34,11 @@ namespace base {
T div_down(T const &v, T const &divisor) {
return v / divisor;
}
template <typename T>
bool is_power_of_two(T const v) {
return !(v & (v - 1));
}
}
//----------------------------------------------------------------