[ratio.ratio] # 21 Metaprogramming library [[meta]](./#meta) ## 21.5 Compile-time rational arithmetic [[ratio]](ratio#ratio) ### 21.5.3 Class template ratio [ratio.ratio] [🔗](#lib:ratio) namespace std {template class ratio {public:static constexpr intmax_t num; static constexpr intmax_t den; using type = ratio; };} [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L7127) If the template argument D is zero or the absolute values of either of the template arguments N and D is not representable by typeintmax_t, the program is ill-formed[.](#1.sentence-1) [*Note [1](#note-1)*: These rules ensure that infinite ratios are avoided and that for any negative input, there exists a representable value of its absolute value which is positive[.](#1.sentence-2) This excludes the most negative value[.](#1.sentence-3) — *end note*] [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L7139) The static data members num and den shall have the following values, where gcd represents the greatest common divisor of the absolute values ofN and D: - [(2.1)](#2.1) num shall have the value sgn(N) * sgn(D) * abs(N) / gcd[.](#2.1.sentence-1) - [(2.2)](#2.2) den shall have the value abs(D) / gcd[.](#2.2.sentence-1)