Fix ratio arithmetic with zero

llvm-svn: 143519
This commit is contained in:
Howard Hinnant 2011-11-01 23:13:37 +00:00
parent 3018b95093
commit 05e485879c
3 changed files with 42 additions and 0 deletions

View File

@ -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 <intmax_t _Xp, intmax_t _Yp>

View File

@ -55,4 +55,22 @@ int main()
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == 127970191639601LL && R::den == 5177331081415LL, "");
}
{
typedef std::ratio<0> R1;
typedef std::ratio<0> R2;
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == 0 && R::den == 1, "");
}
{
typedef std::ratio<1> R1;
typedef std::ratio<0> R2;
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == 1 && R::den == 1, "");
}
{
typedef std::ratio<0> R1;
typedef std::ratio<1> R2;
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == 1 && R::den == 1, "");
}
}

View File

@ -55,4 +55,22 @@ int main()
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == -126708206685271LL && R::den == 5177331081415LL, "");
}
{
typedef std::ratio<0> R1;
typedef std::ratio<0> R2;
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == 0 && R::den == 1, "");
}
{
typedef std::ratio<1> R1;
typedef std::ratio<0> R2;
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == 1 && R::den == 1, "");
}
{
typedef std::ratio<0> R1;
typedef std::ratio<1> R2;
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 1, "");
}
}