namespace std {
template <class T>
constexpr T bit_floor(T x) noexcept;
}
概要
整数値を2の累乗値に切り下げる。
テンプレートパラメータ制約
- 型
T
が符号なし整数型であること
戻り値
x == 0
である場合、0
を返す。そうでない場合、has_single_bit(y) == true
およびy <= x
となるような最大のy
を求めて返す。
例外
投げない
例
出力
129 : 128
0 : 0
1 : 1
2 : 2
3 : 2
4 : 4
5 : 4
6 : 4
7 : 4
8 : 8
9 : 8
10 : 8
11 : 8
12 : 8
13 : 8
14 : 8
15 : 8
16 : 16
17 : 16
18 : 16
19 : 16
20 : 16
21 : 16
22 : 16
23 : 16
24 : 16
25 : 16
26 : 16
27 : 16
28 : 16
29 : 16
30 : 16
31 : 16
32 : 32
33 : 32
34 : 32
バージョン
言語
- C++20
処理系
- Clang:
- GCC: 9.1 ✅
- Visual C++: ??
参照
- P0556R3 Integral power-of-2 operations
- P1956R1 On the names of low-level bit manipulation functions
--
std::floor2
からstd::bit_floor
に名称変更