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