1
0
Fork 0
forked from suyu/suyu

Merge pull request #7695 from Morph1984/is-pow2

common: bit_util: Add IsPow2 helper function
This commit is contained in:
bunnei 2022-01-20 18:06:11 -08:00 committed by GitHub
commit ef7c50b276
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -45,6 +45,12 @@ template <typename T>
return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL)); return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL));
} }
template <typename T>
requires std::is_unsigned_v<T>
[[nodiscard]] constexpr bool IsPow2(T value) {
return std::has_single_bit(value);
}
template <typename T> template <typename T>
requires std::is_integral_v<T> requires std::is_integral_v<T>
[[nodiscard]] T NextPow2(T value) { [[nodiscard]] T NextPow2(T value) {