Files
cppdraft_translate/cppdraft/bit/pow/two.md
2025-10-25 03:02:53 +03:00

3.2 KiB

[bit.pow.two]

22 General utilities library [utilities]

22.11 Bit manipulation [bit]

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

🔗

template<class T> constexpr bool has_single_bit(T x) noexcept;

1

#

Constraints: T is an unsigned integer type ([basic.fundamental]).

2

#

Returns: true if x is an integral power of two;false otherwise.

🔗

template<class T> constexpr T bit_ceil(T x);

3

#

Let N be the smallest power of 2 greater than or equal to x.

4

#

Constraints: T is an unsigned integer type ([basic.fundamental]).

5

#

Preconditions: N is representable as a value of type T.

6

#

Returns: N.

7

#

Throws: Nothing.

8

#

Remarks: A function call expression that violates the precondition in the Preconditions: element is not a core constant expression ([expr.const]).

🔗

template<class T> constexpr T bit_floor(T x) noexcept;

9

#

Constraints: T is an unsigned integer type ([basic.fundamental]).

10

#

Returns: If x == 0, 0; otherwise the maximal value y such that has_single_bit(y) is true and y <= x.

🔗

template<class T> constexpr int bit_width(T x) noexcept;

11

#

Constraints: T is an unsigned integer type ([basic.fundamental]).

12

#

Returns: If x == 0, 0; otherwise one plus the base-2 logarithm of x, with any fractional part discarded.