]> git.ipfire.org Git - thirdparty/glibc.git/blame - math/test-tgmath2.c
Fix trailing space.
[thirdparty/glibc.git] / math / test-tgmath2.c
CommitLineData
1c298d08 1/* Test compilation of tgmath macros.
b168057a 2 Copyright (C) 2007-2015 Free Software Foundation, Inc.
1c298d08
UD
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2007.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
1c298d08
UD
19
20#ifndef HAVE_MAIN
21#undef __NO_MATH_INLINES
22#define __NO_MATH_INLINES 1
23#include <math.h>
24#include <complex.h>
25#include <stdio.h>
26#include <string.h>
27#include <tgmath.h>
28
29//#define DEBUG
30
31typedef complex float cfloat;
32typedef complex double cdouble;
33#ifndef NO_LONG_DOUBLE
34typedef long double ldouble;
35typedef complex long double cldouble;
36#else
37typedef double ldouble;
38typedef complex double cldouble;
39#endif
40
41float vfloat1, vfloat2, vfloat3;
42double vdouble1, vdouble2, vdouble3;
43ldouble vldouble1, vldouble2, vldouble3;
44cfloat vcfloat1, vcfloat2, vcfloat3;
45cdouble vcdouble1, vcdouble2, vcdouble3;
46cldouble vcldouble1, vcldouble2, vcldouble4;
47int vint1, vint2, vint3;
48long int vlong1, vlong2, vlong3;
49long long int vllong1, vllong2, vllong3;
50const float Vfloat1 = 1, Vfloat2 = 2, Vfloat3 = 3;
51const double Vdouble1 = 1, Vdouble2 = 2, Vdouble3 = 3;
52const ldouble Vldouble1 = 1, Vldouble2 = 2, Vldouble3 = 3;
53const cfloat Vcfloat1 = 1, Vcfloat2 = 2, Vcfloat3 = 3;
54const cdouble Vcdouble1 = 1, Vcdouble2 = 2, Vcdouble3 = 3;
55const cldouble Vcldouble1 = 1, Vcldouble2 = 2, Vcldouble4 = 3;
56const int Vint1 = 1, Vint2 = 2, Vint3 = 3;
57const long int Vlong1 = 1, Vlong2 = 2, Vlong3 = 3;
58const long long int Vllong1 = 1, Vllong2 = 2, Vllong3 = 3;
59enum
60 {
61 Tfloat = 0,
62 Tcfloat,
63 Tdouble,
64 Tcdouble,
65#ifndef NO_LONG_DOUBLE
66 Tldouble,
67 Tcldouble,
68#else
69 Tldouble = Tdouble,
70 Tcldouble = Tcdouble,
71#endif
72 Tlast
73 };
74enum
75 {
76 C_cos = 0,
77 C_fabs,
78 C_cabs,
79 C_conj,
80 C_expm1,
81 C_lrint,
82 C_ldexp,
83 C_atan2,
84 C_remquo,
85 C_pow,
86 C_fma,
87 C_last
88 };
89int count;
90int counts[Tlast][C_last];
91
92int
93test (const int Vint4, const long long int Vllong4)
94{
95 int result = 0;
96 int quo = 0;
97
98#define FAIL(str) \
99 do \
100 { \
101 printf ("%s failure on line %d\n", (str), __LINE__); \
102 result = 1; \
103 } \
104 while (0)
105#define TEST_TYPE_ONLY(expr, rettype) \
106 do \
107 { \
108 __typeof__ (expr) texpr = 0; \
109 __typeof__ (rettype) ttype = 0, *ptype; \
110 if (sizeof (expr) != sizeof (rettype)) \
111 FAIL ("type"); \
112 if (__alignof__ (expr) != __alignof__ (rettype)) \
113 FAIL ("type"); \
114 __asm ("" : "=r" (ptype) : "0" (&ttype), "r" (&texpr)); \
115 if (&texpr == ptype) \
116 FAIL ("type"); \
117 } \
118 while (0)
119#define TEST2(expr, type, rettype, fn) \
120 do \
121 { \
122 __typeof__ (expr) texpr = 0; \
123 TEST_TYPE_ONLY (expr, rettype); \
124 if (count != 0) \
125 FAIL ("internal error"); \
126 if (counts[T##type][C_##fn] != 0) \
127 FAIL ("internal error"); \
128 texpr = expr; \
129 __asm __volatile ("" : : "r" (&texpr)); \
130 if (count != 1 || counts[T##type][C_##fn] != 1) \
131 { \
132 FAIL ("wrong function called"); \
133 memset (counts, 0, sizeof (counts)); \
134 } \
135 count = 0; \
136 counts[T##type][C_##fn] = 0; \
137 } \
138 while (0)
139#define TEST(expr, type, fn) TEST2(expr, type, type, fn)
140
141 TEST (cos (vfloat1), float, cos);
142 TEST (cos (vdouble1), double, cos);
143 TEST (cos (vldouble1), ldouble, cos);
144 TEST (cos (vint1), double, cos);
145 TEST (cos (vllong1), double, cos);
146 TEST (cos (vcfloat1), cfloat, cos);
147 TEST (cos (vcdouble1), cdouble, cos);
148 TEST (cos (vcldouble1), cldouble, cos);
149 TEST (cos (Vfloat1), float, cos);
150 TEST (cos (Vdouble1), double, cos);
151 TEST (cos (Vldouble1), ldouble, cos);
152 TEST (cos (Vint1), double, cos);
153 TEST (cos (Vllong1), double, cos);
154 TEST (cos (Vcfloat1), cfloat, cos);
155 TEST (cos (Vcdouble1), cdouble, cos);
156 TEST (cos (Vcldouble1), cldouble, cos);
157
158 TEST (fabs (vfloat1), float, fabs);
159 TEST (fabs (vdouble1), double, fabs);
160 TEST (fabs (vldouble1), ldouble, fabs);
161 TEST (fabs (vint1), double, fabs);
162 TEST (fabs (vllong1), double, fabs);
163 TEST (fabs (vcfloat1), float, cabs);
164 TEST (fabs (vcdouble1), double, cabs);
165 TEST (fabs (vcldouble1), ldouble, cabs);
166 TEST (fabs (Vfloat1), float, fabs);
167 TEST (fabs (Vdouble1), double, fabs);
168 TEST (fabs (Vldouble1), ldouble, fabs);
169#ifndef __OPTIMIZE__
170 /* GCC is too smart to optimize these out. */
171 TEST (fabs (Vint1), double, fabs);
172 TEST (fabs (Vllong1), double, fabs);
173#else
174 TEST_TYPE_ONLY (fabs (vllong1), double);
175 TEST_TYPE_ONLY (fabs (vllong1), double);
176#endif
177 TEST (fabs (Vint4), double, fabs);
178 TEST (fabs (Vllong4), double, fabs);
179 TEST (fabs (Vcfloat1), float, cabs);
180 TEST (fabs (Vcdouble1), double, cabs);
181 TEST (fabs (Vcldouble1), ldouble, cabs);
182
183 TEST (conj (vfloat1), cfloat, conj);
184 TEST (conj (vdouble1), cdouble, conj);
185 TEST (conj (vldouble1), cldouble, conj);
186 TEST (conj (vint1), cdouble, conj);
187 TEST (conj (vllong1), cdouble, conj);
188 TEST (conj (vcfloat1), cfloat, conj);
189 TEST (conj (vcdouble1), cdouble, conj);
190 TEST (conj (vcldouble1), cldouble, conj);
191 TEST (conj (Vfloat1), cfloat, conj);
192 TEST (conj (Vdouble1), cdouble, conj);
193 TEST (conj (Vldouble1), cldouble, conj);
194 TEST (conj (Vint1), cdouble, conj);
195 TEST (conj (Vllong1), cdouble, conj);
196 TEST (conj (Vcfloat1), cfloat, conj);
197 TEST (conj (Vcdouble1), cdouble, conj);
198 TEST (conj (Vcldouble1), cldouble, conj);
199
200 TEST (expm1 (vfloat1), float, expm1);
201 TEST (expm1 (vdouble1), double, expm1);
202 TEST (expm1 (vldouble1), ldouble, expm1);
203 TEST (expm1 (vint1), double, expm1);
204 TEST (expm1 (vllong1), double, expm1);
205 TEST (expm1 (Vfloat1), float, expm1);
206 TEST (expm1 (Vdouble1), double, expm1);
207 TEST (expm1 (Vldouble1), ldouble, expm1);
208 TEST (expm1 (Vint1), double, expm1);
209 TEST (expm1 (Vllong1), double, expm1);
210
211 TEST2 (lrint (vfloat1), float, long int, lrint);
212 TEST2 (lrint (vdouble1), double, long int, lrint);
213 TEST2 (lrint (vldouble1), ldouble, long int, lrint);
214 TEST2 (lrint (vint1), double, long int, lrint);
215 TEST2 (lrint (vllong1), double, long int, lrint);
216 TEST2 (lrint (Vfloat1), float, long int, lrint);
217 TEST2 (lrint (Vdouble1), double, long int, lrint);
218 TEST2 (lrint (Vldouble1), ldouble, long int, lrint);
219 TEST2 (lrint (Vint1), double, long int, lrint);
220 TEST2 (lrint (Vllong1), double, long int, lrint);
221
222 TEST (ldexp (vfloat1, 6), float, ldexp);
223 TEST (ldexp (vdouble1, 6), double, ldexp);
224 TEST (ldexp (vldouble1, 6), ldouble, ldexp);
225 TEST (ldexp (vint1, 6), double, ldexp);
226 TEST (ldexp (vllong1, 6), double, ldexp);
227 TEST (ldexp (Vfloat1, 6), float, ldexp);
228 TEST (ldexp (Vdouble1, 6), double, ldexp);
229 TEST (ldexp (Vldouble1, 6), ldouble, ldexp);
230 TEST (ldexp (Vint1, 6), double, ldexp);
231 TEST (ldexp (Vllong1, 6), double, ldexp);
232
233#define FIRST(x, y) (y, x)
234#define SECOND(x, y) (x, y)
235#define NON_LDBL_TEST(fn, argm, arg, type, fnt) \
236 TEST (fn argm (arg, vfloat1), type, fnt); \
237 TEST (fn argm (arg, vdouble1), type, fnt); \
238 TEST (fn argm (arg, vint1), type, fnt); \
239 TEST (fn argm (arg, vllong1), type, fnt); \
240 TEST (fn argm (arg, Vfloat1), type, fnt); \
241 TEST (fn argm (arg, Vdouble1), type, fnt); \
242 TEST (fn argm (arg, Vint1), type, fnt); \
243 TEST (fn argm (arg, Vllong1), type, fnt);
244#define NON_LDBL_CTEST(fn, argm, arg, type, fnt) \
245 NON_LDBL_TEST(fn, argm, arg, type, fnt); \
246 TEST (fn argm (arg, vcfloat1), type, fnt); \
247 TEST (fn argm (arg, vcdouble1), type, fnt); \
248 TEST (fn argm (arg, Vcfloat1), type, fnt); \
249 TEST (fn argm (arg, Vcdouble1), type, fnt);
250#define BINARY_TEST(fn, fnt) \
251 TEST (fn (vfloat1, vfloat2), float, fnt); \
252 TEST (fn (Vfloat1, vfloat2), float, fnt); \
253 TEST (fn (vfloat1, Vfloat2), float, fnt); \
254 TEST (fn (Vfloat1, Vfloat2), float, fnt); \
255 TEST (fn (vldouble1, vldouble2), ldouble, fnt); \
256 TEST (fn (Vldouble1, vldouble2), ldouble, fnt); \
257 TEST (fn (vldouble1, Vldouble2), ldouble, fnt); \
258 TEST (fn (Vldouble1, Vldouble2), ldouble, fnt); \
259 NON_LDBL_TEST (fn, FIRST, vldouble2, ldouble, fnt); \
260 NON_LDBL_TEST (fn, SECOND, vldouble2, ldouble, fnt); \
261 NON_LDBL_TEST (fn, FIRST, Vldouble2, ldouble, fnt); \
262 NON_LDBL_TEST (fn, SECOND, Vldouble2, ldouble, fnt); \
263 NON_LDBL_TEST (fn, FIRST, vdouble2, double, fnt); \
264 NON_LDBL_TEST (fn, SECOND, vdouble2, double, fnt); \
265 NON_LDBL_TEST (fn, FIRST, Vdouble2, double, fnt); \
266 NON_LDBL_TEST (fn, SECOND, Vdouble2, double, fnt); \
267 NON_LDBL_TEST (fn, FIRST, vint2, double, fnt); \
268 NON_LDBL_TEST (fn, SECOND, vint2, double, fnt); \
269 NON_LDBL_TEST (fn, FIRST, Vint2, double, fnt); \
270 NON_LDBL_TEST (fn, SECOND, Vint2, double, fnt); \
271 NON_LDBL_TEST (fn, FIRST, vllong2, double, fnt); \
272 NON_LDBL_TEST (fn, SECOND, vllong2, double, fnt); \
273 NON_LDBL_TEST (fn, FIRST, Vllong2, double, fnt); \
274 NON_LDBL_TEST (fn, SECOND, Vllong2, double, fnt);
275#define BINARY_CTEST(fn, fnt) \
276 BINARY_TEST (fn, fnt); \
277 TEST (fn (vcfloat1, vfloat2), cfloat, fnt); \
278 TEST (fn (Vcfloat1, vfloat2), cfloat, fnt); \
279 TEST (fn (vcfloat1, Vfloat2), cfloat, fnt); \
280 TEST (fn (Vcfloat1, Vfloat2), cfloat, fnt); \
281 TEST (fn (vcldouble1, vldouble2), cldouble, fnt); \
282 TEST (fn (Vcldouble1, vldouble2), cldouble, fnt); \
283 TEST (fn (vcldouble1, Vldouble2), cldouble, fnt); \
284 TEST (fn (Vcldouble1, Vldouble2), cldouble, fnt); \
285 TEST (fn (vcfloat1, vfloat2), cfloat, fnt); \
286 TEST (fn (Vcfloat1, vfloat2), cfloat, fnt); \
287 TEST (fn (vcfloat1, Vfloat2), cfloat, fnt); \
288 TEST (fn (Vcfloat1, Vfloat2), cfloat, fnt); \
289 TEST (fn (vcldouble1, vldouble2), cldouble, fnt); \
290 TEST (fn (Vcldouble1, vldouble2), cldouble, fnt); \
291 TEST (fn (vcldouble1, Vldouble2), cldouble, fnt); \
292 TEST (fn (Vcldouble1, Vldouble2), cldouble, fnt); \
293 TEST (fn (vcfloat1, vcfloat2), cfloat, fnt); \
294 TEST (fn (Vcfloat1, vcfloat2), cfloat, fnt); \
295 TEST (fn (vcfloat1, Vcfloat2), cfloat, fnt); \
296 TEST (fn (Vcfloat1, Vcfloat2), cfloat, fnt); \
297 TEST (fn (vcldouble1, vcldouble2), cldouble, fnt); \
298 TEST (fn (Vcldouble1, vcldouble2), cldouble, fnt); \
299 TEST (fn (vcldouble1, Vcldouble2), cldouble, fnt); \
300 TEST (fn (Vcldouble1, Vcldouble2), cldouble, fnt); \
301 NON_LDBL_CTEST (fn, FIRST, vcldouble2, cldouble, fnt); \
302 NON_LDBL_CTEST (fn, SECOND, vcldouble2, cldouble, fnt); \
303 NON_LDBL_CTEST (fn, FIRST, Vcldouble2, cldouble, fnt); \
304 NON_LDBL_CTEST (fn, SECOND, Vcldouble2, cldouble, fnt); \
305 NON_LDBL_CTEST (fn, FIRST, vcdouble2, cdouble, fnt); \
306 NON_LDBL_CTEST (fn, SECOND, vcdouble2, cdouble, fnt); \
307 NON_LDBL_CTEST (fn, FIRST, Vcdouble2, cdouble, fnt); \
308 NON_LDBL_CTEST (fn, SECOND, Vcdouble2, cdouble, fnt);
309
310 BINARY_TEST (atan2, atan2);
311
312#define my_remquo(x, y) remquo (x, y, &quo)
313 BINARY_TEST (my_remquo, remquo);
314#undef my_remquo
315
316 BINARY_CTEST (pow, pow);
317
318 /* Testing all arguments of fma would be just too expensive,
319 so test just some. */
320#define my_fma(x, y) fma (x, y, vfloat3)
321 BINARY_TEST (my_fma, fma);
322#undef my_fma
323#define my_fma(x, y) fma (x, vfloat3, y)
324 BINARY_TEST (my_fma, fma);
325#undef my_fma
326#define my_fma(x, y) fma (Vfloat3, x, y)
327 BINARY_TEST (my_fma, fma);
328#undef my_fma
329 TEST (fma (vdouble1, Vdouble2, vllong3), double, fma);
330 TEST (fma (vint1, Vint2, vint3), double, fma);
331 TEST (fma (Vldouble1, vldouble2, Vldouble3), ldouble, fma);
332 TEST (fma (vldouble1, vint2, Vdouble3), ldouble, fma);
333
334 return result;
335}
336
0035851c
AS
337static int
338do_test (void)
1c298d08
UD
339{
340 return test (vint1, vllong1);
341}
342
343/* Now generate the three functions. */
344#define HAVE_MAIN
345
346#define F(name) name
347#define TYPE double
348#define CTYPE cdouble
349#define T Tdouble
350#define C Tcdouble
351#include "test-tgmath2.c"
352
353#define F(name) name##f
354#define TYPE float
355#define CTYPE cfloat
356#define T Tfloat
357#define C Tcfloat
358#include "test-tgmath2.c"
359
360#ifndef NO_LONG_DOUBLE
361#define F(name) name##l
362#define TYPE ldouble
363#define CTYPE cldouble
364#define T Tldouble
365#define C Tcldouble
366#include "test-tgmath2.c"
367#endif
368
0035851c
AS
369#define TEST_FUNCTION do_test ()
370#include "../test-skeleton.c"
371
1c298d08
UD
372#else
373
374#ifdef DEBUG
375#define P() puts (__FUNCTION__); count++
376#else
377#define P() count++;
378#endif
379
380TYPE
381(F(cos)) (TYPE x)
382{
383 counts[T][C_cos]++;
384 P ();
385 return x;
386}
387
388CTYPE
389(F(ccos)) (CTYPE x)
390{
391 counts[C][C_cos]++;
392 P ();
393 return x;
394}
395
396TYPE
397(F(fabs)) (TYPE x)
398{
399 counts[T][C_fabs]++;
400 P ();
401 return x;
402}
403
404TYPE
405(F(cabs)) (CTYPE x)
406{
407 counts[T][C_cabs]++;
408 P ();
409 return x;
410}
411
412CTYPE
413(F(conj)) (CTYPE x)
414{
415 counts[C][C_conj]++;
416 P ();
417 return x;
418}
419
420TYPE
421(F(expm1)) (TYPE x)
422{
423 counts[T][C_expm1]++;
424 P ();
425 return x;
426}
427
428long int
429(F(lrint)) (TYPE x)
430{
431 counts[T][C_lrint]++;
432 P ();
433 return x;
434}
435
436TYPE
437(F(ldexp)) (TYPE x, int y)
438{
439 counts[T][C_ldexp]++;
440 P ();
441 return x + y;
442}
443
444TYPE
445(F(atan2)) (TYPE x, TYPE y)
446{
447 counts[T][C_atan2]++;
448 P ();
449 return x + y;
450}
451
452TYPE
453(F(remquo)) (TYPE x, TYPE y, int *z)
454{
455 counts[T][C_remquo]++;
456 P ();
457 return x + y + *z;
458}
459
460TYPE
461(F(pow)) (TYPE x, TYPE y)
462{
463 counts[T][C_pow]++;
464 P ();
465 return x + y;
466}
467
468CTYPE
469(F(cpow)) (CTYPE x, CTYPE y)
470{
471 counts[C][C_pow]++;
472 P ();
473 return x + y;
474}
475
476TYPE
477(F(fma)) (TYPE x, TYPE y, TYPE z)
478{
479 counts[T][C_fma]++;
480 P ();
481 return x + y + z;
482}
483
484#undef F
485#undef TYPE
486#undef CTYPE
487#undef T
488#undef C
489#undef P
490#endif