[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / divtc3_test.c
blobf8181dafed9dd277c6030fc720a0d08f2ae0ebe7
1 // RUN: %clang_builtins %s %librt -lm -o %t && %run %t
2 // REQUIRES: librt_has_divtc3
3 //
4 // 32-bit: Bug 42493, 64-bit: Bug 42496
5 // XFAIL: sparc
6 //
7 //===-- divtc3_test.c - Test __divtc3 -------------------------------------===//
8 //
9 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10 // See https://llvm.org/LICENSE.txt for license information.
11 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13 //===----------------------------------------------------------------------===//
15 // This file tests __divtc3 for the compiler_rt library.
17 //===----------------------------------------------------------------------===//
19 #include <stdio.h>
21 #include "int_lib.h"
22 #include <math.h>
23 #include <complex.h>
25 // REQUIRES: c99-complex
27 // Returns: the quotient of (a + ib) / (c + id)
29 COMPILER_RT_ABI long double _Complex
30 __divtc3(long double __a, long double __b, long double __c, long double __d);
32 enum {zero, non_zero, inf, NaN, non_zero_nan};
34 int
35 classify(long double _Complex x)
37 if (x == 0)
38 return zero;
39 if (isinf(creall(x)) || isinf(cimagl(x)))
40 return inf;
41 if (isnan(creall(x)) && isnan(cimagl(x)))
42 return NaN;
43 if (isnan(creall(x)))
45 if (cimagl(x) == 0)
46 return NaN;
47 return non_zero_nan;
49 if (isnan(cimagl(x)))
51 if (creall(x) == 0)
52 return NaN;
53 return non_zero_nan;
55 return non_zero;
58 int test__divtc3(long double a, long double b, long double c, long double d)
60 long double _Complex r = __divtc3(a, b, c, d);
61 // printf("test__divtc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n",
62 // a, b, c, d, creall(r), cimagl(r));
64 long double _Complex dividend;
65 long double _Complex divisor;
67 __real__ dividend = a;
68 __imag__ dividend = b;
69 __real__ divisor = c;
70 __imag__ divisor = d;
72 switch (classify(dividend))
74 case zero:
75 switch (classify(divisor))
77 case zero:
78 if (classify(r) != NaN)
79 return 1;
80 break;
81 case non_zero:
82 if (classify(r) != zero)
83 return 1;
84 break;
85 case inf:
86 if (classify(r) != zero)
87 return 1;
88 break;
89 case NaN:
90 if (classify(r) != NaN)
91 return 1;
92 break;
93 case non_zero_nan:
94 if (classify(r) != NaN)
95 return 1;
96 break;
98 break;
99 case non_zero:
100 switch (classify(divisor))
102 case zero:
103 if (classify(r) != inf)
104 return 1;
105 break;
106 case non_zero:
107 if (classify(r) != non_zero)
108 return 1;
110 long double _Complex z = (a * c + b * d) / (c * c + d * d)
111 + (b * c - a * d) / (c * c + d * d) * _Complex_I;
112 if (cabsl((r - z)/r) > 1.e-6)
113 return 1;
115 break;
116 case inf:
117 if (classify(r) != zero)
118 return 1;
119 break;
120 case NaN:
121 if (classify(r) != NaN)
122 return 1;
123 break;
124 case non_zero_nan:
125 if (classify(r) != NaN)
126 return 1;
127 break;
129 break;
130 case inf:
131 switch (classify(divisor))
133 case zero:
134 if (classify(r) != inf)
135 return 1;
136 break;
137 case non_zero:
138 if (classify(r) != inf)
139 return 1;
140 break;
141 case inf:
142 if (classify(r) != NaN)
143 return 1;
144 break;
145 case NaN:
146 if (classify(r) != NaN)
147 return 1;
148 break;
149 case non_zero_nan:
150 if (classify(r) != NaN)
151 return 1;
152 break;
154 break;
155 case NaN:
156 switch (classify(divisor))
158 case zero:
159 if (classify(r) != NaN)
160 return 1;
161 break;
162 case non_zero:
163 if (classify(r) != NaN)
164 return 1;
165 break;
166 case inf:
167 if (classify(r) != NaN)
168 return 1;
169 break;
170 case NaN:
171 if (classify(r) != NaN)
172 return 1;
173 break;
174 case non_zero_nan:
175 if (classify(r) != NaN)
176 return 1;
177 break;
179 break;
180 case non_zero_nan:
181 switch (classify(divisor))
183 case zero:
184 if (classify(r) != inf)
185 return 1;
186 break;
187 case non_zero:
188 if (classify(r) != NaN)
189 return 1;
190 break;
191 case inf:
192 if (classify(r) != NaN)
193 return 1;
194 break;
195 case NaN:
196 if (classify(r) != NaN)
197 return 1;
198 break;
199 case non_zero_nan:
200 if (classify(r) != NaN)
201 return 1;
202 break;
204 break;
207 return 0;
210 long double x[][2] =
212 { 1.e-6, 1.e-6},
213 {-1.e-6, 1.e-6},
214 {-1.e-6, -1.e-6},
215 { 1.e-6, -1.e-6},
217 { 1.e+6, 1.e-6},
218 {-1.e+6, 1.e-6},
219 {-1.e+6, -1.e-6},
220 { 1.e+6, -1.e-6},
222 { 1.e-6, 1.e+6},
223 {-1.e-6, 1.e+6},
224 {-1.e-6, -1.e+6},
225 { 1.e-6, -1.e+6},
227 { 1.e+6, 1.e+6},
228 {-1.e+6, 1.e+6},
229 {-1.e+6, -1.e+6},
230 { 1.e+6, -1.e+6},
232 {NAN, NAN},
233 {-INFINITY, NAN},
234 {-2, NAN},
235 {-1, NAN},
236 {-0.5, NAN},
237 {-0., NAN},
238 {+0., NAN},
239 {0.5, NAN},
240 {1, NAN},
241 {2, NAN},
242 {INFINITY, NAN},
244 {NAN, -INFINITY},
245 {-INFINITY, -INFINITY},
246 {-2, -INFINITY},
247 {-1, -INFINITY},
248 {-0.5, -INFINITY},
249 {-0., -INFINITY},
250 {+0., -INFINITY},
251 {0.5, -INFINITY},
252 {1, -INFINITY},
253 {2, -INFINITY},
254 {INFINITY, -INFINITY},
256 {NAN, -2},
257 {-INFINITY, -2},
258 {-2, -2},
259 {-1, -2},
260 {-0.5, -2},
261 {-0., -2},
262 {+0., -2},
263 {0.5, -2},
264 {1, -2},
265 {2, -2},
266 {INFINITY, -2},
268 {NAN, -1},
269 {-INFINITY, -1},
270 {-2, -1},
271 {-1, -1},
272 {-0.5, -1},
273 {-0., -1},
274 {+0., -1},
275 {0.5, -1},
276 {1, -1},
277 {2, -1},
278 {INFINITY, -1},
280 {NAN, -0.5},
281 {-INFINITY, -0.5},
282 {-2, -0.5},
283 {-1, -0.5},
284 {-0.5, -0.5},
285 {-0., -0.5},
286 {+0., -0.5},
287 {0.5, -0.5},
288 {1, -0.5},
289 {2, -0.5},
290 {INFINITY, -0.5},
292 {NAN, -0.},
293 {-INFINITY, -0.},
294 {-2, -0.},
295 {-1, -0.},
296 {-0.5, -0.},
297 {-0., -0.},
298 {+0., -0.},
299 {0.5, -0.},
300 {1, -0.},
301 {2, -0.},
302 {INFINITY, -0.},
304 {NAN, 0.},
305 {-INFINITY, 0.},
306 {-2, 0.},
307 {-1, 0.},
308 {-0.5, 0.},
309 {-0., 0.},
310 {+0., 0.},
311 {0.5, 0.},
312 {1, 0.},
313 {2, 0.},
314 {INFINITY, 0.},
316 {NAN, 0.5},
317 {-INFINITY, 0.5},
318 {-2, 0.5},
319 {-1, 0.5},
320 {-0.5, 0.5},
321 {-0., 0.5},
322 {+0., 0.5},
323 {0.5, 0.5},
324 {1, 0.5},
325 {2, 0.5},
326 {INFINITY, 0.5},
328 {NAN, 1},
329 {-INFINITY, 1},
330 {-2, 1},
331 {-1, 1},
332 {-0.5, 1},
333 {-0., 1},
334 {+0., 1},
335 {0.5, 1},
336 {1, 1},
337 {2, 1},
338 {INFINITY, 1},
340 {NAN, 2},
341 {-INFINITY, 2},
342 {-2, 2},
343 {-1, 2},
344 {-0.5, 2},
345 {-0., 2},
346 {+0., 2},
347 {0.5, 2},
348 {1, 2},
349 {2, 2},
350 {INFINITY, 2},
352 {NAN, INFINITY},
353 {-INFINITY, INFINITY},
354 {-2, INFINITY},
355 {-1, INFINITY},
356 {-0.5, INFINITY},
357 {-0., INFINITY},
358 {+0., INFINITY},
359 {0.5, INFINITY},
360 {1, INFINITY},
361 {2, INFINITY},
362 {INFINITY, INFINITY}
366 int main()
368 const unsigned N = sizeof(x) / sizeof(x[0]);
369 unsigned i, j;
370 for (i = 0; i < N; ++i)
372 for (j = 0; j < N; ++j)
374 if (test__divtc3(x[i][0], x[i][1], x[j][0], x[j][1]))
375 return 1;
379 // printf("No errors found.\n");
380 return 0;