std::ratio

From cppreference.com
< cpplrm; | numericlrm; | ratio
Defined in header <ratio>
template<

std::intmax_t Num,
std::intmax_t Denom = 1

> class ratio;
(since C++11)

The class template std::ratio provides compile-time rational arithmetic support. Each instantiation of this template exactly represents any finite rational number as long as its numerator Num and denominator Denom are representable as compile-time constants of type std::intmax_t. In addition, Denom may not be zero and may not be equal to the most negative value. Both numerator and denominator are automatically reduced to the lowest terms.

Several convenience typedefs that correspond to the SI ratios are provided by the standard library:

Defined in header <ratio>
Type Definition
yocto std::ratio<1, 1000000000000000000000000>, if std::intmax_t can represent the denominator
zepto std::ratio<1, 1000000000000000000000>, if std::intmax_t can represent the denominator
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>, if std::intmax_t can represent the numerator
yotta std::ratio<1000000000000000000000000, 1>, if std::intmax_t can represent the numerator

Member types

Member type Definition
type std::ratio<num, den>

Member objects

constexpr intmax_t num
[static]
constexpr value of type std::intmax_t equal to sign(Num) * sign(Denom) * abs(Num) / gcd(Num, Denom)
(public static member constant)
constexpr intmax_t den
[static]
constexpr value of type std::intmax_t equal to abs(Denom) / gcd(Num, Denom)
(public static member constant)