1 //===-- muldc3_test.c - Test __muldc3 -------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests __muldc3 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
19 // Returns: the product of a + ib and c + id
21 COMPILER_RT_ABI double _Complex
22 __muldc3(double __a, double __b, double __c, double __d);
24 enum {zero, non_zero, inf, NaN, non_zero_nan};
27 classify(double _Complex x)
31 if (isinf(creal(x)) || isinf(cimag(x)))
33 if (isnan(creal(x)) && isnan(cimag(x)))
50 int test__muldc3(double a, double b, double c, double d)
52 double _Complex r = __muldc3(a, b, c, d);
53 // printf("test__muldc3(%f, %f, %f, %f) = %f + I%f\n",
54 // a, b, c, d, creal(r), cimag(r));
55 double _Complex dividend;
56 double _Complex divisor;
58 __real__ dividend = a;
59 __imag__ dividend = b;
63 switch (classify(dividend))
66 switch (classify(divisor))
69 if (classify(r) != zero)
73 if (classify(r) != zero)
77 if (classify(r) != NaN)
81 if (classify(r) != NaN)
85 if (classify(r) != NaN)
91 switch (classify(divisor))
94 if (classify(r) != zero)
98 if (classify(r) != non_zero)
100 if (r != a * c - b * d + _Complex_I*(a * d + b * c))
104 if (classify(r) != inf)
108 if (classify(r) != NaN)
112 if (classify(r) != NaN)
118 switch (classify(divisor))
121 if (classify(r) != NaN)
125 if (classify(r) != inf)
129 if (classify(r) != inf)
133 if (classify(r) != NaN)
137 if (classify(r) != inf)
143 switch (classify(divisor))
146 if (classify(r) != NaN)
150 if (classify(r) != NaN)
154 if (classify(r) != NaN)
158 if (classify(r) != NaN)
162 if (classify(r) != NaN)
168 switch (classify(divisor))
171 if (classify(r) != NaN)
175 if (classify(r) != NaN)
179 if (classify(r) != inf)
183 if (classify(r) != NaN)
187 if (classify(r) != NaN)
232 {-INFINITY, -INFINITY},
241 {INFINITY, -INFINITY},
340 {-INFINITY, INFINITY},
355 const unsigned N = sizeof(x) / sizeof(x[0]);
357 for (i = 0; i < N; ++i)
359 for (j = 0; j < N; ++j)
361 if (test__muldc3(x[i][0], x[i][1], x[j][0], x[j][1]))