1*4684ddb6SLionel Sambuc //===-- multc3_test.c - Test __multc3 -------------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __multc3 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc
14*4684ddb6SLionel Sambuc #if _ARCH_PPC
15*4684ddb6SLionel Sambuc
16*4684ddb6SLionel Sambuc #include "int_lib.h"
17*4684ddb6SLionel Sambuc #include <math.h>
18*4684ddb6SLionel Sambuc #include <complex.h>
19*4684ddb6SLionel Sambuc #include <stdio.h>
20*4684ddb6SLionel Sambuc
21*4684ddb6SLionel Sambuc // Returns: the product of a + ib and c + id
22*4684ddb6SLionel Sambuc
23*4684ddb6SLionel Sambuc long double _Complex
24*4684ddb6SLionel Sambuc __multc3(long double __a, long double __b, long double __c, long double __d);
25*4684ddb6SLionel Sambuc
26*4684ddb6SLionel Sambuc enum {zero, non_zero, inf, NaN, non_zero_nan};
27*4684ddb6SLionel Sambuc
28*4684ddb6SLionel Sambuc int
classify(long double _Complex x)29*4684ddb6SLionel Sambuc classify(long double _Complex x)
30*4684ddb6SLionel Sambuc {
31*4684ddb6SLionel Sambuc if (x == 0)
32*4684ddb6SLionel Sambuc return zero;
33*4684ddb6SLionel Sambuc if (isinf(creall(x)) || isinf(cimagl(x)))
34*4684ddb6SLionel Sambuc return inf;
35*4684ddb6SLionel Sambuc if (isnan(creall(x)) && isnan(cimagl(x)))
36*4684ddb6SLionel Sambuc return NaN;
37*4684ddb6SLionel Sambuc if (isnan(creall(x)))
38*4684ddb6SLionel Sambuc {
39*4684ddb6SLionel Sambuc if (cimagl(x) == 0)
40*4684ddb6SLionel Sambuc return NaN;
41*4684ddb6SLionel Sambuc return non_zero_nan;
42*4684ddb6SLionel Sambuc }
43*4684ddb6SLionel Sambuc if (isnan(cimagl(x)))
44*4684ddb6SLionel Sambuc {
45*4684ddb6SLionel Sambuc if (creall(x) == 0)
46*4684ddb6SLionel Sambuc return NaN;
47*4684ddb6SLionel Sambuc return non_zero_nan;
48*4684ddb6SLionel Sambuc }
49*4684ddb6SLionel Sambuc return non_zero;
50*4684ddb6SLionel Sambuc }
51*4684ddb6SLionel Sambuc
test__multc3(long double a,long double b,long double c,long double d)52*4684ddb6SLionel Sambuc int test__multc3(long double a, long double b, long double c, long double d)
53*4684ddb6SLionel Sambuc {
54*4684ddb6SLionel Sambuc long double _Complex r = __multc3(a, b, c, d);
55*4684ddb6SLionel Sambuc // printf("test__multc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n",
56*4684ddb6SLionel Sambuc // a, b, c, d, creall(r), cimagl(r));
57*4684ddb6SLionel Sambuc long double _Complex dividend;
58*4684ddb6SLionel Sambuc long double _Complex divisor;
59*4684ddb6SLionel Sambuc
60*4684ddb6SLionel Sambuc __real__ dividend = a;
61*4684ddb6SLionel Sambuc __imag__ dividend = b;
62*4684ddb6SLionel Sambuc __real__ divisor = c;
63*4684ddb6SLionel Sambuc __imag__ divisor = d;
64*4684ddb6SLionel Sambuc
65*4684ddb6SLionel Sambuc switch (classify(dividend))
66*4684ddb6SLionel Sambuc {
67*4684ddb6SLionel Sambuc case zero:
68*4684ddb6SLionel Sambuc switch (classify(divisor))
69*4684ddb6SLionel Sambuc {
70*4684ddb6SLionel Sambuc case zero:
71*4684ddb6SLionel Sambuc if (classify(r) != zero)
72*4684ddb6SLionel Sambuc return 1;
73*4684ddb6SLionel Sambuc break;
74*4684ddb6SLionel Sambuc case non_zero:
75*4684ddb6SLionel Sambuc if (classify(r) != zero)
76*4684ddb6SLionel Sambuc return 1;
77*4684ddb6SLionel Sambuc break;
78*4684ddb6SLionel Sambuc case inf:
79*4684ddb6SLionel Sambuc if (classify(r) != NaN)
80*4684ddb6SLionel Sambuc return 1;
81*4684ddb6SLionel Sambuc break;
82*4684ddb6SLionel Sambuc case NaN:
83*4684ddb6SLionel Sambuc if (classify(r) != NaN)
84*4684ddb6SLionel Sambuc return 1;
85*4684ddb6SLionel Sambuc break;
86*4684ddb6SLionel Sambuc case non_zero_nan:
87*4684ddb6SLionel Sambuc if (classify(r) != NaN)
88*4684ddb6SLionel Sambuc return 1;
89*4684ddb6SLionel Sambuc break;
90*4684ddb6SLionel Sambuc }
91*4684ddb6SLionel Sambuc break;
92*4684ddb6SLionel Sambuc case non_zero:
93*4684ddb6SLionel Sambuc switch (classify(divisor))
94*4684ddb6SLionel Sambuc {
95*4684ddb6SLionel Sambuc case zero:
96*4684ddb6SLionel Sambuc if (classify(r) != zero)
97*4684ddb6SLionel Sambuc return 1;
98*4684ddb6SLionel Sambuc break;
99*4684ddb6SLionel Sambuc case non_zero:
100*4684ddb6SLionel Sambuc if (classify(r) != non_zero)
101*4684ddb6SLionel Sambuc return 1;
102*4684ddb6SLionel Sambuc if (r != a * c - b * d + _Complex_I*(a * d + b * c))
103*4684ddb6SLionel Sambuc return 1;
104*4684ddb6SLionel Sambuc break;
105*4684ddb6SLionel Sambuc case inf:
106*4684ddb6SLionel Sambuc if (classify(r) != inf)
107*4684ddb6SLionel Sambuc return 1;
108*4684ddb6SLionel Sambuc break;
109*4684ddb6SLionel Sambuc case NaN:
110*4684ddb6SLionel Sambuc if (classify(r) != NaN)
111*4684ddb6SLionel Sambuc return 1;
112*4684ddb6SLionel Sambuc break;
113*4684ddb6SLionel Sambuc case non_zero_nan:
114*4684ddb6SLionel Sambuc if (classify(r) != NaN)
115*4684ddb6SLionel Sambuc return 1;
116*4684ddb6SLionel Sambuc break;
117*4684ddb6SLionel Sambuc }
118*4684ddb6SLionel Sambuc break;
119*4684ddb6SLionel Sambuc case inf:
120*4684ddb6SLionel Sambuc switch (classify(divisor))
121*4684ddb6SLionel Sambuc {
122*4684ddb6SLionel Sambuc case zero:
123*4684ddb6SLionel Sambuc if (classify(r) != NaN)
124*4684ddb6SLionel Sambuc return 1;
125*4684ddb6SLionel Sambuc break;
126*4684ddb6SLionel Sambuc case non_zero:
127*4684ddb6SLionel Sambuc if (classify(r) != inf)
128*4684ddb6SLionel Sambuc return 1;
129*4684ddb6SLionel Sambuc break;
130*4684ddb6SLionel Sambuc case inf:
131*4684ddb6SLionel Sambuc if (classify(r) != inf)
132*4684ddb6SLionel Sambuc return 1;
133*4684ddb6SLionel Sambuc break;
134*4684ddb6SLionel Sambuc case NaN:
135*4684ddb6SLionel Sambuc if (classify(r) != NaN)
136*4684ddb6SLionel Sambuc return 1;
137*4684ddb6SLionel Sambuc break;
138*4684ddb6SLionel Sambuc case non_zero_nan:
139*4684ddb6SLionel Sambuc if (classify(r) != inf)
140*4684ddb6SLionel Sambuc return 1;
141*4684ddb6SLionel Sambuc break;
142*4684ddb6SLionel Sambuc }
143*4684ddb6SLionel Sambuc break;
144*4684ddb6SLionel Sambuc case NaN:
145*4684ddb6SLionel Sambuc switch (classify(divisor))
146*4684ddb6SLionel Sambuc {
147*4684ddb6SLionel Sambuc case zero:
148*4684ddb6SLionel Sambuc if (classify(r) != NaN)
149*4684ddb6SLionel Sambuc return 1;
150*4684ddb6SLionel Sambuc break;
151*4684ddb6SLionel Sambuc case non_zero:
152*4684ddb6SLionel Sambuc if (classify(r) != NaN)
153*4684ddb6SLionel Sambuc return 1;
154*4684ddb6SLionel Sambuc break;
155*4684ddb6SLionel Sambuc case inf:
156*4684ddb6SLionel Sambuc if (classify(r) != NaN)
157*4684ddb6SLionel Sambuc return 1;
158*4684ddb6SLionel Sambuc break;
159*4684ddb6SLionel Sambuc case NaN:
160*4684ddb6SLionel Sambuc if (classify(r) != NaN)
161*4684ddb6SLionel Sambuc return 1;
162*4684ddb6SLionel Sambuc break;
163*4684ddb6SLionel Sambuc case non_zero_nan:
164*4684ddb6SLionel Sambuc if (classify(r) != NaN)
165*4684ddb6SLionel Sambuc return 1;
166*4684ddb6SLionel Sambuc break;
167*4684ddb6SLionel Sambuc }
168*4684ddb6SLionel Sambuc break;
169*4684ddb6SLionel Sambuc case non_zero_nan:
170*4684ddb6SLionel Sambuc switch (classify(divisor))
171*4684ddb6SLionel Sambuc {
172*4684ddb6SLionel Sambuc case zero:
173*4684ddb6SLionel Sambuc if (classify(r) != NaN)
174*4684ddb6SLionel Sambuc return 1;
175*4684ddb6SLionel Sambuc break;
176*4684ddb6SLionel Sambuc case non_zero:
177*4684ddb6SLionel Sambuc if (classify(r) != NaN)
178*4684ddb6SLionel Sambuc return 1;
179*4684ddb6SLionel Sambuc break;
180*4684ddb6SLionel Sambuc case inf:
181*4684ddb6SLionel Sambuc if (classify(r) != inf)
182*4684ddb6SLionel Sambuc return 1;
183*4684ddb6SLionel Sambuc break;
184*4684ddb6SLionel Sambuc case NaN:
185*4684ddb6SLionel Sambuc if (classify(r) != NaN)
186*4684ddb6SLionel Sambuc return 1;
187*4684ddb6SLionel Sambuc break;
188*4684ddb6SLionel Sambuc case non_zero_nan:
189*4684ddb6SLionel Sambuc if (classify(r) != NaN)
190*4684ddb6SLionel Sambuc return 1;
191*4684ddb6SLionel Sambuc break;
192*4684ddb6SLionel Sambuc }
193*4684ddb6SLionel Sambuc break;
194*4684ddb6SLionel Sambuc }
195*4684ddb6SLionel Sambuc
196*4684ddb6SLionel Sambuc return 0;
197*4684ddb6SLionel Sambuc }
198*4684ddb6SLionel Sambuc
199*4684ddb6SLionel Sambuc long double x[][2] =
200*4684ddb6SLionel Sambuc {
201*4684ddb6SLionel Sambuc { 1.e-6, 1.e-6},
202*4684ddb6SLionel Sambuc {-1.e-6, 1.e-6},
203*4684ddb6SLionel Sambuc {-1.e-6, -1.e-6},
204*4684ddb6SLionel Sambuc { 1.e-6, -1.e-6},
205*4684ddb6SLionel Sambuc
206*4684ddb6SLionel Sambuc { 1.e+6, 1.e-6},
207*4684ddb6SLionel Sambuc {-1.e+6, 1.e-6},
208*4684ddb6SLionel Sambuc {-1.e+6, -1.e-6},
209*4684ddb6SLionel Sambuc { 1.e+6, -1.e-6},
210*4684ddb6SLionel Sambuc
211*4684ddb6SLionel Sambuc { 1.e-6, 1.e+6},
212*4684ddb6SLionel Sambuc {-1.e-6, 1.e+6},
213*4684ddb6SLionel Sambuc {-1.e-6, -1.e+6},
214*4684ddb6SLionel Sambuc { 1.e-6, -1.e+6},
215*4684ddb6SLionel Sambuc
216*4684ddb6SLionel Sambuc { 1.e+6, 1.e+6},
217*4684ddb6SLionel Sambuc {-1.e+6, 1.e+6},
218*4684ddb6SLionel Sambuc {-1.e+6, -1.e+6},
219*4684ddb6SLionel Sambuc { 1.e+6, -1.e+6},
220*4684ddb6SLionel Sambuc
221*4684ddb6SLionel Sambuc {NAN, NAN},
222*4684ddb6SLionel Sambuc {-INFINITY, NAN},
223*4684ddb6SLionel Sambuc {-2, NAN},
224*4684ddb6SLionel Sambuc {-1, NAN},
225*4684ddb6SLionel Sambuc {-0.5, NAN},
226*4684ddb6SLionel Sambuc {-0., NAN},
227*4684ddb6SLionel Sambuc {+0., NAN},
228*4684ddb6SLionel Sambuc {0.5, NAN},
229*4684ddb6SLionel Sambuc {1, NAN},
230*4684ddb6SLionel Sambuc {2, NAN},
231*4684ddb6SLionel Sambuc {INFINITY, NAN},
232*4684ddb6SLionel Sambuc
233*4684ddb6SLionel Sambuc {NAN, -INFINITY},
234*4684ddb6SLionel Sambuc {-INFINITY, -INFINITY},
235*4684ddb6SLionel Sambuc {-2, -INFINITY},
236*4684ddb6SLionel Sambuc {-1, -INFINITY},
237*4684ddb6SLionel Sambuc {-0.5, -INFINITY},
238*4684ddb6SLionel Sambuc {-0., -INFINITY},
239*4684ddb6SLionel Sambuc {+0., -INFINITY},
240*4684ddb6SLionel Sambuc {0.5, -INFINITY},
241*4684ddb6SLionel Sambuc {1, -INFINITY},
242*4684ddb6SLionel Sambuc {2, -INFINITY},
243*4684ddb6SLionel Sambuc {INFINITY, -INFINITY},
244*4684ddb6SLionel Sambuc
245*4684ddb6SLionel Sambuc {NAN, -2},
246*4684ddb6SLionel Sambuc {-INFINITY, -2},
247*4684ddb6SLionel Sambuc {-2, -2},
248*4684ddb6SLionel Sambuc {-1, -2},
249*4684ddb6SLionel Sambuc {-0.5, -2},
250*4684ddb6SLionel Sambuc {-0., -2},
251*4684ddb6SLionel Sambuc {+0., -2},
252*4684ddb6SLionel Sambuc {0.5, -2},
253*4684ddb6SLionel Sambuc {1, -2},
254*4684ddb6SLionel Sambuc {2, -2},
255*4684ddb6SLionel Sambuc {INFINITY, -2},
256*4684ddb6SLionel Sambuc
257*4684ddb6SLionel Sambuc {NAN, -1},
258*4684ddb6SLionel Sambuc {-INFINITY, -1},
259*4684ddb6SLionel Sambuc {-2, -1},
260*4684ddb6SLionel Sambuc {-1, -1},
261*4684ddb6SLionel Sambuc {-0.5, -1},
262*4684ddb6SLionel Sambuc {-0., -1},
263*4684ddb6SLionel Sambuc {+0., -1},
264*4684ddb6SLionel Sambuc {0.5, -1},
265*4684ddb6SLionel Sambuc {1, -1},
266*4684ddb6SLionel Sambuc {2, -1},
267*4684ddb6SLionel Sambuc {INFINITY, -1},
268*4684ddb6SLionel Sambuc
269*4684ddb6SLionel Sambuc {NAN, -0.5},
270*4684ddb6SLionel Sambuc {-INFINITY, -0.5},
271*4684ddb6SLionel Sambuc {-2, -0.5},
272*4684ddb6SLionel Sambuc {-1, -0.5},
273*4684ddb6SLionel Sambuc {-0.5, -0.5},
274*4684ddb6SLionel Sambuc {-0., -0.5},
275*4684ddb6SLionel Sambuc {+0., -0.5},
276*4684ddb6SLionel Sambuc {0.5, -0.5},
277*4684ddb6SLionel Sambuc {1, -0.5},
278*4684ddb6SLionel Sambuc {2, -0.5},
279*4684ddb6SLionel Sambuc {INFINITY, -0.5},
280*4684ddb6SLionel Sambuc
281*4684ddb6SLionel Sambuc {NAN, -0.},
282*4684ddb6SLionel Sambuc {-INFINITY, -0.},
283*4684ddb6SLionel Sambuc {-2, -0.},
284*4684ddb6SLionel Sambuc {-1, -0.},
285*4684ddb6SLionel Sambuc {-0.5, -0.},
286*4684ddb6SLionel Sambuc {-0., -0.},
287*4684ddb6SLionel Sambuc {+0., -0.},
288*4684ddb6SLionel Sambuc {0.5, -0.},
289*4684ddb6SLionel Sambuc {1, -0.},
290*4684ddb6SLionel Sambuc {2, -0.},
291*4684ddb6SLionel Sambuc {INFINITY, -0.},
292*4684ddb6SLionel Sambuc
293*4684ddb6SLionel Sambuc {NAN, 0.},
294*4684ddb6SLionel Sambuc {-INFINITY, 0.},
295*4684ddb6SLionel Sambuc {-2, 0.},
296*4684ddb6SLionel Sambuc {-1, 0.},
297*4684ddb6SLionel Sambuc {-0.5, 0.},
298*4684ddb6SLionel Sambuc {-0., 0.},
299*4684ddb6SLionel Sambuc {+0., 0.},
300*4684ddb6SLionel Sambuc {0.5, 0.},
301*4684ddb6SLionel Sambuc {1, 0.},
302*4684ddb6SLionel Sambuc {2, 0.},
303*4684ddb6SLionel Sambuc {INFINITY, 0.},
304*4684ddb6SLionel Sambuc
305*4684ddb6SLionel Sambuc {NAN, 0.5},
306*4684ddb6SLionel Sambuc {-INFINITY, 0.5},
307*4684ddb6SLionel Sambuc {-2, 0.5},
308*4684ddb6SLionel Sambuc {-1, 0.5},
309*4684ddb6SLionel Sambuc {-0.5, 0.5},
310*4684ddb6SLionel Sambuc {-0., 0.5},
311*4684ddb6SLionel Sambuc {+0., 0.5},
312*4684ddb6SLionel Sambuc {0.5, 0.5},
313*4684ddb6SLionel Sambuc {1, 0.5},
314*4684ddb6SLionel Sambuc {2, 0.5},
315*4684ddb6SLionel Sambuc {INFINITY, 0.5},
316*4684ddb6SLionel Sambuc
317*4684ddb6SLionel Sambuc {NAN, 1},
318*4684ddb6SLionel Sambuc {-INFINITY, 1},
319*4684ddb6SLionel Sambuc {-2, 1},
320*4684ddb6SLionel Sambuc {-1, 1},
321*4684ddb6SLionel Sambuc {-0.5, 1},
322*4684ddb6SLionel Sambuc {-0., 1},
323*4684ddb6SLionel Sambuc {+0., 1},
324*4684ddb6SLionel Sambuc {0.5, 1},
325*4684ddb6SLionel Sambuc {1, 1},
326*4684ddb6SLionel Sambuc {2, 1},
327*4684ddb6SLionel Sambuc {INFINITY, 1},
328*4684ddb6SLionel Sambuc
329*4684ddb6SLionel Sambuc {NAN, 2},
330*4684ddb6SLionel Sambuc {-INFINITY, 2},
331*4684ddb6SLionel Sambuc {-2, 2},
332*4684ddb6SLionel Sambuc {-1, 2},
333*4684ddb6SLionel Sambuc {-0.5, 2},
334*4684ddb6SLionel Sambuc {-0., 2},
335*4684ddb6SLionel Sambuc {+0., 2},
336*4684ddb6SLionel Sambuc {0.5, 2},
337*4684ddb6SLionel Sambuc {1, 2},
338*4684ddb6SLionel Sambuc {2, 2},
339*4684ddb6SLionel Sambuc {INFINITY, 2},
340*4684ddb6SLionel Sambuc
341*4684ddb6SLionel Sambuc {NAN, INFINITY},
342*4684ddb6SLionel Sambuc {-INFINITY, INFINITY},
343*4684ddb6SLionel Sambuc {-2, INFINITY},
344*4684ddb6SLionel Sambuc {-1, INFINITY},
345*4684ddb6SLionel Sambuc {-0.5, INFINITY},
346*4684ddb6SLionel Sambuc {-0., INFINITY},
347*4684ddb6SLionel Sambuc {+0., INFINITY},
348*4684ddb6SLionel Sambuc {0.5, INFINITY},
349*4684ddb6SLionel Sambuc {1, INFINITY},
350*4684ddb6SLionel Sambuc {2, INFINITY},
351*4684ddb6SLionel Sambuc {INFINITY, INFINITY}
352*4684ddb6SLionel Sambuc
353*4684ddb6SLionel Sambuc };
354*4684ddb6SLionel Sambuc
355*4684ddb6SLionel Sambuc #endif
356*4684ddb6SLionel Sambuc
main()357*4684ddb6SLionel Sambuc int main()
358*4684ddb6SLionel Sambuc {
359*4684ddb6SLionel Sambuc #if _ARCH_PPC
360*4684ddb6SLionel Sambuc const unsigned N = sizeof(x) / sizeof(x[0]);
361*4684ddb6SLionel Sambuc unsigned i, j;
362*4684ddb6SLionel Sambuc for (i = 0; i < N; ++i)
363*4684ddb6SLionel Sambuc {
364*4684ddb6SLionel Sambuc for (j = 0; j < N; ++j)
365*4684ddb6SLionel Sambuc {
366*4684ddb6SLionel Sambuc if (test__multc3(x[i][0], x[i][1], x[j][0], x[j][1]))
367*4684ddb6SLionel Sambuc return 1;
368*4684ddb6SLionel Sambuc }
369*4684ddb6SLionel Sambuc }
370*4684ddb6SLionel Sambuc #else
371*4684ddb6SLionel Sambuc printf("skipped\n");
372*4684ddb6SLionel Sambuc #endif
373*4684ddb6SLionel Sambuc return 0;
374*4684ddb6SLionel Sambuc }
375