xref: /llvm-project/libcxx/test/std/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp (revision 7fc6a55688c816f5fc1a5481ae7af25be7500356)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // test ratio_subtract
10 
11 #include <ratio>
12 
13 #include "test_macros.h"
14 
main(int,char **)15 int main(int, char**)
16 {
17     {
18     typedef std::ratio<1, 1> R1;
19     typedef std::ratio<1, 1> R2;
20     typedef std::ratio_subtract<R1, R2>::type R;
21     static_assert(R::num == 0 && R::den == 1, "");
22     }
23     {
24     typedef std::ratio<1, 2> R1;
25     typedef std::ratio<1, 1> R2;
26     typedef std::ratio_subtract<R1, R2>::type R;
27     static_assert(R::num == -1 && R::den == 2, "");
28     }
29     {
30     typedef std::ratio<-1, 2> R1;
31     typedef std::ratio<1, 1> R2;
32     typedef std::ratio_subtract<R1, R2>::type R;
33     static_assert(R::num == -3 && R::den == 2, "");
34     }
35     {
36     typedef std::ratio<1, -2> R1;
37     typedef std::ratio<1, 1> R2;
38     typedef std::ratio_subtract<R1, R2>::type R;
39     static_assert(R::num == -3 && R::den == 2, "");
40     }
41     {
42     typedef std::ratio<1, 2> R1;
43     typedef std::ratio<-1, 1> R2;
44     typedef std::ratio_subtract<R1, R2>::type R;
45     static_assert(R::num == 3 && R::den == 2, "");
46     }
47     {
48     typedef std::ratio<1, 2> R1;
49     typedef std::ratio<1, -1> R2;
50     typedef std::ratio_subtract<R1, R2>::type R;
51     static_assert(R::num == 3 && R::den == 2, "");
52     }
53     {
54     typedef std::ratio<56987354, 467584654> R1;
55     typedef std::ratio<544668, 22145> R2;
56     typedef std::ratio_subtract<R1, R2>::type R;
57     static_assert(R::num == -126708206685271LL && R::den == 5177331081415LL, "");
58     }
59     {
60     typedef std::ratio<0> R1;
61     typedef std::ratio<0> R2;
62     typedef std::ratio_subtract<R1, R2>::type R;
63     static_assert(R::num == 0 && R::den == 1, "");
64     }
65     {
66     typedef std::ratio<1> R1;
67     typedef std::ratio<0> R2;
68     typedef std::ratio_subtract<R1, R2>::type R;
69     static_assert(R::num == 1 && R::den == 1, "");
70     }
71     {
72     typedef std::ratio<0> R1;
73     typedef std::ratio<1> R2;
74     typedef std::ratio_subtract<R1, R2>::type R;
75     static_assert(R::num == -1 && R::den == 1, "");
76     }
77 
78   return 0;
79 }
80