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