24 Numerics library [numerics]

24.6 Bit manipulation [bit]

24.6.4 Integral powers of 2 [bit.pow.two]

template <class T> constexpr bool ispow2(T x) noexcept;
Returns: true if x is an integral power of two; false otherwise.
Remarks: This function shall not participate in overload resolution unless T is an unsigned integer type ([basic.fundamental]).
template <class T> constexpr T ceil2(T x) noexcept;
Returns: The minimal value y such that ispow2(y) is true and y >= x; if y is not representable as a value of type T, the result is an unspecified value.
Remarks: This function shall not participate in overload resolution unless T is an unsigned integer type ([basic.fundamental]).
template <class T> constexpr T floor2(T x) noexcept;
Returns: If x == 0, 0; otherwise the maximal value y such that ispow2(y) is true and y <= x.
Remarks: This function shall not participate in overload resolution unless T is an unsigned integer type ([basic.fundamental]).
template <class T> constexpr T log2p1(T x) noexcept;
Returns: If x == 0, 0; otherwise one plus the base-2 logarithm of x, with any fractional part discarded.
Remarks: This function shall not participate in overload resolution unless T is an unsigned integer type ([basic.fundamental]).