powerpc64le: bump binutils version requirement to >= 2.26
[glibc.git] / math / test-tgmath.c
blob6d5a84bc01912eff6d08ea892a4c849dc5ca1af8
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001-2020 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 <https://www.gnu.org/licenses/>. */
21 #ifndef HAVE_MAIN
22 #include <float.h>
23 #include <math.h>
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <tgmath.h>
28 //#define DEBUG
30 static void compile_test (void);
31 static void compile_testf (void);
32 #if LDBL_MANT_DIG > DBL_MANT_DIG
33 static void compile_testl (void);
34 #endif
36 float fx;
37 double dx;
38 long double lx;
39 const float fy = 1.25;
40 const double dy = 1.25;
41 const long double ly = 1.25;
42 complex float fz;
43 complex double dz;
44 complex long double lz;
46 volatile int count_double;
47 volatile int count_float;
48 volatile int count_ldouble;
49 volatile int count_cdouble;
50 volatile int count_cfloat;
51 volatile int count_cldouble;
53 #define NCALLS 132
54 #define NCALLS_INT 4
55 #define NCCALLS 47
57 static int
58 do_test (void)
60 int result = 0;
62 count_float = count_double = count_ldouble = 0;
63 count_cfloat = count_cdouble = count_cldouble = 0;
64 compile_test ();
65 if (count_float != 0 || count_cfloat != 0)
67 puts ("float function called for double test");
68 result = 1;
70 if (count_ldouble != 0 || count_cldouble != 0)
72 puts ("long double function called for double test");
73 result = 1;
75 if (count_double < NCALLS + NCALLS_INT)
77 printf ("double functions not called often enough (%d)\n",
78 count_double);
79 result = 1;
81 else if (count_double > NCALLS + NCALLS_INT)
83 printf ("double functions called too often (%d)\n",
84 count_double);
85 result = 1;
87 if (count_cdouble < NCCALLS)
89 printf ("double complex functions not called often enough (%d)\n",
90 count_cdouble);
91 result = 1;
93 else if (count_cdouble > NCCALLS)
95 printf ("double complex functions called too often (%d)\n",
96 count_cdouble);
97 result = 1;
100 count_float = count_double = count_ldouble = 0;
101 count_cfloat = count_cdouble = count_cldouble = 0;
102 compile_testf ();
103 if (count_double != 0 || count_cdouble != 0)
105 puts ("double function called for float test");
106 result = 1;
108 if (count_ldouble != 0 || count_cldouble != 0)
110 puts ("long double function called for float test");
111 result = 1;
113 if (count_float < NCALLS)
115 printf ("float functions not called often enough (%d)\n", count_float);
116 result = 1;
118 else if (count_float > NCALLS)
120 printf ("float functions called too often (%d)\n",
121 count_double);
122 result = 1;
124 if (count_cfloat < NCCALLS)
126 printf ("float complex functions not called often enough (%d)\n",
127 count_cfloat);
128 result = 1;
130 else if (count_cfloat > NCCALLS)
132 printf ("float complex functions called too often (%d)\n",
133 count_cfloat);
134 result = 1;
137 #if LDBL_MANT_DIG > DBL_MANT_DIG
138 count_float = count_double = count_ldouble = 0;
139 count_cfloat = count_cdouble = count_cldouble = 0;
140 compile_testl ();
141 if (count_float != 0 || count_cfloat != 0)
143 puts ("float function called for long double test");
144 result = 1;
146 if (count_double != 0 || count_cdouble != 0)
148 puts ("double function called for long double test");
149 result = 1;
151 if (count_ldouble < NCALLS)
153 printf ("long double functions not called often enough (%d)\n",
154 count_ldouble);
155 result = 1;
157 else if (count_ldouble > NCALLS)
159 printf ("long double functions called too often (%d)\n",
160 count_double);
161 result = 1;
163 if (count_cldouble < NCCALLS)
165 printf ("long double complex functions not called often enough (%d)\n",
166 count_cldouble);
167 result = 1;
169 else if (count_cldouble > NCCALLS)
171 printf ("long double complex functions called too often (%d)\n",
172 count_cldouble);
173 result = 1;
175 #endif
177 return result;
180 /* Now generate the three functions. */
181 #define HAVE_MAIN
183 #define F(name) name
184 #define TYPE double
185 #define TEST_INT 1
186 #define x dx
187 #define y dy
188 #define z dz
189 #define count count_double
190 #define ccount count_cdouble
191 #include "test-tgmath.c"
193 #define F(name) name##f
194 #define TYPE float
195 #define x fx
196 #define y fy
197 #define z fz
198 #define count count_float
199 #define ccount count_cfloat
200 #include "test-tgmath.c"
202 #if LDBL_MANT_DIG > DBL_MANT_DIG
203 #define F(name) name##l
204 #define TYPE long double
205 #define x lx
206 #define y ly
207 #define z lz
208 #define count count_ldouble
209 #define ccount count_cldouble
210 #include "test-tgmath.c"
211 #endif
213 #define TEST_FUNCTION do_test ()
214 #include "../test-skeleton.c"
216 #else
218 #ifdef DEBUG
219 #define P() puts (__FUNCTION__)
220 #else
221 #define P()
222 #endif
224 static void
225 F(compile_test) (void)
227 TYPE a, b, c = 1.0;
228 complex TYPE d;
229 int i = 2;
230 int saved_count;
231 long int j;
232 long long int k;
233 intmax_t m;
234 uintmax_t um;
236 a = cos (cos (x));
237 b = acos (acos (a));
238 a = sin (sin (x));
239 b = asin (asin (a));
240 a = tan (tan (x));
241 b = atan (atan (a));
242 c = atan2 (atan2 (a, c), atan2 (b, x));
243 a = cosh (cosh (x));
244 b = acosh (acosh (a));
245 a = sinh (sinh (x));
246 b = asinh (asinh (a));
247 a = tanh (tanh (x));
248 b = atanh (atanh (a));
249 a = exp (exp (x));
250 b = log (log (a));
251 a = log10 (log10 (x));
252 b = ldexp (ldexp (a, 1), 5);
253 a = frexp (frexp (x, &i), &i);
254 b = expm1 (expm1 (a));
255 a = log1p (log1p (x));
256 b = logb (logb (a));
257 a = exp2 (exp2 (x));
258 b = log2 (log2 (a));
259 a = pow (pow (x, a), pow (c, b));
260 b = sqrt (sqrt (a));
261 a = hypot (hypot (x, b), hypot (c, a));
262 b = cbrt (cbrt (a));
263 a = ceil (ceil (x));
264 b = fabs (fabs (a));
265 a = floor (floor (x));
266 b = fmod (fmod (a, b), fmod (c, x));
267 a = nearbyint (nearbyint (x));
268 b = round (round (a));
269 c = roundeven (roundeven (a));
270 a = trunc (trunc (x));
271 b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
272 j = lrint (x) + lround (a);
273 k = llrint (b) + llround (c);
274 m = fromfp (a, FP_INT_UPWARD, 2) + fromfpx (b, FP_INT_DOWNWARD, 3);
275 um = ufromfp (c, FP_INT_TONEAREST, 4) + ufromfpx (a, FP_INT_TOWARDZERO, 5);
276 a = erf (erf (x));
277 b = erfc (erfc (a));
278 a = tgamma (tgamma (x));
279 b = lgamma (lgamma (a));
280 a = rint (rint (x));
281 b = nextafter (nextafter (a, b), nextafter (c, x));
282 a = nextdown (nextdown (a));
283 b = nexttoward (nexttoward (x, a), c);
284 a = nextup (nextup (a));
285 b = remainder (remainder (a, b), remainder (c, x));
286 a = scalb (scalb (x, a), (TYPE) (6));
287 k = scalbn (a, 7) + scalbln (c, 10l);
288 i = ilogb (x);
289 j = llogb (x);
290 a = fdim (fdim (x, a), fdim (c, b));
291 b = fmax (fmax (a, x), fmax (c, b));
292 a = fmin (fmin (x, a), fmin (c, b));
293 b = fmaxmag (fmaxmag (a, x), fmaxmag (c, b));
294 a = fminmag (fminmag (x, a), fminmag (c, b));
295 b = fma (sin (a), sin (x), sin (c));
297 #ifdef TEST_INT
298 a = atan2 (i, b);
299 b = remquo (i, a, &i);
300 c = fma (i, b, i);
301 a = pow (i, c);
302 #endif
303 x = a + b + c + i + j + k + m + um;
305 saved_count = count;
306 if (ccount != 0)
307 ccount = -10000;
309 d = cos (cos (z));
310 z = acos (acos (d));
311 d = sin (sin (z));
312 z = asin (asin (d));
313 d = tan (tan (z));
314 z = atan (atan (d));
315 d = cosh (cosh (z));
316 z = acosh (acosh (d));
317 d = sinh (sinh (z));
318 z = asinh (asinh (d));
319 d = tanh (tanh (z));
320 z = atanh (atanh (d));
321 d = exp (exp (z));
322 z = log (log (d));
323 d = sqrt (sqrt (z));
324 z = conj (conj (d));
325 d = fabs (conj (a));
326 z = pow (pow (a, d), pow (b, z));
327 d = cproj (cproj (z));
328 z += fabs (cproj (a));
329 a = carg (carg (z));
330 b = creal (creal (d));
331 c = cimag (cimag (z));
332 x += a + b + c + i + j + k;
333 z += d;
335 if (saved_count != count)
336 count = -10000;
338 if (0)
340 a = cos (y);
341 a = acos (y);
342 a = sin (y);
343 a = asin (y);
344 a = tan (y);
345 a = atan (y);
346 a = atan2 (y, y);
347 a = cosh (y);
348 a = acosh (y);
349 a = sinh (y);
350 a = asinh (y);
351 a = tanh (y);
352 a = atanh (y);
353 a = exp (y);
354 a = log (y);
355 a = log10 (y);
356 a = ldexp (y, 5);
357 a = frexp (y, &i);
358 a = expm1 (y);
359 a = log1p (y);
360 a = logb (y);
361 a = exp2 (y);
362 a = log2 (y);
363 a = pow (y, y);
364 a = sqrt (y);
365 a = hypot (y, y);
366 a = cbrt (y);
367 a = ceil (y);
368 a = fabs (y);
369 a = floor (y);
370 a = fmod (y, y);
371 a = nearbyint (y);
372 a = round (y);
373 a = roundeven (y);
374 a = trunc (y);
375 a = remquo (y, y, &i);
376 j = lrint (y) + lround (y);
377 k = llrint (y) + llround (y);
378 m = fromfp (y, FP_INT_UPWARD, 6) + fromfpx (y, FP_INT_DOWNWARD, 7);
379 um = (ufromfp (y, FP_INT_TONEAREST, 8)
380 + ufromfpx (y, FP_INT_TOWARDZERO, 9));
381 a = erf (y);
382 a = erfc (y);
383 a = tgamma (y);
384 a = lgamma (y);
385 a = rint (y);
386 a = nextafter (y, y);
387 a = nexttoward (y, y);
388 a = remainder (y, y);
389 a = scalb (y, (const TYPE) (6));
390 k = scalbn (y, 7) + scalbln (y, 10l);
391 i = ilogb (y);
392 j = llogb (y);
393 a = fdim (y, y);
394 a = fmax (y, y);
395 a = fmin (y, y);
396 a = fmaxmag (y, y);
397 a = fminmag (y, y);
398 a = fma (y, y, y);
400 #ifdef TEST_INT
401 a = atan2 (i, y);
402 a = remquo (i, y, &i);
403 a = fma (i, y, i);
404 a = pow (i, y);
405 #endif
407 d = cos ((const complex TYPE) z);
408 d = acos ((const complex TYPE) z);
409 d = sin ((const complex TYPE) z);
410 d = asin ((const complex TYPE) z);
411 d = tan ((const complex TYPE) z);
412 d = atan ((const complex TYPE) z);
413 d = cosh ((const complex TYPE) z);
414 d = acosh ((const complex TYPE) z);
415 d = sinh ((const complex TYPE) z);
416 d = asinh ((const complex TYPE) z);
417 d = tanh ((const complex TYPE) z);
418 d = atanh ((const complex TYPE) z);
419 d = exp ((const complex TYPE) z);
420 d = log ((const complex TYPE) z);
421 d = sqrt ((const complex TYPE) z);
422 d = pow ((const complex TYPE) z, (const complex TYPE) z);
423 d = fabs ((const complex TYPE) z);
424 d = carg ((const complex TYPE) z);
425 d = creal ((const complex TYPE) z);
426 d = cimag ((const complex TYPE) z);
427 d = conj ((const complex TYPE) z);
428 d = cproj ((const complex TYPE) z);
431 #undef x
432 #undef y
433 #undef z
436 TYPE
437 (F(cos)) (TYPE x)
439 ++count;
440 P ();
441 return x;
444 TYPE
445 (F(acos)) (TYPE x)
447 ++count;
448 P ();
449 return x;
452 TYPE
453 (F(sin)) (TYPE x)
455 ++count;
456 P ();
457 return x;
460 TYPE
461 (F(asin)) (TYPE x)
463 ++count;
464 P ();
465 return x;
468 TYPE
469 (F(tan)) (TYPE x)
471 ++count;
472 P ();
473 return x;
476 TYPE
477 (F(atan)) (TYPE x)
479 ++count;
480 P ();
481 return x;
484 TYPE
485 (F(atan2)) (TYPE x, TYPE y)
487 ++count;
488 P ();
489 return x + y;
492 TYPE
493 (F(cosh)) (TYPE x)
495 ++count;
496 P ();
497 return x;
500 TYPE
501 (F(acosh)) (TYPE x)
503 ++count;
504 P ();
505 return x;
508 TYPE
509 (F(sinh)) (TYPE x)
511 ++count;
512 P ();
513 return x;
516 TYPE
517 (F(asinh)) (TYPE x)
519 ++count;
520 P ();
521 return x;
524 TYPE
525 (F(tanh)) (TYPE x)
527 ++count;
528 P ();
529 return x;
532 TYPE
533 (F(atanh)) (TYPE x)
535 ++count;
536 P ();
537 return x;
540 TYPE
541 (F(exp)) (TYPE x)
543 ++count;
544 P ();
545 return x;
548 TYPE
549 (F(log)) (TYPE x)
551 ++count;
552 P ();
553 return x;
556 TYPE
557 (F(log10)) (TYPE x)
559 ++count;
560 P ();
561 return x;
564 TYPE
565 (F(ldexp)) (TYPE x, int y)
567 ++count;
568 P ();
569 return x + y;
572 TYPE
573 (F(frexp)) (TYPE x, int *y)
575 ++count;
576 P ();
577 return x + *y;
580 TYPE
581 (F(expm1)) (TYPE x)
583 ++count;
584 P ();
585 return x;
588 TYPE
589 (F(log1p)) (TYPE x)
591 ++count;
592 P ();
593 return x;
596 TYPE
597 (F(logb)) (TYPE x)
599 ++count;
600 P ();
601 return x;
604 TYPE
605 (F(exp2)) (TYPE x)
607 ++count;
608 P ();
609 return x;
612 TYPE
613 (F(log2)) (TYPE x)
615 ++count;
616 P ();
617 return x;
620 TYPE
621 (F(pow)) (TYPE x, TYPE y)
623 ++count;
624 P ();
625 return x + y;
628 TYPE
629 (F(sqrt)) (TYPE x)
631 ++count;
632 P ();
633 return x;
636 TYPE
637 (F(hypot)) (TYPE x, TYPE y)
639 ++count;
640 P ();
641 return x + y;
644 TYPE
645 (F(cbrt)) (TYPE x)
647 ++count;
648 P ();
649 return x;
652 TYPE
653 (F(ceil)) (TYPE x)
655 ++count;
656 P ();
657 return x;
660 TYPE
661 (F(fabs)) (TYPE x)
663 ++count;
664 P ();
665 return x;
668 TYPE
669 (F(floor)) (TYPE x)
671 ++count;
672 P ();
673 return x;
676 TYPE
677 (F(fmod)) (TYPE x, TYPE y)
679 ++count;
680 P ();
681 return x + y;
684 TYPE
685 (F(nearbyint)) (TYPE x)
687 ++count;
688 P ();
689 return x;
692 TYPE
693 (F(round)) (TYPE x)
695 ++count;
696 P ();
697 return x;
700 TYPE
701 (F(roundeven)) (TYPE x)
703 ++count;
704 P ();
705 return x;
708 TYPE
709 (F(trunc)) (TYPE x)
711 ++count;
712 P ();
713 return x;
716 TYPE
717 (F(remquo)) (TYPE x, TYPE y, int *i)
719 ++count;
720 P ();
721 return x + y + *i;
724 long int
725 (F(lrint)) (TYPE x)
727 ++count;
728 P ();
729 return x;
732 long int
733 (F(lround)) (TYPE x)
735 ++count;
736 P ();
737 return x;
740 long long int
741 (F(llrint)) (TYPE x)
743 ++count;
744 P ();
745 return x;
748 long long int
749 (F(llround)) (TYPE x)
751 ++count;
752 P ();
753 return x;
756 intmax_t
757 (F(fromfp)) (TYPE x, int round, unsigned int width)
759 ++count;
760 P ();
761 return x;
764 intmax_t
765 (F(fromfpx)) (TYPE x, int round, unsigned int width)
767 ++count;
768 P ();
769 return x;
772 uintmax_t
773 (F(ufromfp)) (TYPE x, int round, unsigned int width)
775 ++count;
776 P ();
777 return x;
780 uintmax_t
781 (F(ufromfpx)) (TYPE x, int round, unsigned int width)
783 ++count;
784 P ();
785 return x;
788 TYPE
789 (F(erf)) (TYPE x)
791 ++count;
792 P ();
793 return x;
796 TYPE
797 (F(erfc)) (TYPE x)
799 ++count;
800 P ();
801 return x;
804 TYPE
805 (F(tgamma)) (TYPE x)
807 ++count;
808 P ();
809 return x;
812 TYPE
813 (F(lgamma)) (TYPE x)
815 ++count;
816 P ();
817 return x;
820 TYPE
821 (F(rint)) (TYPE x)
823 ++count;
824 P ();
825 return x;
828 TYPE
829 (F(nextafter)) (TYPE x, TYPE y)
831 ++count;
832 P ();
833 return x + y;
836 TYPE
837 (F(nextdown)) (TYPE x)
839 ++count;
840 P ();
841 return x;
844 TYPE
845 (F(nexttoward)) (TYPE x, long double y)
847 ++count;
848 P ();
849 return x + y;
852 TYPE
853 (F(nextup)) (TYPE x)
855 ++count;
856 P ();
857 return x;
860 TYPE
861 (F(remainder)) (TYPE x, TYPE y)
863 ++count;
864 P ();
865 return x + y;
868 TYPE
869 (F(scalb)) (TYPE x, TYPE y)
871 ++count;
872 P ();
873 return x + y;
876 TYPE
877 (F(scalbn)) (TYPE x, int y)
879 ++count;
880 P ();
881 return x + y;
884 TYPE
885 (F(scalbln)) (TYPE x, long int y)
887 ++count;
888 P ();
889 return x + y;
893 (F(ilogb)) (TYPE x)
895 ++count;
896 P ();
897 return x;
900 long int
901 (F(llogb)) (TYPE x)
903 ++count;
904 P ();
905 return x;
908 TYPE
909 (F(fdim)) (TYPE x, TYPE y)
911 ++count;
912 P ();
913 return x + y;
916 TYPE
917 (F(fmin)) (TYPE x, TYPE y)
919 ++count;
920 P ();
921 return x + y;
924 TYPE
925 (F(fmax)) (TYPE x, TYPE y)
927 ++count;
928 P ();
929 return x + y;
932 TYPE
933 (F(fminmag)) (TYPE x, TYPE y)
935 ++count;
936 P ();
937 return x + y;
940 TYPE
941 (F(fmaxmag)) (TYPE x, TYPE y)
943 ++count;
944 P ();
945 return x + y;
948 TYPE
949 (F(fma)) (TYPE x, TYPE y, TYPE z)
951 ++count;
952 P ();
953 return x + y + z;
956 complex TYPE
957 (F(cacos)) (complex TYPE x)
959 ++ccount;
960 P ();
961 return x;
964 complex TYPE
965 (F(casin)) (complex TYPE x)
967 ++ccount;
968 P ();
969 return x;
972 complex TYPE
973 (F(catan)) (complex TYPE x)
975 ++ccount;
976 P ();
977 return x;
980 complex TYPE
981 (F(ccos)) (complex TYPE x)
983 ++ccount;
984 P ();
985 return x;
988 complex TYPE
989 (F(csin)) (complex TYPE x)
991 ++ccount;
992 P ();
993 return x;
996 complex TYPE
997 (F(ctan)) (complex TYPE x)
999 ++ccount;
1000 P ();
1001 return x;
1004 complex TYPE
1005 (F(cacosh)) (complex TYPE x)
1007 ++ccount;
1008 P ();
1009 return x;
1012 complex TYPE
1013 (F(casinh)) (complex TYPE x)
1015 ++ccount;
1016 P ();
1017 return x;
1020 complex TYPE
1021 (F(catanh)) (complex TYPE x)
1023 ++ccount;
1024 P ();
1025 return x;
1028 complex TYPE
1029 (F(ccosh)) (complex TYPE x)
1031 ++ccount;
1032 P ();
1033 return x;
1036 complex TYPE
1037 (F(csinh)) (complex TYPE x)
1039 ++ccount;
1040 P ();
1041 return x;
1044 complex TYPE
1045 (F(ctanh)) (complex TYPE x)
1047 ++ccount;
1048 P ();
1049 return x;
1052 complex TYPE
1053 (F(cexp)) (complex TYPE x)
1055 ++ccount;
1056 P ();
1057 return x;
1060 complex TYPE
1061 (F(clog)) (complex TYPE x)
1063 ++ccount;
1064 P ();
1065 return x;
1068 complex TYPE
1069 (F(csqrt)) (complex TYPE x)
1071 ++ccount;
1072 P ();
1073 return x;
1076 complex TYPE
1077 (F(cpow)) (complex TYPE x, complex TYPE y)
1079 ++ccount;
1080 P ();
1081 return x + y;
1084 TYPE
1085 (F(cabs)) (complex TYPE x)
1087 ++ccount;
1088 P ();
1089 return x;
1092 TYPE
1093 (F(carg)) (complex TYPE x)
1095 ++ccount;
1096 P ();
1097 return x;
1100 TYPE
1101 (F(creal)) (complex TYPE x)
1103 ++ccount;
1104 P ();
1105 return __real__ x;
1108 TYPE
1109 (F(cimag)) (complex TYPE x)
1111 ++ccount;
1112 P ();
1113 return __imag__ x;
1116 complex TYPE
1117 (F(conj)) (complex TYPE x)
1119 ++ccount;
1120 P ();
1121 return x;
1124 complex TYPE
1125 (F(cproj)) (complex TYPE x)
1127 ++ccount;
1128 P ();
1129 return x;
1132 #undef F
1133 #undef TYPE
1134 #undef count
1135 #undef ccount
1136 #undef TEST_INT
1137 #endif