Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d01c56
commit 72d23cc
Showing
5 changed files
with
229 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# div | ||
* cstdlib[meta header] | ||
* std[meta namespace] | ||
* function[meta id-type] | ||
|
||
```cpp | ||
namespace std { | ||
div_t | ||
div(int numer, | ||
int denom); // (1) C++03 | ||
constexpr div_t | ||
div(int numer, | ||
int denom); // (1) C++23 | ||
|
||
ldiv_t | ||
div(long numer, | ||
long denom); // (2) C++03 | ||
constexpr ldiv_t | ||
div(long numer, | ||
long denom); // (2) C++23 | ||
|
||
lldiv_t | ||
div(long long numer, | ||
long long denom); // (3) C++03 | ||
constexpr lldiv_t | ||
div(long long numer, | ||
long long denom); // (3) C++23 | ||
|
||
ldiv_t | ||
ldiv(long numer, | ||
long denom); // (4) C++03 | ||
constexpr ldiv_t | ||
ldiv(long numer, | ||
long denom); // (4) C++23 | ||
|
||
lldiv_t | ||
lldiv(long long numer, | ||
long long denom); // (5) C++11 | ||
constexpr lldiv_t | ||
lldiv(long long numer, | ||
long long denom); // (5) C++23 | ||
} | ||
``` | ||
* div_t[link div_t.md] | ||
* ldiv_t[link ldiv_t.md] | ||
* lldiv_t[link lldiv_t.md] | ||
## 概要 | ||
`number / denom`と`number % denom`の計算をひとつの操作で行う。 | ||
- (1) : `int`型のオーバーロード | ||
- (2) : `long`型のオーバーロード | ||
- (3) : `long long`型のオーバーロード | ||
- (4) : `long`型規定 | ||
- (5) : `long long`型規定 | ||
## 戻り値 | ||
戻り値型となるクラスの`quot`に商、`rem`に剰余を代入して返す。 | ||
結果のどちらかが表現できない場合は未定義動作となる。 | ||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <cstdlib> | ||
int main() | ||
{ | ||
std::div_t x = std::div(5, 2); | ||
std::cout << x.quot << std::endl; | ||
std::cout << x.rem << std::endl; | ||
} | ||
``` | ||
* std::div[color ff0000] | ||
* std::div_t[link div_t.md] | ||
|
||
### 出力 | ||
``` | ||
2 | ||
1 | ||
``` | ||
|
||
|
||
### 備考 | ||
特定の環境では、早期に `constexpr` 対応されている場合がある: | ||
|
||
- GCC 4.6.1 以上 | ||
|
||
|
||
## 参照 | ||
- [P0533R9 constexpr for `<cmath>` and `<cstdlib>`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0533r9.pdf) | ||
- C++23での、一部関数の`constexpr`対応 | ||
- [P1467R9 Extended floating-point types and standard names](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html) | ||
- C++23で導入された拡張浮動小数点数型への対応として、`float`、`double`、`long double`のオーバーロードを`floating-point-type`のオーバーロードに統合し、拡張浮動小数点数型も扱えるようにした |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# div_t | ||
* cstdlib[meta header] | ||
* std[meta namespace] | ||
* class[meta id-type] | ||
|
||
```cpp | ||
namespace std { | ||
struct div_t { | ||
int quot; | ||
int rem; | ||
}; | ||
} | ||
``` | ||
## 概要 | ||
[`std::div()`](div.md)関数の戻り値。 | ||
`quot`は「quotient (商)」、`rem`は「remainder (剰余)」。 | ||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <cstdlib> | ||
int main() | ||
{ | ||
std::div_t x = std::div(5, 2); | ||
std::cout << x.quot << std::endl; | ||
std::cout << x.rem << std::endl; | ||
} | ||
``` | ||
* std::div_t[color ff0000] | ||
* std::div[link div.md] | ||
|
||
### 出力 | ||
``` | ||
2 | ||
1 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# ldiv_t | ||
* cstdlib[meta header] | ||
* std[meta namespace] | ||
* class[meta id-type] | ||
|
||
```cpp | ||
namespace std { | ||
struct ldiv_t { | ||
long quot; | ||
long rem; | ||
}; | ||
} | ||
``` | ||
## 概要 | ||
[`std::div()`](div.md)関数の`long`版の戻り値。 | ||
`quot`は「quotient (商)」、`rem`は「remainder (剰余)」。 | ||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <cstdlib> | ||
int main() | ||
{ | ||
std::ldiv_t x = std::div(5L, 2L); | ||
std::cout << x.quot << std::endl; | ||
std::cout << x.rem << std::endl; | ||
} | ||
``` | ||
* std::ldiv_t[color ff0000] | ||
* std::div[link div.md] | ||
|
||
### 出力 | ||
``` | ||
2 | ||
1 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# lldiv_t | ||
* cstdlib[meta header] | ||
* std[meta namespace] | ||
* class[meta id-type] | ||
* cpp11[meta cpp] | ||
|
||
```cpp | ||
namespace std { | ||
struct lldiv_t { | ||
long long quot; | ||
long long rem; | ||
}; | ||
} | ||
``` | ||
## 概要 | ||
[`std::div()`](div.md)関数の`long long`版の戻り値。 | ||
`quot`は「quotient (商)」、`rem`は「remainder (剰余)」。 | ||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <cstdlib> | ||
int main() | ||
{ | ||
std::lldiv_t x = std::div(5LL, 2LL); | ||
std::cout << x.quot << std::endl; | ||
std::cout << x.rem << std::endl; | ||
} | ||
``` | ||
* std::lldiv_t[color ff0000] | ||
* std::div[link div.md] | ||
|
||
### 出力 | ||
``` | ||
2 | ||
1 | ||
``` | ||
|