S390: Optimize wmemset.
[glibc.git] / math / test-tgmath.c
blobb82413eb31dd4bbf3f3c8bc253cb39c19aba5d35
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001-2015 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 <math.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 #ifndef NO_LONG_DOUBLE
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 int count_double;
47 int count_float;
48 int count_ldouble;
49 int count_cdouble;
50 int count_cfloat;
51 int count_cldouble;
53 #define NCALLS 115
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 #ifndef NO_LONG_DOUBLE
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 #ifndef NO_LONG_DOUBLE
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;
230 int saved_count;
231 long int j;
232 long long int k;
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 a = trunc (trunc (x));
268 b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
269 j = lrint (x) + lround (a);
270 k = llrint (b) + llround (c);
271 a = erf (erf (x));
272 b = erfc (erfc (a));
273 a = tgamma (tgamma (x));
274 b = lgamma (lgamma (a));
275 a = rint (rint (x));
276 b = nextafter (nextafter (a, b), nextafter (c, x));
277 a = nexttoward (nexttoward (x, a), c);
278 b = remainder (remainder (a, b), remainder (c, x));
279 a = scalb (scalb (x, a), (TYPE) (6));
280 k = scalbn (a, 7) + scalbln (c, 10l);
281 i = ilogb (x);
282 a = fdim (fdim (x, a), fdim (c, b));
283 b = fmax (fmax (a, x), fmax (c, b));
284 a = fmin (fmin (x, a), fmin (c, b));
285 b = fma (sin (a), sin (x), sin (c));
287 #ifdef TEST_INT
288 a = atan2 (i, b);
289 b = remquo (i, a, &i);
290 c = fma (i, b, i);
291 a = pow (i, c);
292 #endif
293 x = a + b + c + i + j + k;
295 saved_count = count;
296 if (ccount != 0)
297 ccount = -10000;
299 d = cos (cos (z));
300 z = acos (acos (d));
301 d = sin (sin (z));
302 z = asin (asin (d));
303 d = tan (tan (z));
304 z = atan (atan (d));
305 d = cosh (cosh (z));
306 z = acosh (acosh (d));
307 d = sinh (sinh (z));
308 z = asinh (asinh (d));
309 d = tanh (tanh (z));
310 z = atanh (atanh (d));
311 d = exp (exp (z));
312 z = log (log (d));
313 d = sqrt (sqrt (z));
314 z = conj (conj (d));
315 d = fabs (conj (a));
316 z = pow (pow (a, d), pow (b, z));
317 d = cproj (cproj (z));
318 z += fabs (cproj (a));
319 a = carg (carg (z));
320 b = creal (creal (d));
321 c = cimag (cimag (z));
322 x += a + b + c + i + j + k;
323 z += d;
325 if (saved_count != count)
326 count = -10000;
328 if (0)
330 a = cos (y);
331 a = acos (y);
332 a = sin (y);
333 a = asin (y);
334 a = tan (y);
335 a = atan (y);
336 a = atan2 (y, y);
337 a = cosh (y);
338 a = acosh (y);
339 a = sinh (y);
340 a = asinh (y);
341 a = tanh (y);
342 a = atanh (y);
343 a = exp (y);
344 a = log (y);
345 a = log10 (y);
346 a = ldexp (y, 5);
347 a = frexp (y, &i);
348 a = expm1 (y);
349 a = log1p (y);
350 a = logb (y);
351 a = exp2 (y);
352 a = log2 (y);
353 a = pow (y, y);
354 a = sqrt (y);
355 a = hypot (y, y);
356 a = cbrt (y);
357 a = ceil (y);
358 a = fabs (y);
359 a = floor (y);
360 a = fmod (y, y);
361 a = nearbyint (y);
362 a = round (y);
363 a = trunc (y);
364 a = remquo (y, y, &i);
365 j = lrint (y) + lround (y);
366 k = llrint (y) + llround (y);
367 a = erf (y);
368 a = erfc (y);
369 a = tgamma (y);
370 a = lgamma (y);
371 a = rint (y);
372 a = nextafter (y, y);
373 a = nexttoward (y, y);
374 a = remainder (y, y);
375 a = scalb (y, (const TYPE) (6));
376 k = scalbn (y, 7) + scalbln (y, 10l);
377 i = ilogb (y);
378 a = fdim (y, y);
379 a = fmax (y, y);
380 a = fmin (y, y);
381 a = fma (y, y, y);
383 #ifdef TEST_INT
384 a = atan2 (i, y);
385 a = remquo (i, y, &i);
386 a = fma (i, y, i);
387 a = pow (i, y);
388 #endif
390 d = cos ((const complex TYPE) z);
391 d = acos ((const complex TYPE) z);
392 d = sin ((const complex TYPE) z);
393 d = asin ((const complex TYPE) z);
394 d = tan ((const complex TYPE) z);
395 d = atan ((const complex TYPE) z);
396 d = cosh ((const complex TYPE) z);
397 d = acosh ((const complex TYPE) z);
398 d = sinh ((const complex TYPE) z);
399 d = asinh ((const complex TYPE) z);
400 d = tanh ((const complex TYPE) z);
401 d = atanh ((const complex TYPE) z);
402 d = exp ((const complex TYPE) z);
403 d = log ((const complex TYPE) z);
404 d = sqrt ((const complex TYPE) z);
405 d = pow ((const complex TYPE) z, (const complex TYPE) z);
406 d = fabs ((const complex TYPE) z);
407 d = carg ((const complex TYPE) z);
408 d = creal ((const complex TYPE) z);
409 d = cimag ((const complex TYPE) z);
410 d = conj ((const complex TYPE) z);
411 d = cproj ((const complex TYPE) z);
414 #undef x
415 #undef y
416 #undef z
419 TYPE
420 (F(cos)) (TYPE x)
422 ++count;
423 P ();
424 return x;
427 TYPE
428 (F(acos)) (TYPE x)
430 ++count;
431 P ();
432 return x;
435 TYPE
436 (F(sin)) (TYPE x)
438 ++count;
439 P ();
440 return x;
443 TYPE
444 (F(asin)) (TYPE x)
446 ++count;
447 P ();
448 return x;
451 TYPE
452 (F(tan)) (TYPE x)
454 ++count;
455 P ();
456 return x;
459 TYPE
460 (F(atan)) (TYPE x)
462 ++count;
463 P ();
464 return x;
467 TYPE
468 (F(atan2)) (TYPE x, TYPE y)
470 ++count;
471 P ();
472 return x + y;
475 TYPE
476 (F(cosh)) (TYPE x)
478 ++count;
479 P ();
480 return x;
483 TYPE
484 (F(acosh)) (TYPE x)
486 ++count;
487 P ();
488 return x;
491 TYPE
492 (F(sinh)) (TYPE x)
494 ++count;
495 P ();
496 return x;
499 TYPE
500 (F(asinh)) (TYPE x)
502 ++count;
503 P ();
504 return x;
507 TYPE
508 (F(tanh)) (TYPE x)
510 ++count;
511 P ();
512 return x;
515 TYPE
516 (F(atanh)) (TYPE x)
518 ++count;
519 P ();
520 return x;
523 TYPE
524 (F(exp)) (TYPE x)
526 ++count;
527 P ();
528 return x;
531 TYPE
532 (F(log)) (TYPE x)
534 ++count;
535 P ();
536 return x;
539 TYPE
540 (F(log10)) (TYPE x)
542 ++count;
543 P ();
544 return x;
547 TYPE
548 (F(ldexp)) (TYPE x, int y)
550 ++count;
551 P ();
552 return x + y;
555 TYPE
556 (F(frexp)) (TYPE x, int *y)
558 ++count;
559 P ();
560 return x + *y;
563 TYPE
564 (F(expm1)) (TYPE x)
566 ++count;
567 P ();
568 return x;
571 TYPE
572 (F(log1p)) (TYPE x)
574 ++count;
575 P ();
576 return x;
579 TYPE
580 (F(logb)) (TYPE x)
582 ++count;
583 P ();
584 return x;
587 TYPE
588 (F(exp2)) (TYPE x)
590 ++count;
591 P ();
592 return x;
595 TYPE
596 (F(log2)) (TYPE x)
598 ++count;
599 P ();
600 return x;
603 TYPE
604 (F(pow)) (TYPE x, TYPE y)
606 ++count;
607 P ();
608 return x + y;
611 TYPE
612 (F(sqrt)) (TYPE x)
614 ++count;
615 P ();
616 return x;
619 TYPE
620 (F(hypot)) (TYPE x, TYPE y)
622 ++count;
623 P ();
624 return x + y;
627 TYPE
628 (F(cbrt)) (TYPE x)
630 ++count;
631 P ();
632 return x;
635 TYPE
636 (F(ceil)) (TYPE x)
638 ++count;
639 P ();
640 return x;
643 TYPE
644 (F(fabs)) (TYPE x)
646 ++count;
647 P ();
648 return x;
651 TYPE
652 (F(floor)) (TYPE x)
654 ++count;
655 P ();
656 return x;
659 TYPE
660 (F(fmod)) (TYPE x, TYPE y)
662 ++count;
663 P ();
664 return x + y;
667 TYPE
668 (F(nearbyint)) (TYPE x)
670 ++count;
671 P ();
672 return x;
675 TYPE
676 (F(round)) (TYPE x)
678 ++count;
679 P ();
680 return x;
683 TYPE
684 (F(trunc)) (TYPE x)
686 ++count;
687 P ();
688 return x;
691 TYPE
692 (F(remquo)) (TYPE x, TYPE y, int *i)
694 ++count;
695 P ();
696 return x + y + *i;
699 long int
700 (F(lrint)) (TYPE x)
702 ++count;
703 P ();
704 return x;
707 long int
708 (F(lround)) (TYPE x)
710 ++count;
711 P ();
712 return x;
715 long long int
716 (F(llrint)) (TYPE x)
718 ++count;
719 P ();
720 return x;
723 long long int
724 (F(llround)) (TYPE x)
726 ++count;
727 P ();
728 return x;
731 TYPE
732 (F(erf)) (TYPE x)
734 ++count;
735 P ();
736 return x;
739 TYPE
740 (F(erfc)) (TYPE x)
742 ++count;
743 P ();
744 return x;
747 TYPE
748 (F(tgamma)) (TYPE x)
750 ++count;
751 P ();
752 return x;
755 TYPE
756 (F(lgamma)) (TYPE x)
758 ++count;
759 P ();
760 return x;
763 TYPE
764 (F(rint)) (TYPE x)
766 ++count;
767 P ();
768 return x;
771 TYPE
772 (F(nextafter)) (TYPE x, TYPE y)
774 ++count;
775 P ();
776 return x + y;
779 TYPE
780 (F(nexttoward)) (TYPE x, long double y)
782 ++count;
783 P ();
784 return x + y;
787 TYPE
788 (F(remainder)) (TYPE x, TYPE y)
790 ++count;
791 P ();
792 return x + y;
795 TYPE
796 (F(scalb)) (TYPE x, TYPE y)
798 ++count;
799 P ();
800 return x + y;
803 TYPE
804 (F(scalbn)) (TYPE x, int y)
806 ++count;
807 P ();
808 return x + y;
811 TYPE
812 (F(scalbln)) (TYPE x, long int y)
814 ++count;
815 P ();
816 return x + y;
820 (F(ilogb)) (TYPE x)
822 ++count;
823 P ();
824 return x;
827 TYPE
828 (F(fdim)) (TYPE x, TYPE y)
830 ++count;
831 P ();
832 return x + y;
835 TYPE
836 (F(fmin)) (TYPE x, TYPE y)
838 ++count;
839 P ();
840 return x + y;
843 TYPE
844 (F(fmax)) (TYPE x, TYPE y)
846 ++count;
847 P ();
848 return x + y;
851 TYPE
852 (F(fma)) (TYPE x, TYPE y, TYPE z)
854 ++count;
855 P ();
856 return x + y + z;
859 complex TYPE
860 (F(cacos)) (complex TYPE x)
862 ++ccount;
863 P ();
864 return x;
867 complex TYPE
868 (F(casin)) (complex TYPE x)
870 ++ccount;
871 P ();
872 return x;
875 complex TYPE
876 (F(catan)) (complex TYPE x)
878 ++ccount;
879 P ();
880 return x;
883 complex TYPE
884 (F(ccos)) (complex TYPE x)
886 ++ccount;
887 P ();
888 return x;
891 complex TYPE
892 (F(csin)) (complex TYPE x)
894 ++ccount;
895 P ();
896 return x;
899 complex TYPE
900 (F(ctan)) (complex TYPE x)
902 ++ccount;
903 P ();
904 return x;
907 complex TYPE
908 (F(cacosh)) (complex TYPE x)
910 ++ccount;
911 P ();
912 return x;
915 complex TYPE
916 (F(casinh)) (complex TYPE x)
918 ++ccount;
919 P ();
920 return x;
923 complex TYPE
924 (F(catanh)) (complex TYPE x)
926 ++ccount;
927 P ();
928 return x;
931 complex TYPE
932 (F(ccosh)) (complex TYPE x)
934 ++ccount;
935 P ();
936 return x;
939 complex TYPE
940 (F(csinh)) (complex TYPE x)
942 ++ccount;
943 P ();
944 return x;
947 complex TYPE
948 (F(ctanh)) (complex TYPE x)
950 ++ccount;
951 P ();
952 return x;
955 complex TYPE
956 (F(cexp)) (complex TYPE x)
958 ++ccount;
959 P ();
960 return x;
963 complex TYPE
964 (F(clog)) (complex TYPE x)
966 ++ccount;
967 P ();
968 return x;
971 complex TYPE
972 (F(csqrt)) (complex TYPE x)
974 ++ccount;
975 P ();
976 return x;
979 complex TYPE
980 (F(cpow)) (complex TYPE x, complex TYPE y)
982 ++ccount;
983 P ();
984 return x + y;
987 TYPE
988 (F(cabs)) (complex TYPE x)
990 ++ccount;
991 P ();
992 return x;
995 TYPE
996 (F(carg)) (complex TYPE x)
998 ++ccount;
999 P ();
1000 return x;
1003 TYPE
1004 (F(creal)) (complex TYPE x)
1006 ++ccount;
1007 P ();
1008 return __real__ x;
1011 TYPE
1012 (F(cimag)) (complex TYPE x)
1014 ++ccount;
1015 P ();
1016 return __imag__ x;
1019 complex TYPE
1020 (F(conj)) (complex TYPE x)
1022 ++ccount;
1023 P ();
1024 return x;
1027 complex TYPE
1028 (F(cproj)) (complex TYPE x)
1030 ++ccount;
1031 P ();
1032 return x;
1035 #undef F
1036 #undef TYPE
1037 #undef count
1038 #undef ccount
1039 #undef TEST_INT
1040 #endif