1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <complex>
11
12 // template<class T>
13 // complex<T>
14 // operator*(const complex<T>& lhs, const complex<T>& rhs);
15
16 #include <complex>
17 #include <cassert>
18
19 #include "../cases.h"
20
21 template <class T>
22 void
test(const std::complex<T> & lhs,const std::complex<T> & rhs,std::complex<T> x)23 test(const std::complex<T>& lhs, const std::complex<T>& rhs, std::complex<T> x)
24 {
25 assert(lhs * rhs == x);
26 }
27
28 template <class T>
29 void
test()30 test()
31 {
32 std::complex<T> lhs(1.5, 2.5);
33 std::complex<T> rhs(1.5, 2.5);
34 std::complex<T> x(-4.0, 7.5);
35 test(lhs, rhs, x);
36 }
37
38 // test edges
39
test_edges()40 void test_edges()
41 {
42 const unsigned N = sizeof(x) / sizeof(x[0]);
43 for (unsigned i = 0; i < N; ++i)
44 {
45 for (unsigned j = 0; j < N; ++j)
46 {
47 std::complex<double> r = x[i] * x[j];
48 switch (classify(x[i]))
49 {
50 case zero:
51 switch (classify(x[j]))
52 {
53 case zero:
54 assert(classify(r) == zero);
55 break;
56 case non_zero:
57 assert(classify(r) == zero);
58 break;
59 case inf:
60 assert(classify(r) == NaN);
61 break;
62 case NaN:
63 assert(classify(r) == NaN);
64 break;
65 case non_zero_nan:
66 assert(classify(r) == NaN);
67 break;
68 }
69 break;
70 case non_zero:
71 switch (classify(x[j]))
72 {
73 case zero:
74 assert(classify(r) == zero);
75 break;
76 case non_zero:
77 assert(classify(r) == non_zero);
78 break;
79 case inf:
80 assert(classify(r) == inf);
81 break;
82 case NaN:
83 assert(classify(r) == NaN);
84 break;
85 case non_zero_nan:
86 assert(classify(r) == NaN);
87 break;
88 }
89 break;
90 case inf:
91 switch (classify(x[j]))
92 {
93 case zero:
94 assert(classify(r) == NaN);
95 break;
96 case non_zero:
97 assert(classify(r) == inf);
98 break;
99 case inf:
100 assert(classify(r) == inf);
101 break;
102 case NaN:
103 assert(classify(r) == NaN);
104 break;
105 case non_zero_nan:
106 assert(classify(r) == inf);
107 break;
108 }
109 break;
110 case NaN:
111 switch (classify(x[j]))
112 {
113 case zero:
114 assert(classify(r) == NaN);
115 break;
116 case non_zero:
117 assert(classify(r) == NaN);
118 break;
119 case inf:
120 assert(classify(r) == NaN);
121 break;
122 case NaN:
123 assert(classify(r) == NaN);
124 break;
125 case non_zero_nan:
126 assert(classify(r) == NaN);
127 break;
128 }
129 break;
130 case non_zero_nan:
131 switch (classify(x[j]))
132 {
133 case zero:
134 assert(classify(r) == NaN);
135 break;
136 case non_zero:
137 assert(classify(r) == NaN);
138 break;
139 case inf:
140 assert(classify(r) == inf);
141 break;
142 case NaN:
143 assert(classify(r) == NaN);
144 break;
145 case non_zero_nan:
146 assert(classify(r) == NaN);
147 break;
148 }
149 break;
150 }
151 }
152 }
153 }
154
main()155 int main()
156 {
157 test<float>();
158 test<double>();
159 test<long double>();
160 test_edges();
161 }
162