Add roundeven, roundevenf, roundevenl.
[glibc.git] / math / test-tgmath.c
blob7a58d99985d5d98eb4aa20fb6c4113f9a4bac695
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 134
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 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 a = erf (erf (x));
273 b = erfc (erfc (a));
274 a = tgamma (tgamma (x));
275 b = lgamma (lgamma (a));
276 a = rint (rint (x));
277 b = nextafter (nextafter (a, b), nextafter (c, x));
278 a = nextdown (nextdown (a));
279 b = nexttoward (nexttoward (x, a), c);
280 a = nextup (nextup (a));
281 b = remainder (remainder (a, b), remainder (c, x));
282 a = scalb (scalb (x, a), (TYPE) (6));
283 k = scalbn (a, 7) + scalbln (c, 10l);
284 i = ilogb (x);
285 j = llogb (x);
286 a = fdim (fdim (x, a), fdim (c, b));
287 b = fmax (fmax (a, x), fmax (c, b));
288 a = fmin (fmin (x, a), fmin (c, b));
289 b = fmaxmag (fmaxmag (a, x), fmaxmag (c, b));
290 a = fminmag (fminmag (x, a), fminmag (c, b));
291 b = fma (sin (a), sin (x), sin (c));
292 a = totalorder (totalorder (x, b), totalorder (c, x));
293 b = totalordermag (totalordermag (x, a), totalordermag (c, x));
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;
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 a = erf (y);
377 a = erfc (y);
378 a = tgamma (y);
379 a = lgamma (y);
380 a = rint (y);
381 a = nextafter (y, y);
382 a = nexttoward (y, y);
383 a = remainder (y, y);
384 a = scalb (y, (const TYPE) (6));
385 k = scalbn (y, 7) + scalbln (y, 10l);
386 i = ilogb (y);
387 j = llogb (y);
388 a = fdim (y, y);
389 a = fmax (y, y);
390 a = fmin (y, y);
391 a = fmaxmag (y, y);
392 a = fminmag (y, y);
393 a = fma (y, y, y);
394 a = totalorder (y, y);
395 a = totalordermag (y, y);
397 #ifdef TEST_INT
398 a = atan2 (i, y);
399 a = remquo (i, y, &i);
400 a = fma (i, y, i);
401 a = pow (i, y);
402 #endif
404 d = cos ((const complex TYPE) z);
405 d = acos ((const complex TYPE) z);
406 d = sin ((const complex TYPE) z);
407 d = asin ((const complex TYPE) z);
408 d = tan ((const complex TYPE) z);
409 d = atan ((const complex TYPE) z);
410 d = cosh ((const complex TYPE) z);
411 d = acosh ((const complex TYPE) z);
412 d = sinh ((const complex TYPE) z);
413 d = asinh ((const complex TYPE) z);
414 d = tanh ((const complex TYPE) z);
415 d = atanh ((const complex TYPE) z);
416 d = exp ((const complex TYPE) z);
417 d = log ((const complex TYPE) z);
418 d = sqrt ((const complex TYPE) z);
419 d = pow ((const complex TYPE) z, (const complex TYPE) z);
420 d = fabs ((const complex TYPE) z);
421 d = carg ((const complex TYPE) z);
422 d = creal ((const complex TYPE) z);
423 d = cimag ((const complex TYPE) z);
424 d = conj ((const complex TYPE) z);
425 d = cproj ((const complex TYPE) z);
428 #undef x
429 #undef y
430 #undef z
433 TYPE
434 (F(cos)) (TYPE x)
436 ++count;
437 P ();
438 return x;
441 TYPE
442 (F(acos)) (TYPE x)
444 ++count;
445 P ();
446 return x;
449 TYPE
450 (F(sin)) (TYPE x)
452 ++count;
453 P ();
454 return x;
457 TYPE
458 (F(asin)) (TYPE x)
460 ++count;
461 P ();
462 return x;
465 TYPE
466 (F(tan)) (TYPE x)
468 ++count;
469 P ();
470 return x;
473 TYPE
474 (F(atan)) (TYPE x)
476 ++count;
477 P ();
478 return x;
481 TYPE
482 (F(atan2)) (TYPE x, TYPE y)
484 ++count;
485 P ();
486 return x + y;
489 TYPE
490 (F(cosh)) (TYPE x)
492 ++count;
493 P ();
494 return x;
497 TYPE
498 (F(acosh)) (TYPE x)
500 ++count;
501 P ();
502 return x;
505 TYPE
506 (F(sinh)) (TYPE x)
508 ++count;
509 P ();
510 return x;
513 TYPE
514 (F(asinh)) (TYPE x)
516 ++count;
517 P ();
518 return x;
521 TYPE
522 (F(tanh)) (TYPE x)
524 ++count;
525 P ();
526 return x;
529 TYPE
530 (F(atanh)) (TYPE x)
532 ++count;
533 P ();
534 return x;
537 TYPE
538 (F(exp)) (TYPE x)
540 ++count;
541 P ();
542 return x;
545 TYPE
546 (F(log)) (TYPE x)
548 ++count;
549 P ();
550 return x;
553 TYPE
554 (F(log10)) (TYPE x)
556 ++count;
557 P ();
558 return x;
561 TYPE
562 (F(ldexp)) (TYPE x, int y)
564 ++count;
565 P ();
566 return x + y;
569 TYPE
570 (F(frexp)) (TYPE x, int *y)
572 ++count;
573 P ();
574 return x + *y;
577 TYPE
578 (F(expm1)) (TYPE x)
580 ++count;
581 P ();
582 return x;
585 TYPE
586 (F(log1p)) (TYPE x)
588 ++count;
589 P ();
590 return x;
593 TYPE
594 (F(logb)) (TYPE x)
596 ++count;
597 P ();
598 return x;
601 TYPE
602 (F(exp2)) (TYPE x)
604 ++count;
605 P ();
606 return x;
609 TYPE
610 (F(log2)) (TYPE x)
612 ++count;
613 P ();
614 return x;
617 TYPE
618 (F(pow)) (TYPE x, TYPE y)
620 ++count;
621 P ();
622 return x + y;
625 TYPE
626 (F(sqrt)) (TYPE x)
628 ++count;
629 P ();
630 return x;
633 TYPE
634 (F(hypot)) (TYPE x, TYPE y)
636 ++count;
637 P ();
638 return x + y;
641 TYPE
642 (F(cbrt)) (TYPE x)
644 ++count;
645 P ();
646 return x;
649 TYPE
650 (F(ceil)) (TYPE x)
652 ++count;
653 P ();
654 return x;
657 TYPE
658 (F(fabs)) (TYPE x)
660 ++count;
661 P ();
662 return x;
665 TYPE
666 (F(floor)) (TYPE x)
668 ++count;
669 P ();
670 return x;
673 TYPE
674 (F(fmod)) (TYPE x, TYPE y)
676 ++count;
677 P ();
678 return x + y;
681 TYPE
682 (F(nearbyint)) (TYPE x)
684 ++count;
685 P ();
686 return x;
689 TYPE
690 (F(round)) (TYPE x)
692 ++count;
693 P ();
694 return x;
697 TYPE
698 (F(roundeven)) (TYPE x)
700 ++count;
701 P ();
702 return x;
705 TYPE
706 (F(trunc)) (TYPE x)
708 ++count;
709 P ();
710 return x;
713 TYPE
714 (F(remquo)) (TYPE x, TYPE y, int *i)
716 ++count;
717 P ();
718 return x + y + *i;
721 long int
722 (F(lrint)) (TYPE x)
724 ++count;
725 P ();
726 return x;
729 long int
730 (F(lround)) (TYPE x)
732 ++count;
733 P ();
734 return x;
737 long long int
738 (F(llrint)) (TYPE x)
740 ++count;
741 P ();
742 return x;
745 long long int
746 (F(llround)) (TYPE x)
748 ++count;
749 P ();
750 return x;
753 TYPE
754 (F(erf)) (TYPE x)
756 ++count;
757 P ();
758 return x;
761 TYPE
762 (F(erfc)) (TYPE x)
764 ++count;
765 P ();
766 return x;
769 TYPE
770 (F(tgamma)) (TYPE x)
772 ++count;
773 P ();
774 return x;
777 TYPE
778 (F(lgamma)) (TYPE x)
780 ++count;
781 P ();
782 return x;
785 TYPE
786 (F(rint)) (TYPE x)
788 ++count;
789 P ();
790 return x;
793 TYPE
794 (F(nextafter)) (TYPE x, TYPE y)
796 ++count;
797 P ();
798 return x + y;
801 TYPE
802 (F(nextdown)) (TYPE x)
804 ++count;
805 P ();
806 return x;
809 TYPE
810 (F(nexttoward)) (TYPE x, long double y)
812 ++count;
813 P ();
814 return x + y;
817 TYPE
818 (F(nextup)) (TYPE x)
820 ++count;
821 P ();
822 return x;
825 TYPE
826 (F(remainder)) (TYPE x, TYPE y)
828 ++count;
829 P ();
830 return x + y;
833 TYPE
834 (F(scalb)) (TYPE x, TYPE y)
836 ++count;
837 P ();
838 return x + y;
841 TYPE
842 (F(scalbn)) (TYPE x, int y)
844 ++count;
845 P ();
846 return x + y;
849 TYPE
850 (F(scalbln)) (TYPE x, long int y)
852 ++count;
853 P ();
854 return x + y;
858 (F(ilogb)) (TYPE x)
860 ++count;
861 P ();
862 return x;
865 long int
866 (F(llogb)) (TYPE x)
868 ++count;
869 P ();
870 return x;
873 TYPE
874 (F(fdim)) (TYPE x, TYPE y)
876 ++count;
877 P ();
878 return x + y;
881 TYPE
882 (F(fmin)) (TYPE x, TYPE y)
884 ++count;
885 P ();
886 return x + y;
889 TYPE
890 (F(fmax)) (TYPE x, TYPE y)
892 ++count;
893 P ();
894 return x + y;
897 TYPE
898 (F(fminmag)) (TYPE x, TYPE y)
900 ++count;
901 P ();
902 return x + y;
905 TYPE
906 (F(fmaxmag)) (TYPE x, TYPE y)
908 ++count;
909 P ();
910 return x + y;
913 TYPE
914 (F(fma)) (TYPE x, TYPE y, TYPE z)
916 ++count;
917 P ();
918 return x + y + z;
922 (F(totalorder)) (TYPE x, TYPE y)
924 ++count;
925 P ();
926 return x + y;
930 (F(totalordermag)) (TYPE x, TYPE y)
932 ++count;
933 P ();
934 return x + y;
937 complex TYPE
938 (F(cacos)) (complex TYPE x)
940 ++ccount;
941 P ();
942 return x;
945 complex TYPE
946 (F(casin)) (complex TYPE x)
948 ++ccount;
949 P ();
950 return x;
953 complex TYPE
954 (F(catan)) (complex TYPE x)
956 ++ccount;
957 P ();
958 return x;
961 complex TYPE
962 (F(ccos)) (complex TYPE x)
964 ++ccount;
965 P ();
966 return x;
969 complex TYPE
970 (F(csin)) (complex TYPE x)
972 ++ccount;
973 P ();
974 return x;
977 complex TYPE
978 (F(ctan)) (complex TYPE x)
980 ++ccount;
981 P ();
982 return x;
985 complex TYPE
986 (F(cacosh)) (complex TYPE x)
988 ++ccount;
989 P ();
990 return x;
993 complex TYPE
994 (F(casinh)) (complex TYPE x)
996 ++ccount;
997 P ();
998 return x;
1001 complex TYPE
1002 (F(catanh)) (complex TYPE x)
1004 ++ccount;
1005 P ();
1006 return x;
1009 complex TYPE
1010 (F(ccosh)) (complex TYPE x)
1012 ++ccount;
1013 P ();
1014 return x;
1017 complex TYPE
1018 (F(csinh)) (complex TYPE x)
1020 ++ccount;
1021 P ();
1022 return x;
1025 complex TYPE
1026 (F(ctanh)) (complex TYPE x)
1028 ++ccount;
1029 P ();
1030 return x;
1033 complex TYPE
1034 (F(cexp)) (complex TYPE x)
1036 ++ccount;
1037 P ();
1038 return x;
1041 complex TYPE
1042 (F(clog)) (complex TYPE x)
1044 ++ccount;
1045 P ();
1046 return x;
1049 complex TYPE
1050 (F(csqrt)) (complex TYPE x)
1052 ++ccount;
1053 P ();
1054 return x;
1057 complex TYPE
1058 (F(cpow)) (complex TYPE x, complex TYPE y)
1060 ++ccount;
1061 P ();
1062 return x + y;
1065 TYPE
1066 (F(cabs)) (complex TYPE x)
1068 ++ccount;
1069 P ();
1070 return x;
1073 TYPE
1074 (F(carg)) (complex TYPE x)
1076 ++ccount;
1077 P ();
1078 return x;
1081 TYPE
1082 (F(creal)) (complex TYPE x)
1084 ++ccount;
1085 P ();
1086 return __real__ x;
1089 TYPE
1090 (F(cimag)) (complex TYPE x)
1092 ++ccount;
1093 P ();
1094 return __imag__ x;
1097 complex TYPE
1098 (F(conj)) (complex TYPE x)
1100 ++ccount;
1101 P ();
1102 return x;
1105 complex TYPE
1106 (F(cproj)) (complex TYPE x)
1108 ++ccount;
1109 P ();
1110 return x;
1113 #undef F
1114 #undef TYPE
1115 #undef count
1116 #undef ccount
1117 #undef TEST_INT
1118 #endif