File tree Expand file tree Collapse file tree 5 files changed +215
-5
lines changed
Expand file tree Collapse file tree 5 files changed +215
-5
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ C++20とは、2020年中に改訂される予定の、C++バージョンの通
8989- [ ` <compare> ` ] ( /reference/compare.md.nolink ) ヘッダを新設する。ここでは、一貫比較 (宇宙船演算子) をサポートするための型と比較関数が定義される
9090- [ ` <bit> ` ] ( /reference/bit.md ) ヘッダを新設する
9191 - Struct Aliasing規則に抵触しないビットレベルの再解釈キャストである[ ` std::bit_cast() ` ] ( /reference/bit/bit_cast.md.nolink ) 関数を追加
92- - 2の乗数関係の関数として、整数値が2の乗数かを判定する [ ` std::ispow2() ` ] ( /reference/bit/ispow2.md ) 関数、整数値を2の乗数値に切り上げる [ ` std::ceil2() ` ] ( /reference/bit/ceil2.md.nolink ) 関数、整数値を2の乗数値に切り下げる [ ` std::floor2() ` ] ( /reference/bit/floor2.md.nolink ) 関数、2を底とした整数値の対数を求める[ ` std::log2p1() ` ] ( /reference/bit/log2p1.md.nolink ) 関数を追加
92+ - 2の乗数関係の関数として、整数値が2の累乗かを判定する [ ` std::ispow2() ` ] ( /reference/bit/ispow2.md ) 関数、整数値を2の累乗値に切り上げる [ ` std::ceil2() ` ] ( /reference/bit/ceil2.md ) 関数、整数値を2の累乗値に切り下げる [ ` std::floor2() ` ] ( /reference/bit/floor2.md ) 関数、2を底とした整数値の対数を求める[ ` std::log2p1() ` ] ( /reference/bit/log2p1.md.nolink ) 関数を追加
9393- 型制約のための要件ライブラリとして[ ` <concepts> ` ] ( /reference/concepts.md ) を追加
9494
9595
Original file line number Diff line number Diff line change 1515
1616| 名前 | 説明 | 対応バージョン |
1717| ------| ------| ----------------|
18- | [ ` ispow2 ` ] ( bit/ispow2.md ) | 整数値が2の乗数かを判定する (functional template) | C++20 |
19- | [ ` ceil2 ` ] ( bit/ceil2.md.nolink ) | 整数値を2の乗数値に切り上げる (functional template) | C++20 |
20- | [ ` floor2 ` ] ( bit/floor2.md.nolink ) | 整数値を2の乗数値に切り下げる (functional template) | C++20 |
18+ | [ ` ispow2 ` ] ( bit/ispow2.md ) | 整数値が2の累乗かを判定する (functional template) | C++20 |
19+ | [ ` ceil2 ` ] ( bit/ceil2.md ) | 整数値を2の累乗値に切り上げる (functional template) | C++20 |
20+ | [ ` floor2 ` ] ( bit/floor2.md ) | 整数値を2の累乗値に切り下げる (functional template) | C++20 |
2121| [ ` log2p1 ` ] ( bit/log2p1.md.nolink ) | 2を底とした整数値の対数を求める (functional template) | C++20 |
2222
2323
Original file line number Diff line number Diff line change 1+ # ceil2
2+ * bit[ meta header]
3+ * std[ meta namespace]
4+ * function template[ meta id-type]
5+ * cpp20[ meta cpp]
6+
7+ ``` cpp
8+ namespace std {
9+ template <class T >
10+ constexpr T ceil2(T x) noexcept;
11+ }
12+ ```
13+
14+ ## 概要
15+ 整数値を2の累乗値に切り上げる。
16+
17+
18+ ## 要件
19+ 以下の条件を満たさない場合、この関数はオーバーロード解決の候補から除外される
20+
21+ - 型`T`が符号なし整数型であること
22+
23+
24+ ## 戻り値
25+ [`ispow2`](ispow2.md)`(y) == true`および`y >= x`となるような最小の`y`を求めて返す。
26+
27+ `y`が型`T`の値として表現できない場合、戻り値は未規定の値となる。
28+
29+
30+ ## 例外
31+ 投げない
32+
33+
34+ ## 例
35+ ```cpp example
36+ #include <iostream>
37+ #include <bit>
38+
39+ void convert_to_pow2(unsigned int x)
40+ {
41+ std::cout << x << "\t : " << std::ceil2(x) << std::endl;
42+ }
43+
44+ int main()
45+ {
46+ std::cout << "127\t : " << std::ceil2(127u) << std::endl;
47+
48+ for (unsigned int i = 0u; i <= 32u; ++i) {
49+ convert_to_pow2(i);
50+ }
51+ }
52+ ```
53+ * std::ceil2[ color ff0000]
54+
55+ ### 出力
56+ ```
57+ 127 : 128
58+ 0 : 1
59+ 1 : 1
60+ 2 : 2
61+ 3 : 4
62+ 4 : 4
63+ 5 : 8
64+ 6 : 8
65+ 7 : 8
66+ 8 : 8
67+ 9 : 16
68+ 10 : 16
69+ 11 : 16
70+ 12 : 16
71+ 13 : 16
72+ 14 : 16
73+ 15 : 16
74+ 16 : 16
75+ 17 : 32
76+ 18 : 32
77+ 19 : 32
78+ 20 : 32
79+ 21 : 32
80+ 22 : 32
81+ 23 : 32
82+ 24 : 32
83+ 25 : 32
84+ 26 : 32
85+ 27 : 32
86+ 28 : 32
87+ 29 : 32
88+ 30 : 32
89+ 31 : 32
90+ 32 : 32
91+ ```
92+
93+
94+ ## バージョン
95+ ### 言語
96+ - C++20
97+
98+ ### 処理系
99+ - [ Clang, C++20 mode] ( /implementation.md#clang ) :
100+ - [ GCC, C++20 mode] ( /implementation.md#gcc ) : 9.1
101+ - [ Visual C++] ( /implementation.md#visual_cpp ) : ??
102+
103+
104+ ## 参照
105+ - [ P0556R3 Integral power-of-2 operations] ( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0556r3.html )
Original file line number Diff line number Diff line change 1+ # floor2
2+ * bit[ meta header]
3+ * std[ meta namespace]
4+ * function template[ meta id-type]
5+ * cpp20[ meta cpp]
6+
7+ ``` cpp
8+ namespace std {
9+ template <class T >
10+ constexpr T floor2(T x) noexcept;
11+ }
12+ ```
13+
14+ ## 概要
15+ 整数値を2の累乗値に切り下げる。
16+
17+
18+ ## 要件
19+ 以下の条件を満たさない場合、この関数はオーバーロード解決の候補から除外される
20+
21+ - 型`T`が符号なし整数型であること
22+
23+
24+ ## 戻り値
25+ `x == 0`である場合、`0`を返す。そうでない場合、[`ispow2`](ispow2.md)`(y) == true`および`y <= x`となるような最大の`y`を求めて返す。
26+
27+
28+ ## 例外
29+ 投げない
30+
31+
32+ ## 例
33+ ```cpp example
34+ #include <iostream>
35+ #include <bit>
36+
37+ void convert_to_pow2(unsigned int x)
38+ {
39+ std::cout << x << "\t : " << std::floor2(x) << std::endl;
40+ }
41+
42+ int main()
43+ {
44+ std::cout << "129\t : " << std::floor2(129u) << std::endl;
45+
46+ for (unsigned int i = 0u; i <= 34u; ++i) {
47+ convert_to_pow2(i);
48+ }
49+ }
50+ ```
51+ * std::floor2[ color ff0000]
52+
53+ ### 出力
54+ ```
55+ 129 : 128
56+ 0 : 0
57+ 1 : 1
58+ 2 : 2
59+ 3 : 2
60+ 4 : 4
61+ 5 : 4
62+ 6 : 4
63+ 7 : 4
64+ 8 : 8
65+ 9 : 8
66+ 10 : 8
67+ 11 : 8
68+ 12 : 8
69+ 13 : 8
70+ 14 : 8
71+ 15 : 8
72+ 16 : 16
73+ 17 : 16
74+ 18 : 16
75+ 19 : 16
76+ 20 : 16
77+ 21 : 16
78+ 22 : 16
79+ 23 : 16
80+ 24 : 16
81+ 25 : 16
82+ 26 : 16
83+ 27 : 16
84+ 28 : 16
85+ 29 : 16
86+ 30 : 16
87+ 31 : 16
88+ 32 : 32
89+ 33 : 32
90+ 34 : 32
91+ ```
92+
93+
94+ ## バージョン
95+ ### 言語
96+ - C++20
97+
98+ ### 処理系
99+ - [ Clang, C++20 mode] ( /implementation.md#clang ) :
100+ - [ GCC, C++20 mode] ( /implementation.md#gcc ) : 9.1
101+ - [ Visual C++] ( /implementation.md#visual_cpp ) : ??
102+
103+
104+ ## 参照
105+ - [ P0556R3 Integral power-of-2 operations] ( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0556r3.html )
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ namespace std {
1212```
1313
1414## 概要
15- 整数値が2の乗数かを判定する 。
15+ 整数値が2の累乗かを判定する 。
1616
1717
1818## 要件
You can’t perform that action at this time.
0 commit comments