support_become_root: Enable file creation in user namespaces
[glibc.git] / math / test-tgmath.c
blob0f3e2e535edd169a5614fc8293f2ec675eeea106
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com> and
5 Ulrich Drepper <drepper@redhat.com>, 2001.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef HAVE_MAIN
22 #undef __NO_MATH_INLINES
23 #define __NO_MATH_INLINES 1
24 #include <float.h>
25 #include <math.h>
26 #include <stdint.h>
27 #include <stdio.h>
28 #include <tgmath.h>
30 //#define DEBUG
32 static void compile_test (void);
33 static void compile_testf (void);
34 #if LDBL_MANT_DIG > DBL_MANT_DIG
35 static void compile_testl (void);
36 #endif
38 float fx;
39 double dx;
40 long double lx;
41 const float fy = 1.25;
42 const double dy = 1.25;
43 const long double ly = 1.25;
44 complex float fz;
45 complex double dz;
46 complex long double lz;
48 int count_double;
49 int count_float;
50 int count_ldouble;
51 int count_cdouble;
52 int count_cfloat;
53 int count_cldouble;
55 #define NCALLS 134
56 #define NCALLS_INT 4
57 #define NCCALLS 47
59 static int
60 do_test (void)
62 int result = 0;
64 count_float = count_double = count_ldouble = 0;
65 count_cfloat = count_cdouble = count_cldouble = 0;
66 compile_test ();
67 if (count_float != 0 || count_cfloat != 0)
69 puts ("float function called for double test");
70 result = 1;
72 if (count_ldouble != 0 || count_cldouble != 0)
74 puts ("long double function called for double test");
75 result = 1;
77 if (count_double < NCALLS + NCALLS_INT)
79 printf ("double functions not called often enough (%d)\n",
80 count_double);
81 result = 1;
83 else if (count_double > NCALLS + NCALLS_INT)
85 printf ("double functions called too often (%d)\n",
86 count_double);
87 result = 1;
89 if (count_cdouble < NCCALLS)
91 printf ("double complex functions not called often enough (%d)\n",
92 count_cdouble);
93 result = 1;
95 else if (count_cdouble > NCCALLS)
97 printf ("double complex functions called too often (%d)\n",
98 count_cdouble);
99 result = 1;
102 count_float = count_double = count_ldouble = 0;
103 count_cfloat = count_cdouble = count_cldouble = 0;
104 compile_testf ();
105 if (count_double != 0 || count_cdouble != 0)
107 puts ("double function called for float test");
108 result = 1;
110 if (count_ldouble != 0 || count_cldouble != 0)
112 puts ("long double function called for float test");
113 result = 1;
115 if (count_float < NCALLS)
117 printf ("float functions not called often enough (%d)\n", count_float);
118 result = 1;
120 else if (count_float > NCALLS)
122 printf ("float functions called too often (%d)\n",
123 count_double);
124 result = 1;
126 if (count_cfloat < NCCALLS)
128 printf ("float complex functions not called often enough (%d)\n",
129 count_cfloat);
130 result = 1;
132 else if (count_cfloat > NCCALLS)
134 printf ("float complex functions called too often (%d)\n",
135 count_cfloat);
136 result = 1;
139 #if LDBL_MANT_DIG > DBL_MANT_DIG
140 count_float = count_double = count_ldouble = 0;
141 count_cfloat = count_cdouble = count_cldouble = 0;
142 compile_testl ();
143 if (count_float != 0 || count_cfloat != 0)
145 puts ("float function called for long double test");
146 result = 1;
148 if (count_double != 0 || count_cdouble != 0)
150 puts ("double function called for long double test");
151 result = 1;
153 if (count_ldouble < NCALLS)
155 printf ("long double functions not called often enough (%d)\n",
156 count_ldouble);
157 result = 1;
159 else if (count_ldouble > NCALLS)
161 printf ("long double functions called too often (%d)\n",
162 count_double);
163 result = 1;
165 if (count_cldouble < NCCALLS)
167 printf ("long double complex functions not called often enough (%d)\n",
168 count_cldouble);
169 result = 1;
171 else if (count_cldouble > NCCALLS)
173 printf ("long double complex functions called too often (%d)\n",
174 count_cldouble);
175 result = 1;
177 #endif
179 return result;
182 /* Now generate the three functions. */
183 #define HAVE_MAIN
185 #define F(name) name
186 #define TYPE double
187 #define TEST_INT 1
188 #define x dx
189 #define y dy
190 #define z dz
191 #define count count_double
192 #define ccount count_cdouble
193 #include "test-tgmath.c"
195 #define F(name) name##f
196 #define TYPE float
197 #define x fx
198 #define y fy
199 #define z fz
200 #define count count_float
201 #define ccount count_cfloat
202 #include "test-tgmath.c"
204 #if LDBL_MANT_DIG > DBL_MANT_DIG
205 #define F(name) name##l
206 #define TYPE long double
207 #define x lx
208 #define y ly
209 #define z lz
210 #define count count_ldouble
211 #define ccount count_cldouble
212 #include "test-tgmath.c"
213 #endif
215 #define TEST_FUNCTION do_test ()
216 #include "../test-skeleton.c"
218 #else
220 #ifdef DEBUG
221 #define P() puts (__FUNCTION__)
222 #else
223 #define P()
224 #endif
226 static void
227 F(compile_test) (void)
229 TYPE a, b, c = 1.0;
230 complex TYPE d;
231 int i = 2;
232 int saved_count;
233 long int j;
234 long long int k;
235 intmax_t m;
236 uintmax_t um;
238 a = cos (cos (x));
239 b = acos (acos (a));
240 a = sin (sin (x));
241 b = asin (asin (a));
242 a = tan (tan (x));
243 b = atan (atan (a));
244 c = atan2 (atan2 (a, c), atan2 (b, x));
245 a = cosh (cosh (x));
246 b = acosh (acosh (a));
247 a = sinh (sinh (x));
248 b = asinh (asinh (a));
249 a = tanh (tanh (x));
250 b = atanh (atanh (a));
251 a = exp (exp (x));
252 b = log (log (a));
253 a = log10 (log10 (x));
254 b = ldexp (ldexp (a, 1), 5);
255 a = frexp (frexp (x, &i), &i);
256 b = expm1 (expm1 (a));
257 a = log1p (log1p (x));
258 b = logb (logb (a));
259 a = exp2 (exp2 (x));
260 b = log2 (log2 (a));
261 a = pow (pow (x, a), pow (c, b));
262 b = sqrt (sqrt (a));
263 a = hypot (hypot (x, b), hypot (c, a));
264 b = cbrt (cbrt (a));
265 a = ceil (ceil (x));
266 b = fabs (fabs (a));
267 a = floor (floor (x));
268 b = fmod (fmod (a, b), fmod (c, x));
269 a = nearbyint (nearbyint (x));
270 b = round (round (a));
271 c = roundeven (roundeven (a));
272 a = trunc (trunc (x));
273 b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
274 j = lrint (x) + lround (a);
275 k = llrint (b) + llround (c);
276 m = fromfp (a, FP_INT_UPWARD, 2) + fromfpx (b, FP_INT_DOWNWARD, 3);
277 um = ufromfp (c, FP_INT_TONEAREST, 4) + ufromfpx (a, FP_INT_TOWARDZERO, 5);
278 a = erf (erf (x));
279 b = erfc (erfc (a));
280 a = tgamma (tgamma (x));
281 b = lgamma (lgamma (a));
282 a = rint (rint (x));
283 b = nextafter (nextafter (a, b), nextafter (c, x));
284 a = nextdown (nextdown (a));
285 b = nexttoward (nexttoward (x, a), c);
286 a = nextup (nextup (a));
287 b = remainder (remainder (a, b), remainder (c, x));
288 a = scalb (scalb (x, a), (TYPE) (6));
289 k = scalbn (a, 7) + scalbln (c, 10l);
290 i = ilogb (x);
291 j = llogb (x);
292 a = fdim (fdim (x, a), fdim (c, b));
293 b = fmax (fmax (a, x), fmax (c, b));
294 a = fmin (fmin (x, a), fmin (c, b));
295 b = fmaxmag (fmaxmag (a, x), fmaxmag (c, b));
296 a = fminmag (fminmag (x, a), fminmag (c, b));
297 b = fma (sin (a), sin (x), sin (c));
298 a = totalorder (x, b);
299 b = totalordermag (x, a);
301 #ifdef TEST_INT
302 a = atan2 (i, b);
303 b = remquo (i, a, &i);
304 c = fma (i, b, i);
305 a = pow (i, c);
306 #endif
307 x = a + b + c + i + j + k + m + um;
309 saved_count = count;
310 if (ccount != 0)
311 ccount = -10000;
313 d = cos (cos (z));
314 z = acos (acos (d));
315 d = sin (sin (z));
316 z = asin (asin (d));
317 d = tan (tan (z));
318 z = atan (atan (d));
319 d = cosh (cosh (z));
320 z = acosh (acosh (d));
321 d = sinh (sinh (z));
322 z = asinh (asinh (d));
323 d = tanh (tanh (z));
324 z = atanh (atanh (d));
325 d = exp (exp (z));
326 z = log (log (d));
327 d = sqrt (sqrt (z));
328 z = conj (conj (d));
329 d = fabs (conj (a));
330 z = pow (pow (a, d), pow (b, z));
331 d = cproj (cproj (z));
332 z += fabs (cproj (a));
333 a = carg (carg (z));
334 b = creal (creal (d));
335 c = cimag (cimag (z));
336 x += a + b + c + i + j + k;
337 z += d;
339 if (saved_count != count)
340 count = -10000;
342 if (0)
344 a = cos (y);
345 a = acos (y);
346 a = sin (y);
347 a = asin (y);
348 a = tan (y);
349 a = atan (y);
350 a = atan2 (y, y);
351 a = cosh (y);
352 a = acosh (y);
353 a = sinh (y);
354 a = asinh (y);
355 a = tanh (y);
356 a = atanh (y);
357 a = exp (y);
358 a = log (y);
359 a = log10 (y);
360 a = ldexp (y, 5);
361 a = frexp (y, &i);
362 a = expm1 (y);
363 a = log1p (y);
364 a = logb (y);
365 a = exp2 (y);
366 a = log2 (y);
367 a = pow (y, y);
368 a = sqrt (y);
369 a = hypot (y, y);
370 a = cbrt (y);
371 a = ceil (y);
372 a = fabs (y);
373 a = floor (y);
374 a = fmod (y, y);
375 a = nearbyint (y);
376 a = round (y);
377 a = roundeven (y);
378 a = trunc (y);
379 a = remquo (y, y, &i);
380 j = lrint (y) + lround (y);
381 k = llrint (y) + llround (y);
382 m = fromfp (y, FP_INT_UPWARD, 6) + fromfpx (y, FP_INT_DOWNWARD, 7);
383 um = (ufromfp (y, FP_INT_TONEAREST, 8)
384 + ufromfpx (y, FP_INT_TOWARDZERO, 9));
385 a = erf (y);
386 a = erfc (y);
387 a = tgamma (y);
388 a = lgamma (y);
389 a = rint (y);
390 a = nextafter (y, y);
391 a = nexttoward (y, y);
392 a = remainder (y, y);
393 a = scalb (y, (const TYPE) (6));
394 k = scalbn (y, 7) + scalbln (y, 10l);
395 i = ilogb (y);
396 j = llogb (y);
397 a = fdim (y, y);
398 a = fmax (y, y);
399 a = fmin (y, y);
400 a = fmaxmag (y, y);
401 a = fminmag (y, y);
402 a = fma (y, y, y);
403 a = totalorder (y, y);
404 a = totalordermag (y, y);
406 #ifdef TEST_INT
407 a = atan2 (i, y);
408 a = remquo (i, y, &i);
409 a = fma (i, y, i);
410 a = pow (i, y);
411 #endif
413 d = cos ((const complex TYPE) z);
414 d = acos ((const complex TYPE) z);
415 d = sin ((const complex TYPE) z);
416 d = asin ((const complex TYPE) z);
417 d = tan ((const complex TYPE) z);
418 d = atan ((const complex TYPE) z);
419 d = cosh ((const complex TYPE) z);
420 d = acosh ((const complex TYPE) z);
421 d = sinh ((const complex TYPE) z);
422 d = asinh ((const complex TYPE) z);
423 d = tanh ((const complex TYPE) z);
424 d = atanh ((const complex TYPE) z);
425 d = exp ((const complex TYPE) z);
426 d = log ((const complex TYPE) z);
427 d = sqrt ((const complex TYPE) z);
428 d = pow ((const complex TYPE) z, (const complex TYPE) z);
429 d = fabs ((const complex TYPE) z);
430 d = carg ((const complex TYPE) z);
431 d = creal ((const complex TYPE) z);
432 d = cimag ((const complex TYPE) z);
433 d = conj ((const complex TYPE) z);
434 d = cproj ((const complex TYPE) z);
437 #undef x
438 #undef y
439 #undef z
442 TYPE
443 (F(cos)) (TYPE x)
445 ++count;
446 P ();
447 return x;
450 TYPE
451 (F(acos)) (TYPE x)
453 ++count;
454 P ();
455 return x;
458 TYPE
459 (F(sin)) (TYPE x)
461 ++count;
462 P ();
463 return x;
466 TYPE
467 (F(asin)) (TYPE x)
469 ++count;
470 P ();
471 return x;
474 TYPE
475 (F(tan)) (TYPE x)
477 ++count;
478 P ();
479 return x;
482 TYPE
483 (F(atan)) (TYPE x)
485 ++count;
486 P ();
487 return x;
490 TYPE
491 (F(atan2)) (TYPE x, TYPE y)
493 ++count;
494 P ();
495 return x + y;
498 TYPE
499 (F(cosh)) (TYPE x)
501 ++count;
502 P ();
503 return x;
506 TYPE
507 (F(acosh)) (TYPE x)
509 ++count;
510 P ();
511 return x;
514 TYPE
515 (F(sinh)) (TYPE x)
517 ++count;
518 P ();
519 return x;
522 TYPE
523 (F(asinh)) (TYPE x)
525 ++count;
526 P ();
527 return x;
530 TYPE
531 (F(tanh)) (TYPE x)
533 ++count;
534 P ();
535 return x;
538 TYPE
539 (F(atanh)) (TYPE x)
541 ++count;
542 P ();
543 return x;
546 TYPE
547 (F(exp)) (TYPE x)
549 ++count;
550 P ();
551 return x;
554 TYPE
555 (F(log)) (TYPE x)
557 ++count;
558 P ();
559 return x;
562 TYPE
563 (F(log10)) (TYPE x)
565 ++count;
566 P ();
567 return x;
570 TYPE
571 (F(ldexp)) (TYPE x, int y)
573 ++count;
574 P ();
575 return x + y;
578 TYPE
579 (F(frexp)) (TYPE x, int *y)
581 ++count;
582 P ();
583 return x + *y;
586 TYPE
587 (F(expm1)) (TYPE x)
589 ++count;
590 P ();
591 return x;
594 TYPE
595 (F(log1p)) (TYPE x)
597 ++count;
598 P ();
599 return x;
602 TYPE
603 (F(logb)) (TYPE x)
605 ++count;
606 P ();
607 return x;
610 TYPE
611 (F(exp2)) (TYPE x)
613 ++count;
614 P ();
615 return x;
618 TYPE
619 (F(log2)) (TYPE x)
621 ++count;
622 P ();
623 return x;
626 TYPE
627 (F(pow)) (TYPE x, TYPE y)
629 ++count;
630 P ();
631 return x + y;
634 TYPE
635 (F(sqrt)) (TYPE x)
637 ++count;
638 P ();
639 return x;
642 TYPE
643 (F(hypot)) (TYPE x, TYPE y)
645 ++count;
646 P ();
647 return x + y;
650 TYPE
651 (F(cbrt)) (TYPE x)
653 ++count;
654 P ();
655 return x;
658 TYPE
659 (F(ceil)) (TYPE x)
661 ++count;
662 P ();
663 return x;
666 TYPE
667 (F(fabs)) (TYPE x)
669 ++count;
670 P ();
671 return x;
674 TYPE
675 (F(floor)) (TYPE x)
677 ++count;
678 P ();
679 return x;
682 TYPE
683 (F(fmod)) (TYPE x, TYPE y)
685 ++count;
686 P ();
687 return x + y;
690 TYPE
691 (F(nearbyint)) (TYPE x)
693 ++count;
694 P ();
695 return x;
698 TYPE
699 (F(round)) (TYPE x)
701 ++count;
702 P ();
703 return x;
706 TYPE
707 (F(roundeven)) (TYPE x)
709 ++count;
710 P ();
711 return x;
714 TYPE
715 (F(trunc)) (TYPE x)
717 ++count;
718 P ();
719 return x;
722 TYPE
723 (F(remquo)) (TYPE x, TYPE y, int *i)
725 ++count;
726 P ();
727 return x + y + *i;
730 long int
731 (F(lrint)) (TYPE x)
733 ++count;
734 P ();
735 return x;
738 long int
739 (F(lround)) (TYPE x)
741 ++count;
742 P ();
743 return x;
746 long long int
747 (F(llrint)) (TYPE x)
749 ++count;
750 P ();
751 return x;
754 long long int
755 (F(llround)) (TYPE x)
757 ++count;
758 P ();
759 return x;
762 intmax_t
763 (F(fromfp)) (TYPE x, int round, unsigned int width)
765 ++count;
766 P ();
767 return x;
770 intmax_t
771 (F(fromfpx)) (TYPE x, int round, unsigned int width)
773 ++count;
774 P ();
775 return x;
778 uintmax_t
779 (F(ufromfp)) (TYPE x, int round, unsigned int width)
781 ++count;
782 P ();
783 return x;
786 uintmax_t
787 (F(ufromfpx)) (TYPE x, int round, unsigned int width)
789 ++count;
790 P ();
791 return x;
794 TYPE
795 (F(erf)) (TYPE x)
797 ++count;
798 P ();
799 return x;
802 TYPE
803 (F(erfc)) (TYPE x)
805 ++count;
806 P ();
807 return x;
810 TYPE
811 (F(tgamma)) (TYPE x)
813 ++count;
814 P ();
815 return x;
818 TYPE
819 (F(lgamma)) (TYPE x)
821 ++count;
822 P ();
823 return x;
826 TYPE
827 (F(rint)) (TYPE x)
829 ++count;
830 P ();
831 return x;
834 TYPE
835 (F(nextafter)) (TYPE x, TYPE y)
837 ++count;
838 P ();
839 return x + y;
842 TYPE
843 (F(nextdown)) (TYPE x)
845 ++count;
846 P ();
847 return x;
850 TYPE
851 (F(nexttoward)) (TYPE x, long double y)
853 ++count;
854 P ();
855 return x + y;
858 TYPE
859 (F(nextup)) (TYPE x)
861 ++count;
862 P ();
863 return x;
866 TYPE
867 (F(remainder)) (TYPE x, TYPE y)
869 ++count;
870 P ();
871 return x + y;
874 TYPE
875 (F(scalb)) (TYPE x, TYPE y)
877 ++count;
878 P ();
879 return x + y;
882 TYPE
883 (F(scalbn)) (TYPE x, int y)
885 ++count;
886 P ();
887 return x + y;
890 TYPE
891 (F(scalbln)) (TYPE x, long int y)
893 ++count;
894 P ();
895 return x + y;
899 (F(ilogb)) (TYPE x)
901 ++count;
902 P ();
903 return x;
906 long int
907 (F(llogb)) (TYPE x)
909 ++count;
910 P ();
911 return x;
914 TYPE
915 (F(fdim)) (TYPE x, TYPE y)
917 ++count;
918 P ();
919 return x + y;
922 TYPE
923 (F(fmin)) (TYPE x, TYPE y)
925 ++count;
926 P ();
927 return x + y;
930 TYPE
931 (F(fmax)) (TYPE x, TYPE y)
933 ++count;
934 P ();
935 return x + y;
938 TYPE
939 (F(fminmag)) (TYPE x, TYPE y)
941 ++count;
942 P ();
943 return x + y;
946 TYPE
947 (F(fmaxmag)) (TYPE x, TYPE y)
949 ++count;
950 P ();
951 return x + y;
954 TYPE
955 (F(fma)) (TYPE x, TYPE y, TYPE z)
957 ++count;
958 P ();
959 return x + y + z;
963 (F(totalorder)) (TYPE x, TYPE y)
965 ++count;
966 P ();
967 return x + y;
971 (F(totalordermag)) (TYPE x, TYPE y)
973 ++count;
974 P ();
975 return x + y;
978 complex TYPE
979 (F(cacos)) (complex TYPE x)
981 ++ccount;
982 P ();
983 return x;
986 complex TYPE
987 (F(casin)) (complex TYPE x)
989 ++ccount;
990 P ();
991 return x;
994 complex TYPE
995 (F(catan)) (complex TYPE x)
997 ++ccount;
998 P ();
999 return x;
1002 complex TYPE
1003 (F(ccos)) (complex TYPE x)
1005 ++ccount;
1006 P ();
1007 return x;
1010 complex TYPE
1011 (F(csin)) (complex TYPE x)
1013 ++ccount;
1014 P ();
1015 return x;
1018 complex TYPE
1019 (F(ctan)) (complex TYPE x)
1021 ++ccount;
1022 P ();
1023 return x;
1026 complex TYPE
1027 (F(cacosh)) (complex TYPE x)
1029 ++ccount;
1030 P ();
1031 return x;
1034 complex TYPE
1035 (F(casinh)) (complex TYPE x)
1037 ++ccount;
1038 P ();
1039 return x;
1042 complex TYPE
1043 (F(catanh)) (complex TYPE x)
1045 ++ccount;
1046 P ();
1047 return x;
1050 complex TYPE
1051 (F(ccosh)) (complex TYPE x)
1053 ++ccount;
1054 P ();
1055 return x;
1058 complex TYPE
1059 (F(csinh)) (complex TYPE x)
1061 ++ccount;
1062 P ();
1063 return x;
1066 complex TYPE
1067 (F(ctanh)) (complex TYPE x)
1069 ++ccount;
1070 P ();
1071 return x;
1074 complex TYPE
1075 (F(cexp)) (complex TYPE x)
1077 ++ccount;
1078 P ();
1079 return x;
1082 complex TYPE
1083 (F(clog)) (complex TYPE x)
1085 ++ccount;
1086 P ();
1087 return x;
1090 complex TYPE
1091 (F(csqrt)) (complex TYPE x)
1093 ++ccount;
1094 P ();
1095 return x;
1098 complex TYPE
1099 (F(cpow)) (complex TYPE x, complex TYPE y)
1101 ++ccount;
1102 P ();
1103 return x + y;
1106 TYPE
1107 (F(cabs)) (complex TYPE x)
1109 ++ccount;
1110 P ();
1111 return x;
1114 TYPE
1115 (F(carg)) (complex TYPE x)
1117 ++ccount;
1118 P ();
1119 return x;
1122 TYPE
1123 (F(creal)) (complex TYPE x)
1125 ++ccount;
1126 P ();
1127 return __real__ x;
1130 TYPE
1131 (F(cimag)) (complex TYPE x)
1133 ++ccount;
1134 P ();
1135 return __imag__ x;
1138 complex TYPE
1139 (F(conj)) (complex TYPE x)
1141 ++ccount;
1142 P ();
1143 return x;
1146 complex TYPE
1147 (F(cproj)) (complex TYPE x)
1149 ++ccount;
1150 P ();
1151 return x;
1154 #undef F
1155 #undef TYPE
1156 #undef count
1157 #undef ccount
1158 #undef TEST_INT
1159 #endif