Author: hhinnant
Date: Tue Nov 1 18:13:37 2011
New Revision: 143519
URL: http://llvm.org/viewvc/llvm-project?rev=143519&view=rev
Log:
Fix ratio arithmetic with zero
Modified:
libcxx/trunk/include/ratio
libcxx/trunk/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp
libcxx/trunk/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp
Modified: libcxx/trunk/include/ratio
URL:
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ratio?rev=143519&r1=143518&r2=143519&view=diff
==============================================================================
--- libcxx/trunk/include/ratio (original)
+++ libcxx/trunk/include/ratio Tue Nov 1 18:13:37 2011
@@ -90,6 +90,12 @@
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>
Modified: libcxx/trunk/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp
URL:
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp?rev=143519&r1=143518&r2=143519&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp
(original)
+++ libcxx/trunk/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp Tue
Nov 1 18:13:37 2011
@@ -55,4 +55,22 @@
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, "");
+ }
}
Modified:
libcxx/trunk/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp
URL:
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp?rev=143519&r1=143518&r2=143519&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp
(original)
+++ libcxx/trunk/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp
Tue Nov 1 18:13:37 2011
@@ -55,4 +55,22 @@
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, "");
+ }
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits