Namespaces
Variants
Views
Actions

std::log2p1

From cppreference.com
< cpp‎ | numeric
Revision as of 00:50, 18 June 2018 by T. Canens (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
 
 
Defined in header <bit>
template< class T >
constexpr T log2p1(T x) noexcept;
(since C++20)

If x is not zero, calculates the number of bits needed to store the value x, that is, 1 + floor(log2(x)). If x is zero, returns zero.

This overload participates in overload resolution only if T is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type.

Return value

Zero if x is zero; otherwise, one plus the base-2 logarithm of x, with any fractional part discarded.

Example