diff --git a/include/ratio b/include/ratio index 4ef66c5bf..654cb3312 100644 --- a/include/ratio +++ b/include/ratio @@ -90,6 +90,12 @@ struct __static_gcd<_Xp, 0> static const intmax_t value = _Xp; }; +template <> +struct __static_gcd<0, 0> +{ + static const intmax_t value = 1; +}; + // __static_lcm template diff --git a/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp b/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp index 3d43fc048..a537f0215 100644 --- a/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp +++ b/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp @@ -55,4 +55,22 @@ int main() typedef std::ratio_add::type R; static_assert(R::num == 127970191639601LL && R::den == 5177331081415LL, ""); } + { + typedef std::ratio<0> R1; + typedef std::ratio<0> R2; + typedef std::ratio_add::type R; + static_assert(R::num == 0 && R::den == 1, ""); + } + { + typedef std::ratio<1> R1; + typedef std::ratio<0> R2; + typedef std::ratio_add::type R; + static_assert(R::num == 1 && R::den == 1, ""); + } + { + typedef std::ratio<0> R1; + typedef std::ratio<1> R2; + typedef std::ratio_add::type R; + static_assert(R::num == 1 && R::den == 1, ""); + } } diff --git a/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp b/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp index 5c77fffae..33efd90f5 100644 --- a/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp +++ b/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp @@ -55,4 +55,22 @@ int main() typedef std::ratio_subtract::type R; static_assert(R::num == -126708206685271LL && R::den == 5177331081415LL, ""); } + { + typedef std::ratio<0> R1; + typedef std::ratio<0> R2; + typedef std::ratio_subtract::type R; + static_assert(R::num == 0 && R::den == 1, ""); + } + { + typedef std::ratio<1> R1; + typedef std::ratio<0> R2; + typedef std::ratio_subtract::type R; + static_assert(R::num == 1 && R::den == 1, ""); + } + { + typedef std::ratio<0> R1; + typedef std::ratio<1> R2; + typedef std::ratio_subtract::type R; + static_assert(R::num == -1 && R::den == 1, ""); + } }