MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / RoundUpToPowerOfTwo

Function RoundUpToPowerOfTwo

Bcore/src/main/cpp/base/bit_utils.h:128–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126
127template <typename T>
128constexpr T RoundUpToPowerOfTwo(T x) {
129 static_assert(std::is_integral<T>::value, "T must be integral");
130 static_assert(std::is_unsigned<T>::value, "T must be unsigned");
131 // NOTE: Undefined if x > (1 << (std::numeric_limits<T>::digits - 1)).
132 return (x < 2u) ? x : static_cast<T>(1u) << (std::numeric_limits<T>::digits - CLZ(x - 1u));
133}
134
135// Return highest possible N - a power of two - such that val >= N.
136template <typename T>

Callers

nothing calls this directly

Calls 1

CLZFunction · 0.85

Tested by

no test coverage detected