float128: Add strtof128, wcstof128, and related functions.
[glibc.git] / math / test-tgmath.c
blobb38138b764ee1d7d2da501fc10468e6a2ee4b3ee
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001-2017 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 <stdint.h>
26 #include <stdio.h>
27 #include <tgmath.h>
29 //#define DEBUG
31 static void compile_test (void);
32 static void compile_testf (void);
33 #ifndef NO_LONG_DOUBLE
34 static void compile_testl (void);
35 #endif
37 float fx;
38 double dx;
39 long double lx;
40 const float fy = 1.25;
41 const double dy = 1.25;
42 const long double ly = 1.25;
43 complex float fz;
44 complex double dz;
45 complex long double lz;
47 int count_double;
48 int count_float;
49 int count_ldouble;
50 int count_cdouble;
51 int count_cfloat;
52 int count_cldouble;
54 #define NCALLS 138
55 #define NCALLS_INT 4
56 #define NCCALLS 47
58 static int
59 do_test (void)
61 int result = 0;
63 count_float = count_double = count_ldouble = 0;
64 count_cfloat = count_cdouble = count_cldouble = 0;
65 compile_test ();
66 if (count_float != 0 || count_cfloat != 0)
68 puts ("float function called for double test");
69 result = 1;
71 if (count_ldouble != 0 || count_cldouble != 0)
73 puts ("long double function called for double test");
74 result = 1;
76 if (count_double < NCALLS + NCALLS_INT)
78 printf ("double functions not called often enough (%d)\n",
79 count_double);
80 result = 1;
82 else if (count_double > NCALLS + NCALLS_INT)
84 printf ("double functions called too often (%d)\n",
85 count_double);
86 result = 1;
88 if (count_cdouble < NCCALLS)
90 printf ("double complex functions not called often enough (%d)\n",
91 count_cdouble);
92 result = 1;
94 else if (count_cdouble > NCCALLS)
96 printf ("double complex functions called too often (%d)\n",
97 count_cdouble);
98 result = 1;
101 count_float = count_double = count_ldouble = 0;
102 count_cfloat = count_cdouble = count_cldouble = 0;
103 compile_testf ();
104 if (count_double != 0 || count_cdouble != 0)
106 puts ("double function called for float test");
107 result = 1;
109 if (count_ldouble != 0 || count_cldouble != 0)
111 puts ("long double function called for float test");
112 result = 1;
114 if (count_float < NCALLS)
116 printf ("float functions not called often enough (%d)\n", count_float);
117 result = 1;
119 else if (count_float > NCALLS)
121 printf ("float functions called too often (%d)\n",
122 count_double);
123 result = 1;
125 if (count_cfloat < NCCALLS)
127 printf ("float complex functions not called often enough (%d)\n",
128 count_cfloat);
129 result = 1;
131 else if (count_cfloat > NCCALLS)
133 printf ("float complex functions called too often (%d)\n",
134 count_cfloat);
135 result = 1;
138 #ifndef NO_LONG_DOUBLE
139 count_float = count_double = count_ldouble = 0;
140 count_cfloat = count_cdouble = count_cldouble = 0;
141 compile_testl ();
142 if (count_float != 0 || count_cfloat != 0)
144 puts ("float function called for long double test");
145 result = 1;
147 if (count_double != 0 || count_cdouble != 0)
149 puts ("double function called for long double test");
150 result = 1;
152 if (count_ldouble < NCALLS)
154 printf ("long double functions not called often enough (%d)\n",
155 count_ldouble);
156 result = 1;
158 else if (count_ldouble > NCALLS)
160 printf ("long double functions called too often (%d)\n",
161 count_double);
162 result = 1;
164 if (count_cldouble < NCCALLS)
166 printf ("long double complex functions not called often enough (%d)\n",
167 count_cldouble);
168 result = 1;
170 else if (count_cldouble > NCCALLS)
172 printf ("long double complex functions called too often (%d)\n",
173 count_cldouble);
174 result = 1;
176 #endif
178 return result;
181 /* Now generate the three functions. */
182 #define HAVE_MAIN
184 #define F(name) name
185 #define TYPE double
186 #define TEST_INT 1
187 #define x dx
188 #define y dy
189 #define z dz
190 #define count count_double
191 #define ccount count_cdouble
192 #include "test-tgmath.c"
194 #define F(name) name##f
195 #define TYPE float
196 #define x fx
197 #define y fy
198 #define z fz
199 #define count count_float
200 #define ccount count_cfloat
201 #include "test-tgmath.c"
203 #ifndef NO_LONG_DOUBLE
204 #define F(name) name##l
205 #define TYPE long double
206 #define x lx
207 #define y ly
208 #define z lz
209 #define count count_ldouble
210 #define ccount count_cldouble
211 #include "test-tgmath.c"
212 #endif
214 #define TEST_FUNCTION do_test ()
215 #include "../test-skeleton.c"
217 #else
219 #ifdef DEBUG
220 #define P() puts (__FUNCTION__)
221 #else
222 #define P()
223 #endif
225 static void
226 F(compile_test) (void)
228 TYPE a, b, c = 1.0;
229 complex TYPE d;
230 int i = 2;
231 int saved_count;
232 long int j;
233 long long int k;
234 intmax_t m;
235 uintmax_t um;
237 a = cos (cos (x));
238 b = acos (acos (a));
239 a = sin (sin (x));
240 b = asin (asin (a));
241 a = tan (tan (x));
242 b = atan (atan (a));
243 c = atan2 (atan2 (a, c), atan2 (b, x));
244 a = cosh (cosh (x));
245 b = acosh (acosh (a));
246 a = sinh (sinh (x));
247 b = asinh (asinh (a));
248 a = tanh (tanh (x));
249 b = atanh (atanh (a));
250 a = exp (exp (x));
251 b = log (log (a));
252 a = log10 (log10 (x));
253 b = ldexp (ldexp (a, 1), 5);
254 a = frexp (frexp (x, &i), &i);
255 b = expm1 (expm1 (a));
256 a = log1p (log1p (x));
257 b = logb (logb (a));
258 a = exp2 (exp2 (x));
259 b = log2 (log2 (a));
260 a = pow (pow (x, a), pow (c, b));
261 b = sqrt (sqrt (a));
262 a = hypot (hypot (x, b), hypot (c, a));
263 b = cbrt (cbrt (a));
264 a = ceil (ceil (x));
265 b = fabs (fabs (a));
266 a = floor (floor (x));
267 b = fmod (fmod (a, b), fmod (c, x));
268 a = nearbyint (nearbyint (x));
269 b = round (round (a));
270 c = roundeven (roundeven (a));
271 a = trunc (trunc (x));
272 b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
273 j = lrint (x) + lround (a);
274 k = llrint (b) + llround (c);
275 m = fromfp (a, FP_INT_UPWARD, 2) + fromfpx (b, FP_INT_DOWNWARD, 3);
276 um = ufromfp (c, FP_INT_TONEAREST, 4) + ufromfpx (a, FP_INT_TOWARDZERO, 5);
277 a = erf (erf (x));
278 b = erfc (erfc (a));
279 a = tgamma (tgamma (x));
280 b = lgamma (lgamma (a));
281 a = rint (rint (x));
282 b = nextafter (nextafter (a, b), nextafter (c, x));
283 a = nextdown (nextdown (a));
284 b = nexttoward (nexttoward (x, a), c);
285 a = nextup (nextup (a));
286 b = remainder (remainder (a, b), remainder (c, x));
287 a = scalb (scalb (x, a), (TYPE) (6));
288 k = scalbn (a, 7) + scalbln (c, 10l);
289 i = ilogb (x);
290 j = llogb (x);
291 a = fdim (fdim (x, a), fdim (c, b));
292 b = fmax (fmax (a, x), fmax (c, b));
293 a = fmin (fmin (x, a), fmin (c, b));
294 b = fmaxmag (fmaxmag (a, x), fmaxmag (c, b));
295 a = fminmag (fminmag (x, a), fminmag (c, b));
296 b = fma (sin (a), sin (x), sin (c));
297 a = totalorder (totalorder (x, b), totalorder (c, x));
298 b = totalordermag (totalordermag (x, a), totalordermag (c, x));
300 #ifdef TEST_INT
301 a = atan2 (i, b);
302 b = remquo (i, a, &i);
303 c = fma (i, b, i);
304 a = pow (i, c);
305 #endif
306 x = a + b + c + i + j + k + m + um;
308 saved_count = count;
309 if (ccount != 0)
310 ccount = -10000;
312 d = cos (cos (z));
313 z = acos (acos (d));
314 d = sin (sin (z));
315 z = asin (asin (d));
316 d = tan (tan (z));
317 z = atan (atan (d));
318 d = cosh (cosh (z));
319 z = acosh (acosh (d));
320 d = sinh (sinh (z));
321 z = asinh (asinh (d));
322 d = tanh (tanh (z));
323 z = atanh (atanh (d));
324 d = exp (exp (z));
325 z = log (log (d));
326 d = sqrt (sqrt (z));
327 z = conj (conj (d));
328 d = fabs (conj (a));
329 z = pow (pow (a, d), pow (b, z));
330 d = cproj (cproj (z));
331 z += fabs (cproj (a));
332 a = carg (carg (z));
333 b = creal (creal (d));
334 c = cimag (cimag (z));
335 x += a + b + c + i + j + k;
336 z += d;
338 if (saved_count != count)
339 count = -10000;
341 if (0)
343 a = cos (y);
344 a = acos (y);
345 a = sin (y);
346 a = asin (y);
347 a = tan (y);
348 a = atan (y);
349 a = atan2 (y, y);
350 a = cosh (y);
351 a = acosh (y);
352 a = sinh (y);
353 a = asinh (y);
354 a = tanh (y);
355 a = atanh (y);
356 a = exp (y);
357 a = log (y);
358 a = log10 (y);
359 a = ldexp (y, 5);
360 a = frexp (y, &i);
361 a = expm1 (y);
362 a = log1p (y);
363 a = logb (y);
364 a = exp2 (y);
365 a = log2 (y);
366 a = pow (y, y);
367 a = sqrt (y);
368 a = hypot (y, y);
369 a = cbrt (y);
370 a = ceil (y);
371 a = fabs (y);
372 a = floor (y);
373 a = fmod (y, y);
374 a = nearbyint (y);
375 a = round (y);
376 a = roundeven (y);
377 a = trunc (y);
378 a = remquo (y, y, &i);
379 j = lrint (y) + lround (y);
380 k = llrint (y) + llround (y);
381 m = fromfp (y, FP_INT_UPWARD, 6) + fromfpx (y, FP_INT_DOWNWARD, 7);
382 um = (ufromfp (y, FP_INT_TONEAREST, 8)
383 + ufromfpx (y, FP_INT_TOWARDZERO, 9));
384 a = erf (y);
385 a = erfc (y);
386 a = tgamma (y);
387 a = lgamma (y);
388 a = rint (y);
389 a = nextafter (y, y);
390 a = nexttoward (y, y);
391 a = remainder (y, y);
392 a = scalb (y, (const TYPE) (6));
393 k = scalbn (y, 7) + scalbln (y, 10l);
394 i = ilogb (y);
395 j = llogb (y);
396 a = fdim (y, y);
397 a = fmax (y, y);
398 a = fmin (y, y);
399 a = fmaxmag (y, y);
400 a = fminmag (y, y);
401 a = fma (y, y, y);
402 a = totalorder (y, y);
403 a = totalordermag (y, y);
405 #ifdef TEST_INT
406 a = atan2 (i, y);
407 a = remquo (i, y, &i);
408 a = fma (i, y, i);
409 a = pow (i, y);
410 #endif
412 d = cos ((const complex TYPE) z);
413 d = acos ((const complex TYPE) z);
414 d = sin ((const complex TYPE) z);
415 d = asin ((const complex TYPE) z);
416 d = tan ((const complex TYPE) z);
417 d = atan ((const complex TYPE) z);
418 d = cosh ((const complex TYPE) z);
419 d = acosh ((const complex TYPE) z);
420 d = sinh ((const complex TYPE) z);
421 d = asinh ((const complex TYPE) z);
422 d = tanh ((const complex TYPE) z);
423 d = atanh ((const complex TYPE) z);
424 d = exp ((const complex TYPE) z);
425 d = log ((const complex TYPE) z);
426 d = sqrt ((const complex TYPE) z);
427 d = pow ((const complex TYPE) z, (const complex TYPE) z);
428 d = fabs ((const complex TYPE) z);
429 d = carg ((const complex TYPE) z);
430 d = creal ((const complex TYPE) z);
431 d = cimag ((const complex TYPE) z);
432 d = conj ((const complex TYPE) z);
433 d = cproj ((const complex TYPE) z);
436 #undef x
437 #undef y
438 #undef z
441 TYPE
442 (F(cos)) (TYPE x)
444 ++count;
445 P ();
446 return x;
449 TYPE
450 (F(acos)) (TYPE x)
452 ++count;
453 P ();
454 return x;
457 TYPE
458 (F(sin)) (TYPE x)
460 ++count;
461 P ();
462 return x;
465 TYPE
466 (F(asin)) (TYPE x)
468 ++count;
469 P ();
470 return x;
473 TYPE
474 (F(tan)) (TYPE x)
476 ++count;
477 P ();
478 return x;
481 TYPE
482 (F(atan)) (TYPE x)
484 ++count;
485 P ();
486 return x;
489 TYPE
490 (F(atan2)) (TYPE x, TYPE y)
492 ++count;
493 P ();
494 return x + y;
497 TYPE
498 (F(cosh)) (TYPE x)
500 ++count;
501 P ();
502 return x;
505 TYPE
506 (F(acosh)) (TYPE x)
508 ++count;
509 P ();
510 return x;
513 TYPE
514 (F(sinh)) (TYPE x)
516 ++count;
517 P ();
518 return x;
521 TYPE
522 (F(asinh)) (TYPE x)
524 ++count;
525 P ();
526 return x;
529 TYPE
530 (F(tanh)) (TYPE x)
532 ++count;
533 P ();
534 return x;
537 TYPE
538 (F(atanh)) (TYPE x)
540 ++count;
541 P ();
542 return x;
545 TYPE
546 (F(exp)) (TYPE x)
548 ++count;
549 P ();
550 return x;
553 TYPE
554 (F(log)) (TYPE x)
556 ++count;
557 P ();
558 return x;
561 TYPE
562 (F(log10)) (TYPE x)
564 ++count;
565 P ();
566 return x;
569 TYPE
570 (F(ldexp)) (TYPE x, int y)
572 ++count;
573 P ();
574 return x + y;
577 TYPE
578 (F(frexp)) (TYPE x, int *y)
580 ++count;
581 P ();
582 return x + *y;
585 TYPE
586 (F(expm1)) (TYPE x)
588 ++count;
589 P ();
590 return x;
593 TYPE
594 (F(log1p)) (TYPE x)
596 ++count;
597 P ();
598 return x;
601 TYPE
602 (F(logb)) (TYPE x)
604 ++count;
605 P ();
606 return x;
609 TYPE
610 (F(exp2)) (TYPE x)
612 ++count;
613 P ();
614 return x;
617 TYPE
618 (F(log2)) (TYPE x)
620 ++count;
621 P ();
622 return x;
625 TYPE
626 (F(pow)) (TYPE x, TYPE y)
628 ++count;
629 P ();
630 return x + y;
633 TYPE
634 (F(sqrt)) (TYPE x)
636 ++count;
637 P ();
638 return x;
641 TYPE
642 (F(hypot)) (TYPE x, TYPE y)
644 ++count;
645 P ();
646 return x + y;
649 TYPE
650 (F(cbrt)) (TYPE x)
652 ++count;
653 P ();
654 return x;
657 TYPE
658 (F(ceil)) (TYPE x)
660 ++count;
661 P ();
662 return x;
665 TYPE
666 (F(fabs)) (TYPE x)
668 ++count;
669 P ();
670 return x;
673 TYPE
674 (F(floor)) (TYPE x)
676 ++count;
677 P ();
678 return x;
681 TYPE
682 (F(fmod)) (TYPE x, TYPE y)
684 ++count;
685 P ();
686 return x + y;
689 TYPE
690 (F(nearbyint)) (TYPE x)
692 ++count;
693 P ();
694 return x;
697 TYPE
698 (F(round)) (TYPE x)
700 ++count;
701 P ();
702 return x;
705 TYPE
706 (F(roundeven)) (TYPE x)
708 ++count;
709 P ();
710 return x;
713 TYPE
714 (F(trunc)) (TYPE x)
716 ++count;
717 P ();
718 return x;
721 TYPE
722 (F(remquo)) (TYPE x, TYPE y, int *i)
724 ++count;
725 P ();
726 return x + y + *i;
729 long int
730 (F(lrint)) (TYPE x)
732 ++count;
733 P ();
734 return x;
737 long int
738 (F(lround)) (TYPE x)
740 ++count;
741 P ();
742 return x;
745 long long int
746 (F(llrint)) (TYPE x)
748 ++count;
749 P ();
750 return x;
753 long long int
754 (F(llround)) (TYPE x)
756 ++count;
757 P ();
758 return x;
761 intmax_t
762 (F(fromfp)) (TYPE x, int round, unsigned int width)
764 ++count;
765 P ();
766 return x;
769 intmax_t
770 (F(fromfpx)) (TYPE x, int round, unsigned int width)
772 ++count;
773 P ();
774 return x;
777 uintmax_t
778 (F(ufromfp)) (TYPE x, int round, unsigned int width)
780 ++count;
781 P ();
782 return x;
785 uintmax_t
786 (F(ufromfpx)) (TYPE x, int round, unsigned int width)
788 ++count;
789 P ();
790 return x;
793 TYPE
794 (F(erf)) (TYPE x)
796 ++count;
797 P ();
798 return x;
801 TYPE
802 (F(erfc)) (TYPE x)
804 ++count;
805 P ();
806 return x;
809 TYPE
810 (F(tgamma)) (TYPE x)
812 ++count;
813 P ();
814 return x;
817 TYPE
818 (F(lgamma)) (TYPE x)
820 ++count;
821 P ();
822 return x;
825 TYPE
826 (F(rint)) (TYPE x)
828 ++count;
829 P ();
830 return x;
833 TYPE
834 (F(nextafter)) (TYPE x, TYPE y)
836 ++count;
837 P ();
838 return x + y;
841 TYPE
842 (F(nextdown)) (TYPE x)
844 ++count;
845 P ();
846 return x;
849 TYPE
850 (F(nexttoward)) (TYPE x, long double y)
852 ++count;
853 P ();
854 return x + y;
857 TYPE
858 (F(nextup)) (TYPE x)
860 ++count;
861 P ();
862 return x;
865 TYPE
866 (F(remainder)) (TYPE x, TYPE y)
868 ++count;
869 P ();
870 return x + y;
873 TYPE
874 (F(scalb)) (TYPE x, TYPE y)
876 ++count;
877 P ();
878 return x + y;
881 TYPE
882 (F(scalbn)) (TYPE x, int y)
884 ++count;
885 P ();
886 return x + y;
889 TYPE
890 (F(scalbln)) (TYPE x, long int y)
892 ++count;
893 P ();
894 return x + y;
898 (F(ilogb)) (TYPE x)
900 ++count;
901 P ();
902 return x;
905 long int
906 (F(llogb)) (TYPE x)
908 ++count;
909 P ();
910 return x;
913 TYPE
914 (F(fdim)) (TYPE x, TYPE y)
916 ++count;
917 P ();
918 return x + y;
921 TYPE
922 (F(fmin)) (TYPE x, TYPE y)
924 ++count;
925 P ();
926 return x + y;
929 TYPE
930 (F(fmax)) (TYPE x, TYPE y)
932 ++count;
933 P ();
934 return x + y;
937 TYPE
938 (F(fminmag)) (TYPE x, TYPE y)
940 ++count;
941 P ();
942 return x + y;
945 TYPE
946 (F(fmaxmag)) (TYPE x, TYPE y)
948 ++count;
949 P ();
950 return x + y;
953 TYPE
954 (F(fma)) (TYPE x, TYPE y, TYPE z)
956 ++count;
957 P ();
958 return x + y + z;
962 (F(totalorder)) (TYPE x, TYPE y)
964 ++count;
965 P ();
966 return x + y;
970 (F(totalordermag)) (TYPE x, TYPE y)
972 ++count;
973 P ();
974 return x + y;
977 complex TYPE
978 (F(cacos)) (complex TYPE x)
980 ++ccount;
981 P ();
982 return x;
985 complex TYPE
986 (F(casin)) (complex TYPE x)
988 ++ccount;
989 P ();
990 return x;
993 complex TYPE
994 (F(catan)) (complex TYPE x)
996 ++ccount;
997 P ();
998 return x;
1001 complex TYPE
1002 (F(ccos)) (complex TYPE x)
1004 ++ccount;
1005 P ();
1006 return x;
1009 complex TYPE
1010 (F(csin)) (complex TYPE x)
1012 ++ccount;
1013 P ();
1014 return x;
1017 complex TYPE
1018 (F(ctan)) (complex TYPE x)
1020 ++ccount;
1021 P ();
1022 return x;
1025 complex TYPE
1026 (F(cacosh)) (complex TYPE x)
1028 ++ccount;
1029 P ();
1030 return x;
1033 complex TYPE
1034 (F(casinh)) (complex TYPE x)
1036 ++ccount;
1037 P ();
1038 return x;
1041 complex TYPE
1042 (F(catanh)) (complex TYPE x)
1044 ++ccount;
1045 P ();
1046 return x;
1049 complex TYPE
1050 (F(ccosh)) (complex TYPE x)
1052 ++ccount;
1053 P ();
1054 return x;
1057 complex TYPE
1058 (F(csinh)) (complex TYPE x)
1060 ++ccount;
1061 P ();
1062 return x;
1065 complex TYPE
1066 (F(ctanh)) (complex TYPE x)
1068 ++ccount;
1069 P ();
1070 return x;
1073 complex TYPE
1074 (F(cexp)) (complex TYPE x)
1076 ++ccount;
1077 P ();
1078 return x;
1081 complex TYPE
1082 (F(clog)) (complex TYPE x)
1084 ++ccount;
1085 P ();
1086 return x;
1089 complex TYPE
1090 (F(csqrt)) (complex TYPE x)
1092 ++ccount;
1093 P ();
1094 return x;
1097 complex TYPE
1098 (F(cpow)) (complex TYPE x, complex TYPE y)
1100 ++ccount;
1101 P ();
1102 return x + y;
1105 TYPE
1106 (F(cabs)) (complex TYPE x)
1108 ++ccount;
1109 P ();
1110 return x;
1113 TYPE
1114 (F(carg)) (complex TYPE x)
1116 ++ccount;
1117 P ();
1118 return x;
1121 TYPE
1122 (F(creal)) (complex TYPE x)
1124 ++ccount;
1125 P ();
1126 return __real__ x;
1129 TYPE
1130 (F(cimag)) (complex TYPE x)
1132 ++ccount;
1133 P ();
1134 return __imag__ x;
1137 complex TYPE
1138 (F(conj)) (complex TYPE x)
1140 ++ccount;
1141 P ();
1142 return x;
1145 complex TYPE
1146 (F(cproj)) (complex TYPE x)
1148 ++ccount;
1149 P ();
1150 return x;
1153 #undef F
1154 #undef TYPE
1155 #undef count
1156 #undef ccount
1157 #undef TEST_INT
1158 #endif