Documentation Home >> Headers >> <ratio> Header >> std::ratio class template

The std::ratio class template provides a mechanism for compile-time arithmetic involving rational values such as one half (std::ratio<1,2>), two thirds (std::ratio<2,3>) or fifteen forty-thirds (std::ratio<15,43>). It is used within the just::thread library for specifying the period when instantiating the std::chrono::duration class template.

template <intmax_t N, intmax_t D = 1>
class ratio
{
public:
    static const intmax_t num= see below;
    static const intmax_t den= see below;
};

D may not be zero.

num and den are the numerator and denominator of the fraction N/D reduced to lowest terms. den is always positive. If N and D are the same sign, num is positive, otherwise num is negative.

ratio<4,6>::num == 2
ratio<4,6>::den == 3
ratio<4,-6>::num == -2
ratio<4,-6>::den == 3
Header

#include <ratio>

See Also