<ratio>
コンパイル時に有理数を格納> <および処理するために使用するテンプレートと定数を定義するために、標準ヘッダーの比率を指定します。
#include <ratio>
比率の構造
template <intmax_t N, intmax_t D = 1>
struct ratio
{
static constexpr intmax_t num;
static constexpr intmax_t den;
typedef ratio<num, den> type;
};
ratio Structure は num と den == N または D と num と den よくあるファクタはありません。静的な定数 num と den を受け取るように定義します。 num / den は value ですテンプレート クラスによって表されます。 したがって、type は num == N0 と den == D0 インスタンス化 ratio<N0, D0> を指定します。
特殊化
<比率は>、次のフォームがある ratio の特殊な形式を定義します。
template <class R1, class R2> struct ratio_specialization
各クラスは、ratioから特化したクラスである 2 種類のテンプレート パラメーターを受け取ります。 type の値は関連の論理演算によって決まります。
名前 |
type 値 |
---|---|
ratio_add |
R1 + R2 |
ratio_divide |
R1 / R2 |
ratio_equal |
R1 == R2 |
ratio_greater |
R1 > R2 |
ratio_greater_equal |
R1 >= R2 |
ratio_less |
R1 < R2 |
ratio_less_equal |
R1 <= R2 |
ratio_multiply |
R1 * R2 |
ratio_not_equal |
!(R1 == R2) |
ratio_subtract |
R1 - R2 |
typedef
typedef ratio<1, 1000000000000000000> atto;
typedef ratio<1, 1000000000000000> femto;
typedef ratio<1, 1000000000000> pico;
typedef ratio<1, 1000000000> nano;
typedef ratio<1, 1000000> micro;
typedef ratio<1, 1000> milli;
typedef ratio<1, 100> centi;
typedef ratio<1, 10> deci;
typedef ratio< 10, 1> deca;
typedef ratio< 100, 1> hecto;
typedef ratio< 1000, 1> kilo;
typedef ratio< 1000000, 1> mega;
typedef ratio< 1000000000, 1> giga;
typedef ratio< 1000000000000, 1> tera;
typedef ratio< 1000000000000000, 1> peta;
typedef ratio< 1000000000000000000, 1> exa;