The ratio header provides compile-time rational arithmetic for representing values such as 60:1, 3:6, or 1:1,000,000,000. std::ratio reduces fractions and exposes their numerator and denominator. section 4.2.1
Its facilities support:
- Comparing equivalent ratios with ratio_equal. section 4.2.1
- Adding and multiplying ratios at compile time. section 4.2.1 section 4.2.2
- Naming common SI scales such as nano, milli, and kilo. section 4.2.1
- Defining custom chrono durations, including centuries. section 4.2.2
Reduced fractions
std::ratio<3, 6> becomes 1/2, while ratio_add can combine it with another half to produce 1/1. section 4.2.1
template<std::intmax_t Num, std::intmax_t Denom = 1> class ratio;
The declaration shows that numerator and denominator are signed integer non-type template parameters, with the denominator defaulting to 1. section 4.2.1
