Derive-C
Loading...
Searching...
No Matches
dc::math Namespace Reference

Functions

template<typename T>
constexpr unsigned msb_index (T x) noexcept

Function Documentation

◆ msb_index()

template<typename T>
unsigned dc::math::msb_index ( T x)
constexprnoexcept

Definition at line 30 of file math.h.

30 {
31 static_assert(std::is_unsigned_v<T>, "DC_MATH_MSB_INDEX requires an unsigned integer type");
32
33 if (x == 0) {
34 return 0U;
35 }
36
37 constexpr unsigned bits = sizeof(T) * 8U;
38 return bits - 1U - std::countl_zero(x);
39}