std::ratio
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <ratio> で定義
|
||
template< std::intmax_t Num, std::intmax_t Denom = 1 > class ratio; |
(C++11以上) | |
クラステンプレート std::ratio はコンパイル時有理数算術のサポートを提供します。 このテンプレートの各実体化は、その分子と分母が std::intmax_t 型のコンパイル時定数として表現できる限り、任意の有限の有理数を正確に表現します。 Denom はゼロであってはならず、最も負な値と等しくあってはなりません。
分子と分母を表す静的データメンバ num および den は、 Num および Denom をそれらの最大公約数で割ることによって計算されます。 しかし、異なる Num または Denom を持つ2つの std::ratio は、たとえそれらが (約分した後で) 同じ有理数を表していても、異なる型です。 ratio 型はその type メンバを通して最も小さな項に約分できます (std::ratio<3, 6>::type は std::ratio<1, 2> です)。
SI 接頭辞に対応するいくつかの便利な typedef が標準ライブラリによって提供されます。
ヘッダ
<ratio> で定義 | |
| 型 | 定義 |
yocto
|
std::ratio<1, 1000000000000000000000000> (std::intmax_t がその分母を表現できる場合)
|
zepto
|
std::ratio<1, 1000000000000000000000> (std::intmax_t がその分母を表現できる場合)
|
atto
|
std::ratio<1, 1000000000000000000>
|
femto
|
std::ratio<1, 1000000000000000>
|
pico
|
std::ratio<1, 1000000000000>
|
nano
|
std::ratio<1, 1000000000>
|
micro
|
std::ratio<1, 1000000>
|
milli
|
std::ratio<1, 1000>
|
centi
|
std::ratio<1, 100>
|
deci
|
std::ratio<1, 10>
|
deca
|
std::ratio<10, 1>
|
hecto
|
std::ratio<100, 1>
|
kilo
|
std::ratio<1000, 1>
|
mega
|
std::ratio<1000000, 1>
|
giga
|
std::ratio<1000000000, 1>
|
tera
|
std::ratio<1000000000000, 1>
|
peta
|
std::ratio<1000000000000000, 1>
|
exa
|
std::ratio<1000000000000000000, 1>
|
zetta
|
std::ratio<1000000000000000000000, 1> (std::intmax_t がその分子を表現できる場合)
|
yotta
|
std::ratio<1000000000000000000000000, 1> (std::intmax_t がその分子を表現できる場合)
|
メンバ型
| メンバ型 | 定義 |
type
|
std::ratio<num, den>
|
メンバオブジェクト
constexpr intmax_t num [静的] |
sign(Num) * sign(Denom) * abs(Num) / gcd(Num, Denom) と等しい std::intmax_t 型の constexpr な値 (パブリック静的メンバ定数) |
constexpr intmax_t den [静的] |
abs(Denom) / gcd(Num, Denom) と等しい std::intmax_t 型の constexpr な値 (パブリック静的メンバ定数) |