Use O_CLOEXEC in tzfile handling
[glibc.git] / math / test-tgmath2.c
blobedb723c95ec3ff73b21ff2ea021d3d1e40c11f59
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2007 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2007.
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef HAVE_MAIN
22 #undef __NO_MATH_INLINES
23 #define __NO_MATH_INLINES 1
24 #include <math.h>
25 #include <complex.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <tgmath.h>
30 //#define DEBUG
32 typedef complex float cfloat;
33 typedef complex double cdouble;
34 #ifndef NO_LONG_DOUBLE
35 typedef long double ldouble;
36 typedef complex long double cldouble;
37 #else
38 typedef double ldouble;
39 typedef complex double cldouble;
40 #endif
42 float vfloat1, vfloat2, vfloat3;
43 double vdouble1, vdouble2, vdouble3;
44 ldouble vldouble1, vldouble2, vldouble3;
45 cfloat vcfloat1, vcfloat2, vcfloat3;
46 cdouble vcdouble1, vcdouble2, vcdouble3;
47 cldouble vcldouble1, vcldouble2, vcldouble4;
48 int vint1, vint2, vint3;
49 long int vlong1, vlong2, vlong3;
50 long long int vllong1, vllong2, vllong3;
51 const float Vfloat1 = 1, Vfloat2 = 2, Vfloat3 = 3;
52 const double Vdouble1 = 1, Vdouble2 = 2, Vdouble3 = 3;
53 const ldouble Vldouble1 = 1, Vldouble2 = 2, Vldouble3 = 3;
54 const cfloat Vcfloat1 = 1, Vcfloat2 = 2, Vcfloat3 = 3;
55 const cdouble Vcdouble1 = 1, Vcdouble2 = 2, Vcdouble3 = 3;
56 const cldouble Vcldouble1 = 1, Vcldouble2 = 2, Vcldouble4 = 3;
57 const int Vint1 = 1, Vint2 = 2, Vint3 = 3;
58 const long int Vlong1 = 1, Vlong2 = 2, Vlong3 = 3;
59 const long long int Vllong1 = 1, Vllong2 = 2, Vllong3 = 3;
60 enum
62 Tfloat = 0,
63 Tcfloat,
64 Tdouble,
65 Tcdouble,
66 #ifndef NO_LONG_DOUBLE
67 Tldouble,
68 Tcldouble,
69 #else
70 Tldouble = Tdouble,
71 Tcldouble = Tcdouble,
72 #endif
73 Tlast
75 enum
77 C_cos = 0,
78 C_fabs,
79 C_cabs,
80 C_conj,
81 C_expm1,
82 C_lrint,
83 C_ldexp,
84 C_atan2,
85 C_remquo,
86 C_pow,
87 C_fma,
88 C_last
90 int count;
91 int counts[Tlast][C_last];
93 int
94 test (const int Vint4, const long long int Vllong4)
96 int result = 0;
97 int quo = 0;
99 #define FAIL(str) \
100 do \
102 printf ("%s failure on line %d\n", (str), __LINE__); \
103 result = 1; \
105 while (0)
106 #define TEST_TYPE_ONLY(expr, rettype) \
107 do \
109 __typeof__ (expr) texpr = 0; \
110 __typeof__ (rettype) ttype = 0, *ptype; \
111 if (sizeof (expr) != sizeof (rettype)) \
112 FAIL ("type"); \
113 if (__alignof__ (expr) != __alignof__ (rettype)) \
114 FAIL ("type"); \
115 __asm ("" : "=r" (ptype) : "0" (&ttype), "r" (&texpr)); \
116 if (&texpr == ptype) \
117 FAIL ("type"); \
119 while (0)
120 #define TEST2(expr, type, rettype, fn) \
121 do \
123 __typeof__ (expr) texpr = 0; \
124 TEST_TYPE_ONLY (expr, rettype); \
125 if (count != 0) \
126 FAIL ("internal error"); \
127 if (counts[T##type][C_##fn] != 0) \
128 FAIL ("internal error"); \
129 texpr = expr; \
130 __asm __volatile ("" : : "r" (&texpr)); \
131 if (count != 1 || counts[T##type][C_##fn] != 1) \
133 FAIL ("wrong function called"); \
134 memset (counts, 0, sizeof (counts)); \
136 count = 0; \
137 counts[T##type][C_##fn] = 0; \
139 while (0)
140 #define TEST(expr, type, fn) TEST2(expr, type, type, fn)
142 TEST (cos (vfloat1), float, cos);
143 TEST (cos (vdouble1), double, cos);
144 TEST (cos (vldouble1), ldouble, cos);
145 TEST (cos (vint1), double, cos);
146 TEST (cos (vllong1), double, cos);
147 TEST (cos (vcfloat1), cfloat, cos);
148 TEST (cos (vcdouble1), cdouble, cos);
149 TEST (cos (vcldouble1), cldouble, cos);
150 TEST (cos (Vfloat1), float, cos);
151 TEST (cos (Vdouble1), double, cos);
152 TEST (cos (Vldouble1), ldouble, cos);
153 TEST (cos (Vint1), double, cos);
154 TEST (cos (Vllong1), double, cos);
155 TEST (cos (Vcfloat1), cfloat, cos);
156 TEST (cos (Vcdouble1), cdouble, cos);
157 TEST (cos (Vcldouble1), cldouble, cos);
159 TEST (fabs (vfloat1), float, fabs);
160 TEST (fabs (vdouble1), double, fabs);
161 TEST (fabs (vldouble1), ldouble, fabs);
162 TEST (fabs (vint1), double, fabs);
163 TEST (fabs (vllong1), double, fabs);
164 TEST (fabs (vcfloat1), float, cabs);
165 TEST (fabs (vcdouble1), double, cabs);
166 TEST (fabs (vcldouble1), ldouble, cabs);
167 TEST (fabs (Vfloat1), float, fabs);
168 TEST (fabs (Vdouble1), double, fabs);
169 TEST (fabs (Vldouble1), ldouble, fabs);
170 #ifndef __OPTIMIZE__
171 /* GCC is too smart to optimize these out. */
172 TEST (fabs (Vint1), double, fabs);
173 TEST (fabs (Vllong1), double, fabs);
174 #else
175 TEST_TYPE_ONLY (fabs (vllong1), double);
176 TEST_TYPE_ONLY (fabs (vllong1), double);
177 #endif
178 TEST (fabs (Vint4), double, fabs);
179 TEST (fabs (Vllong4), double, fabs);
180 TEST (fabs (Vcfloat1), float, cabs);
181 TEST (fabs (Vcdouble1), double, cabs);
182 TEST (fabs (Vcldouble1), ldouble, cabs);
184 TEST (conj (vfloat1), cfloat, conj);
185 TEST (conj (vdouble1), cdouble, conj);
186 TEST (conj (vldouble1), cldouble, conj);
187 TEST (conj (vint1), cdouble, conj);
188 TEST (conj (vllong1), cdouble, conj);
189 TEST (conj (vcfloat1), cfloat, conj);
190 TEST (conj (vcdouble1), cdouble, conj);
191 TEST (conj (vcldouble1), cldouble, conj);
192 TEST (conj (Vfloat1), cfloat, conj);
193 TEST (conj (Vdouble1), cdouble, conj);
194 TEST (conj (Vldouble1), cldouble, conj);
195 TEST (conj (Vint1), cdouble, conj);
196 TEST (conj (Vllong1), cdouble, conj);
197 TEST (conj (Vcfloat1), cfloat, conj);
198 TEST (conj (Vcdouble1), cdouble, conj);
199 TEST (conj (Vcldouble1), cldouble, conj);
201 TEST (expm1 (vfloat1), float, expm1);
202 TEST (expm1 (vdouble1), double, expm1);
203 TEST (expm1 (vldouble1), ldouble, expm1);
204 TEST (expm1 (vint1), double, expm1);
205 TEST (expm1 (vllong1), double, expm1);
206 TEST (expm1 (Vfloat1), float, expm1);
207 TEST (expm1 (Vdouble1), double, expm1);
208 TEST (expm1 (Vldouble1), ldouble, expm1);
209 TEST (expm1 (Vint1), double, expm1);
210 TEST (expm1 (Vllong1), double, expm1);
212 TEST2 (lrint (vfloat1), float, long int, lrint);
213 TEST2 (lrint (vdouble1), double, long int, lrint);
214 TEST2 (lrint (vldouble1), ldouble, long int, lrint);
215 TEST2 (lrint (vint1), double, long int, lrint);
216 TEST2 (lrint (vllong1), double, long int, lrint);
217 TEST2 (lrint (Vfloat1), float, long int, lrint);
218 TEST2 (lrint (Vdouble1), double, long int, lrint);
219 TEST2 (lrint (Vldouble1), ldouble, long int, lrint);
220 TEST2 (lrint (Vint1), double, long int, lrint);
221 TEST2 (lrint (Vllong1), double, long int, lrint);
223 TEST (ldexp (vfloat1, 6), float, ldexp);
224 TEST (ldexp (vdouble1, 6), double, ldexp);
225 TEST (ldexp (vldouble1, 6), ldouble, ldexp);
226 TEST (ldexp (vint1, 6), double, ldexp);
227 TEST (ldexp (vllong1, 6), double, ldexp);
228 TEST (ldexp (Vfloat1, 6), float, ldexp);
229 TEST (ldexp (Vdouble1, 6), double, ldexp);
230 TEST (ldexp (Vldouble1, 6), ldouble, ldexp);
231 TEST (ldexp (Vint1, 6), double, ldexp);
232 TEST (ldexp (Vllong1, 6), double, ldexp);
234 #define FIRST(x, y) (y, x)
235 #define SECOND(x, y) (x, y)
236 #define NON_LDBL_TEST(fn, argm, arg, type, fnt) \
237 TEST (fn argm (arg, vfloat1), type, fnt); \
238 TEST (fn argm (arg, vdouble1), type, fnt); \
239 TEST (fn argm (arg, vint1), type, fnt); \
240 TEST (fn argm (arg, vllong1), type, fnt); \
241 TEST (fn argm (arg, Vfloat1), type, fnt); \
242 TEST (fn argm (arg, Vdouble1), type, fnt); \
243 TEST (fn argm (arg, Vint1), type, fnt); \
244 TEST (fn argm (arg, Vllong1), type, fnt);
245 #define NON_LDBL_CTEST(fn, argm, arg, type, fnt) \
246 NON_LDBL_TEST(fn, argm, arg, type, fnt); \
247 TEST (fn argm (arg, vcfloat1), type, fnt); \
248 TEST (fn argm (arg, vcdouble1), type, fnt); \
249 TEST (fn argm (arg, Vcfloat1), type, fnt); \
250 TEST (fn argm (arg, Vcdouble1), type, fnt);
251 #define BINARY_TEST(fn, 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 (Vfloat1, Vfloat2), float, fnt); \
256 TEST (fn (vldouble1, vldouble2), ldouble, fnt); \
257 TEST (fn (Vldouble1, vldouble2), ldouble, fnt); \
258 TEST (fn (vldouble1, Vldouble2), ldouble, fnt); \
259 TEST (fn (Vldouble1, Vldouble2), ldouble, fnt); \
260 NON_LDBL_TEST (fn, FIRST, vldouble2, ldouble, fnt); \
261 NON_LDBL_TEST (fn, SECOND, vldouble2, ldouble, fnt); \
262 NON_LDBL_TEST (fn, FIRST, Vldouble2, ldouble, fnt); \
263 NON_LDBL_TEST (fn, SECOND, Vldouble2, ldouble, fnt); \
264 NON_LDBL_TEST (fn, FIRST, vdouble2, double, fnt); \
265 NON_LDBL_TEST (fn, SECOND, vdouble2, double, fnt); \
266 NON_LDBL_TEST (fn, FIRST, Vdouble2, double, fnt); \
267 NON_LDBL_TEST (fn, SECOND, Vdouble2, double, fnt); \
268 NON_LDBL_TEST (fn, FIRST, vint2, double, fnt); \
269 NON_LDBL_TEST (fn, SECOND, vint2, double, fnt); \
270 NON_LDBL_TEST (fn, FIRST, Vint2, double, fnt); \
271 NON_LDBL_TEST (fn, SECOND, Vint2, double, fnt); \
272 NON_LDBL_TEST (fn, FIRST, vllong2, double, fnt); \
273 NON_LDBL_TEST (fn, SECOND, vllong2, double, fnt); \
274 NON_LDBL_TEST (fn, FIRST, Vllong2, double, fnt); \
275 NON_LDBL_TEST (fn, SECOND, Vllong2, double, fnt);
276 #define BINARY_CTEST(fn, fnt) \
277 BINARY_TEST (fn, 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 (Vcfloat1, Vfloat2), cfloat, 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 (Vcldouble1, Vldouble2), cldouble, 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 (Vcfloat1, Vfloat2), cfloat, 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 (Vcldouble1, Vldouble2), cldouble, 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 (Vcfloat1, Vcfloat2), cfloat, fnt); \
298 TEST (fn (vcldouble1, vcldouble2), cldouble, fnt); \
299 TEST (fn (Vcldouble1, vcldouble2), cldouble, fnt); \
300 TEST (fn (vcldouble1, Vcldouble2), cldouble, fnt); \
301 TEST (fn (Vcldouble1, Vcldouble2), cldouble, fnt); \
302 NON_LDBL_CTEST (fn, FIRST, vcldouble2, cldouble, fnt); \
303 NON_LDBL_CTEST (fn, SECOND, vcldouble2, cldouble, fnt); \
304 NON_LDBL_CTEST (fn, FIRST, Vcldouble2, cldouble, fnt); \
305 NON_LDBL_CTEST (fn, SECOND, Vcldouble2, cldouble, fnt); \
306 NON_LDBL_CTEST (fn, FIRST, vcdouble2, cdouble, fnt); \
307 NON_LDBL_CTEST (fn, SECOND, vcdouble2, cdouble, fnt); \
308 NON_LDBL_CTEST (fn, FIRST, Vcdouble2, cdouble, fnt); \
309 NON_LDBL_CTEST (fn, SECOND, Vcdouble2, cdouble, fnt);
311 BINARY_TEST (atan2, atan2);
313 #define my_remquo(x, y) remquo (x, y, &quo)
314 BINARY_TEST (my_remquo, remquo);
315 #undef my_remquo
317 BINARY_CTEST (pow, pow);
319 /* Testing all arguments of fma would be just too expensive,
320 so test just some. */
321 #define my_fma(x, y) fma (x, y, vfloat3)
322 BINARY_TEST (my_fma, fma);
323 #undef my_fma
324 #define my_fma(x, y) fma (x, vfloat3, y)
325 BINARY_TEST (my_fma, fma);
326 #undef my_fma
327 #define my_fma(x, y) fma (Vfloat3, x, y)
328 BINARY_TEST (my_fma, fma);
329 #undef my_fma
330 TEST (fma (vdouble1, Vdouble2, vllong3), double, fma);
331 TEST (fma (vint1, Vint2, vint3), double, fma);
332 TEST (fma (Vldouble1, vldouble2, Vldouble3), ldouble, fma);
333 TEST (fma (vldouble1, vint2, Vdouble3), ldouble, fma);
335 return result;
339 main (void)
341 return test (vint1, vllong1);
344 /* Now generate the three functions. */
345 #define HAVE_MAIN
347 #define F(name) name
348 #define TYPE double
349 #define CTYPE cdouble
350 #define T Tdouble
351 #define C Tcdouble
352 #include "test-tgmath2.c"
354 #define F(name) name##f
355 #define TYPE float
356 #define CTYPE cfloat
357 #define T Tfloat
358 #define C Tcfloat
359 #include "test-tgmath2.c"
361 #ifndef NO_LONG_DOUBLE
362 #define F(name) name##l
363 #define TYPE ldouble
364 #define CTYPE cldouble
365 #define T Tldouble
366 #define C Tcldouble
367 #include "test-tgmath2.c"
368 #endif
370 #else
372 #ifdef DEBUG
373 #define P() puts (__FUNCTION__); count++
374 #else
375 #define P() count++;
376 #endif
378 TYPE
379 (F(cos)) (TYPE x)
381 counts[T][C_cos]++;
382 P ();
383 return x;
386 CTYPE
387 (F(ccos)) (CTYPE x)
389 counts[C][C_cos]++;
390 P ();
391 return x;
394 TYPE
395 (F(fabs)) (TYPE x)
397 counts[T][C_fabs]++;
398 P ();
399 return x;
402 TYPE
403 (F(cabs)) (CTYPE x)
405 counts[T][C_cabs]++;
406 P ();
407 return x;
410 CTYPE
411 (F(conj)) (CTYPE x)
413 counts[C][C_conj]++;
414 P ();
415 return x;
418 TYPE
419 (F(expm1)) (TYPE x)
421 counts[T][C_expm1]++;
422 P ();
423 return x;
426 long int
427 (F(lrint)) (TYPE x)
429 counts[T][C_lrint]++;
430 P ();
431 return x;
434 TYPE
435 (F(ldexp)) (TYPE x, int y)
437 counts[T][C_ldexp]++;
438 P ();
439 return x + y;
442 TYPE
443 (F(atan2)) (TYPE x, TYPE y)
445 counts[T][C_atan2]++;
446 P ();
447 return x + y;
450 TYPE
451 (F(remquo)) (TYPE x, TYPE y, int *z)
453 counts[T][C_remquo]++;
454 P ();
455 return x + y + *z;
458 TYPE
459 (F(pow)) (TYPE x, TYPE y)
461 counts[T][C_pow]++;
462 P ();
463 return x + y;
466 CTYPE
467 (F(cpow)) (CTYPE x, CTYPE y)
469 counts[C][C_pow]++;
470 P ();
471 return x + y;
474 TYPE
475 (F(fma)) (TYPE x, TYPE y, TYPE z)
477 counts[T][C_fma]++;
478 P ();
479 return x + y + z;
482 #undef F
483 #undef TYPE
484 #undef CTYPE
485 #undef T
486 #undef C
487 #undef P
488 #endif