Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // test ratio_subtract |
| 11 | |
| 12 | #include <ratio> |
| 13 | |
| 14 | int main() |
| 15 | { |
| 16 | { |
| 17 | typedef std::ratio<1, 1> R1; |
| 18 | typedef std::ratio<1, 1> R2; |
| 19 | typedef std::ratio_subtract<R1, R2>::type R; |
| 20 | static_assert(R::num == 0 && R::den == 1, ""); |
| 21 | } |
| 22 | { |
| 23 | typedef std::ratio<1, 2> R1; |
| 24 | typedef std::ratio<1, 1> R2; |
| 25 | typedef std::ratio_subtract<R1, R2>::type R; |
| 26 | static_assert(R::num == -1 && R::den == 2, ""); |
| 27 | } |
| 28 | { |
| 29 | typedef std::ratio<-1, 2> R1; |
| 30 | typedef std::ratio<1, 1> R2; |
| 31 | typedef std::ratio_subtract<R1, R2>::type R; |
| 32 | static_assert(R::num == -3 && R::den == 2, ""); |
| 33 | } |
| 34 | { |
| 35 | typedef std::ratio<1, -2> R1; |
| 36 | typedef std::ratio<1, 1> R2; |
| 37 | typedef std::ratio_subtract<R1, R2>::type R; |
| 38 | static_assert(R::num == -3 && R::den == 2, ""); |
| 39 | } |
| 40 | { |
| 41 | typedef std::ratio<1, 2> R1; |
| 42 | typedef std::ratio<-1, 1> R2; |
| 43 | typedef std::ratio_subtract<R1, R2>::type R; |
| 44 | static_assert(R::num == 3 && R::den == 2, ""); |
| 45 | } |
| 46 | { |
| 47 | typedef std::ratio<1, 2> R1; |
| 48 | typedef std::ratio<1, -1> R2; |
| 49 | typedef std::ratio_subtract<R1, R2>::type R; |
| 50 | static_assert(R::num == 3 && R::den == 2, ""); |
| 51 | } |
| 52 | { |
| 53 | typedef std::ratio<56987354, 467584654> R1; |
| 54 | typedef std::ratio<544668, 22145> R2; |
| 55 | typedef std::ratio_subtract<R1, R2>::type R; |
| 56 | static_assert(R::num == -126708206685271LL && R::den == 5177331081415LL, ""); |
| 57 | } |
Howard Hinnant | 05e4858 | 2011-11-01 23:13:37 +0000 | [diff] [blame^] | 58 | { |
| 59 | typedef std::ratio<0> R1; |
| 60 | typedef std::ratio<0> R2; |
| 61 | typedef std::ratio_subtract<R1, R2>::type R; |
| 62 | static_assert(R::num == 0 && R::den == 1, ""); |
| 63 | } |
| 64 | { |
| 65 | typedef std::ratio<1> R1; |
| 66 | typedef std::ratio<0> R2; |
| 67 | typedef std::ratio_subtract<R1, R2>::type R; |
| 68 | static_assert(R::num == 1 && R::den == 1, ""); |
| 69 | } |
| 70 | { |
| 71 | typedef std::ratio<0> R1; |
| 72 | typedef std::ratio<1> R2; |
| 73 | typedef std::ratio_subtract<R1, R2>::type R; |
| 74 | static_assert(R::num == -1 && R::den == 1, ""); |
| 75 | } |
Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 76 | } |