Use __builtin_fma more in dbl-64 code.
[glibc.git] / math / test-tgmath.c
blob70ab42881a44ccd1e2885eb240dbe5bab67dcd9b
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001-2016 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 119
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 = nextdown (nextdown (a));
278 b = nexttoward (nexttoward (x, a), c);
279 a = nextup (nextup (a));
280 b = remainder (remainder (a, b), remainder (c, x));
281 a = scalb (scalb (x, a), (TYPE) (6));
282 k = scalbn (a, 7) + scalbln (c, 10l);
283 i = ilogb (x);
284 a = fdim (fdim (x, a), fdim (c, b));
285 b = fmax (fmax (a, x), fmax (c, b));
286 a = fmin (fmin (x, a), fmin (c, b));
287 b = fma (sin (a), sin (x), sin (c));
289 #ifdef TEST_INT
290 a = atan2 (i, b);
291 b = remquo (i, a, &i);
292 c = fma (i, b, i);
293 a = pow (i, c);
294 #endif
295 x = a + b + c + i + j + k;
297 saved_count = count;
298 if (ccount != 0)
299 ccount = -10000;
301 d = cos (cos (z));
302 z = acos (acos (d));
303 d = sin (sin (z));
304 z = asin (asin (d));
305 d = tan (tan (z));
306 z = atan (atan (d));
307 d = cosh (cosh (z));
308 z = acosh (acosh (d));
309 d = sinh (sinh (z));
310 z = asinh (asinh (d));
311 d = tanh (tanh (z));
312 z = atanh (atanh (d));
313 d = exp (exp (z));
314 z = log (log (d));
315 d = sqrt (sqrt (z));
316 z = conj (conj (d));
317 d = fabs (conj (a));
318 z = pow (pow (a, d), pow (b, z));
319 d = cproj (cproj (z));
320 z += fabs (cproj (a));
321 a = carg (carg (z));
322 b = creal (creal (d));
323 c = cimag (cimag (z));
324 x += a + b + c + i + j + k;
325 z += d;
327 if (saved_count != count)
328 count = -10000;
330 if (0)
332 a = cos (y);
333 a = acos (y);
334 a = sin (y);
335 a = asin (y);
336 a = tan (y);
337 a = atan (y);
338 a = atan2 (y, y);
339 a = cosh (y);
340 a = acosh (y);
341 a = sinh (y);
342 a = asinh (y);
343 a = tanh (y);
344 a = atanh (y);
345 a = exp (y);
346 a = log (y);
347 a = log10 (y);
348 a = ldexp (y, 5);
349 a = frexp (y, &i);
350 a = expm1 (y);
351 a = log1p (y);
352 a = logb (y);
353 a = exp2 (y);
354 a = log2 (y);
355 a = pow (y, y);
356 a = sqrt (y);
357 a = hypot (y, y);
358 a = cbrt (y);
359 a = ceil (y);
360 a = fabs (y);
361 a = floor (y);
362 a = fmod (y, y);
363 a = nearbyint (y);
364 a = round (y);
365 a = trunc (y);
366 a = remquo (y, y, &i);
367 j = lrint (y) + lround (y);
368 k = llrint (y) + llround (y);
369 a = erf (y);
370 a = erfc (y);
371 a = tgamma (y);
372 a = lgamma (y);
373 a = rint (y);
374 a = nextafter (y, y);
375 a = nexttoward (y, y);
376 a = remainder (y, y);
377 a = scalb (y, (const TYPE) (6));
378 k = scalbn (y, 7) + scalbln (y, 10l);
379 i = ilogb (y);
380 a = fdim (y, y);
381 a = fmax (y, y);
382 a = fmin (y, y);
383 a = fma (y, y, y);
385 #ifdef TEST_INT
386 a = atan2 (i, y);
387 a = remquo (i, y, &i);
388 a = fma (i, y, i);
389 a = pow (i, y);
390 #endif
392 d = cos ((const complex TYPE) z);
393 d = acos ((const complex TYPE) z);
394 d = sin ((const complex TYPE) z);
395 d = asin ((const complex TYPE) z);
396 d = tan ((const complex TYPE) z);
397 d = atan ((const complex TYPE) z);
398 d = cosh ((const complex TYPE) z);
399 d = acosh ((const complex TYPE) z);
400 d = sinh ((const complex TYPE) z);
401 d = asinh ((const complex TYPE) z);
402 d = tanh ((const complex TYPE) z);
403 d = atanh ((const complex TYPE) z);
404 d = exp ((const complex TYPE) z);
405 d = log ((const complex TYPE) z);
406 d = sqrt ((const complex TYPE) z);
407 d = pow ((const complex TYPE) z, (const complex TYPE) z);
408 d = fabs ((const complex TYPE) z);
409 d = carg ((const complex TYPE) z);
410 d = creal ((const complex TYPE) z);
411 d = cimag ((const complex TYPE) z);
412 d = conj ((const complex TYPE) z);
413 d = cproj ((const complex TYPE) z);
416 #undef x
417 #undef y
418 #undef z
421 TYPE
422 (F(cos)) (TYPE x)
424 ++count;
425 P ();
426 return x;
429 TYPE
430 (F(acos)) (TYPE x)
432 ++count;
433 P ();
434 return x;
437 TYPE
438 (F(sin)) (TYPE x)
440 ++count;
441 P ();
442 return x;
445 TYPE
446 (F(asin)) (TYPE x)
448 ++count;
449 P ();
450 return x;
453 TYPE
454 (F(tan)) (TYPE x)
456 ++count;
457 P ();
458 return x;
461 TYPE
462 (F(atan)) (TYPE x)
464 ++count;
465 P ();
466 return x;
469 TYPE
470 (F(atan2)) (TYPE x, TYPE y)
472 ++count;
473 P ();
474 return x + y;
477 TYPE
478 (F(cosh)) (TYPE x)
480 ++count;
481 P ();
482 return x;
485 TYPE
486 (F(acosh)) (TYPE x)
488 ++count;
489 P ();
490 return x;
493 TYPE
494 (F(sinh)) (TYPE x)
496 ++count;
497 P ();
498 return x;
501 TYPE
502 (F(asinh)) (TYPE x)
504 ++count;
505 P ();
506 return x;
509 TYPE
510 (F(tanh)) (TYPE x)
512 ++count;
513 P ();
514 return x;
517 TYPE
518 (F(atanh)) (TYPE x)
520 ++count;
521 P ();
522 return x;
525 TYPE
526 (F(exp)) (TYPE x)
528 ++count;
529 P ();
530 return x;
533 TYPE
534 (F(log)) (TYPE x)
536 ++count;
537 P ();
538 return x;
541 TYPE
542 (F(log10)) (TYPE x)
544 ++count;
545 P ();
546 return x;
549 TYPE
550 (F(ldexp)) (TYPE x, int y)
552 ++count;
553 P ();
554 return x + y;
557 TYPE
558 (F(frexp)) (TYPE x, int *y)
560 ++count;
561 P ();
562 return x + *y;
565 TYPE
566 (F(expm1)) (TYPE x)
568 ++count;
569 P ();
570 return x;
573 TYPE
574 (F(log1p)) (TYPE x)
576 ++count;
577 P ();
578 return x;
581 TYPE
582 (F(logb)) (TYPE x)
584 ++count;
585 P ();
586 return x;
589 TYPE
590 (F(exp2)) (TYPE x)
592 ++count;
593 P ();
594 return x;
597 TYPE
598 (F(log2)) (TYPE x)
600 ++count;
601 P ();
602 return x;
605 TYPE
606 (F(pow)) (TYPE x, TYPE y)
608 ++count;
609 P ();
610 return x + y;
613 TYPE
614 (F(sqrt)) (TYPE x)
616 ++count;
617 P ();
618 return x;
621 TYPE
622 (F(hypot)) (TYPE x, TYPE y)
624 ++count;
625 P ();
626 return x + y;
629 TYPE
630 (F(cbrt)) (TYPE x)
632 ++count;
633 P ();
634 return x;
637 TYPE
638 (F(ceil)) (TYPE x)
640 ++count;
641 P ();
642 return x;
645 TYPE
646 (F(fabs)) (TYPE x)
648 ++count;
649 P ();
650 return x;
653 TYPE
654 (F(floor)) (TYPE x)
656 ++count;
657 P ();
658 return x;
661 TYPE
662 (F(fmod)) (TYPE x, TYPE y)
664 ++count;
665 P ();
666 return x + y;
669 TYPE
670 (F(nearbyint)) (TYPE x)
672 ++count;
673 P ();
674 return x;
677 TYPE
678 (F(round)) (TYPE x)
680 ++count;
681 P ();
682 return x;
685 TYPE
686 (F(trunc)) (TYPE x)
688 ++count;
689 P ();
690 return x;
693 TYPE
694 (F(remquo)) (TYPE x, TYPE y, int *i)
696 ++count;
697 P ();
698 return x + y + *i;
701 long int
702 (F(lrint)) (TYPE x)
704 ++count;
705 P ();
706 return x;
709 long int
710 (F(lround)) (TYPE x)
712 ++count;
713 P ();
714 return x;
717 long long int
718 (F(llrint)) (TYPE x)
720 ++count;
721 P ();
722 return x;
725 long long int
726 (F(llround)) (TYPE x)
728 ++count;
729 P ();
730 return x;
733 TYPE
734 (F(erf)) (TYPE x)
736 ++count;
737 P ();
738 return x;
741 TYPE
742 (F(erfc)) (TYPE x)
744 ++count;
745 P ();
746 return x;
749 TYPE
750 (F(tgamma)) (TYPE x)
752 ++count;
753 P ();
754 return x;
757 TYPE
758 (F(lgamma)) (TYPE x)
760 ++count;
761 P ();
762 return x;
765 TYPE
766 (F(rint)) (TYPE x)
768 ++count;
769 P ();
770 return x;
773 TYPE
774 (F(nextafter)) (TYPE x, TYPE y)
776 ++count;
777 P ();
778 return x + y;
781 TYPE
782 (F(nextdown)) (TYPE x)
784 ++count;
785 P ();
786 return x;
789 TYPE
790 (F(nexttoward)) (TYPE x, long double y)
792 ++count;
793 P ();
794 return x + y;
797 TYPE
798 (F(nextup)) (TYPE x)
800 ++count;
801 P ();
802 return x;
805 TYPE
806 (F(remainder)) (TYPE x, TYPE y)
808 ++count;
809 P ();
810 return x + y;
813 TYPE
814 (F(scalb)) (TYPE x, TYPE y)
816 ++count;
817 P ();
818 return x + y;
821 TYPE
822 (F(scalbn)) (TYPE x, int y)
824 ++count;
825 P ();
826 return x + y;
829 TYPE
830 (F(scalbln)) (TYPE x, long int y)
832 ++count;
833 P ();
834 return x + y;
838 (F(ilogb)) (TYPE x)
840 ++count;
841 P ();
842 return x;
845 TYPE
846 (F(fdim)) (TYPE x, TYPE y)
848 ++count;
849 P ();
850 return x + y;
853 TYPE
854 (F(fmin)) (TYPE x, TYPE y)
856 ++count;
857 P ();
858 return x + y;
861 TYPE
862 (F(fmax)) (TYPE x, TYPE y)
864 ++count;
865 P ();
866 return x + y;
869 TYPE
870 (F(fma)) (TYPE x, TYPE y, TYPE z)
872 ++count;
873 P ();
874 return x + y + z;
877 complex TYPE
878 (F(cacos)) (complex TYPE x)
880 ++ccount;
881 P ();
882 return x;
885 complex TYPE
886 (F(casin)) (complex TYPE x)
888 ++ccount;
889 P ();
890 return x;
893 complex TYPE
894 (F(catan)) (complex TYPE x)
896 ++ccount;
897 P ();
898 return x;
901 complex TYPE
902 (F(ccos)) (complex TYPE x)
904 ++ccount;
905 P ();
906 return x;
909 complex TYPE
910 (F(csin)) (complex TYPE x)
912 ++ccount;
913 P ();
914 return x;
917 complex TYPE
918 (F(ctan)) (complex TYPE x)
920 ++ccount;
921 P ();
922 return x;
925 complex TYPE
926 (F(cacosh)) (complex TYPE x)
928 ++ccount;
929 P ();
930 return x;
933 complex TYPE
934 (F(casinh)) (complex TYPE x)
936 ++ccount;
937 P ();
938 return x;
941 complex TYPE
942 (F(catanh)) (complex TYPE x)
944 ++ccount;
945 P ();
946 return x;
949 complex TYPE
950 (F(ccosh)) (complex TYPE x)
952 ++ccount;
953 P ();
954 return x;
957 complex TYPE
958 (F(csinh)) (complex TYPE x)
960 ++ccount;
961 P ();
962 return x;
965 complex TYPE
966 (F(ctanh)) (complex TYPE x)
968 ++ccount;
969 P ();
970 return x;
973 complex TYPE
974 (F(cexp)) (complex TYPE x)
976 ++ccount;
977 P ();
978 return x;
981 complex TYPE
982 (F(clog)) (complex TYPE x)
984 ++ccount;
985 P ();
986 return x;
989 complex TYPE
990 (F(csqrt)) (complex TYPE x)
992 ++ccount;
993 P ();
994 return x;
997 complex TYPE
998 (F(cpow)) (complex TYPE x, complex TYPE y)
1000 ++ccount;
1001 P ();
1002 return x + y;
1005 TYPE
1006 (F(cabs)) (complex TYPE x)
1008 ++ccount;
1009 P ();
1010 return x;
1013 TYPE
1014 (F(carg)) (complex TYPE x)
1016 ++ccount;
1017 P ();
1018 return x;
1021 TYPE
1022 (F(creal)) (complex TYPE x)
1024 ++ccount;
1025 P ();
1026 return __real__ x;
1029 TYPE
1030 (F(cimag)) (complex TYPE x)
1032 ++ccount;
1033 P ();
1034 return __imag__ x;
1037 complex TYPE
1038 (F(conj)) (complex TYPE x)
1040 ++ccount;
1041 P ();
1042 return x;
1045 complex TYPE
1046 (F(cproj)) (complex TYPE x)
1048 ++ccount;
1049 P ();
1050 return x;
1053 #undef F
1054 #undef TYPE
1055 #undef count
1056 #undef ccount
1057 #undef TEST_INT
1058 #endif