std::ratio
From Cppreference
| C++ Standard Library | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Numerics library | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile time rational arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Defined in header <ratio>
|
||
| template<
intmax_t Num, |
(since C++11) | |
The class template ratio is the core class in the compile-time rational arithmetic library. It reduces the supplied numerator and denominator to the lowest terms.
Several convenience SI typedefs are already provided:
| typedef std::ratio<1, 1000000000000000000000000> yocto; //see below
typedef std::ratio<1, 1000000000000000000000> zepto; //see below |
(since C++11) | |
The typedefs yocto, zepto, zetta, yotta are provided only if intmax_t is sufficient to represent the values used to instantiate the templates.
[edit] Template parameters
| Nom | - | defines the numerator of the ratio |
| Denom | - | defines the denominator of the ratio. It cannot be equal to 0 |
[edit] Member objects
|
static constexpr intmax_t num
[static]
|
defines the reduced numerator. Equivalent to sign(N) * sign(D) * abs(N) / gcd(D,N) (public static member constant) |
|
static constexpr intmax_t den
[static]
|
defines the reduced denominator. Equivalent to abs(D) / gcd(D,N) (public static member constant) |