Add totalorder, totalorderf, totalorderl.
[glibc.git] / math / test-tgmath.c
bloba24058c9bd2daf1859455f731d59c1a35766b9c8
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 122
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));
288 a = totalorder (totalorder (x, b), totalorder (c, x));
290 #ifdef TEST_INT
291 a = atan2 (i, b);
292 b = remquo (i, a, &i);
293 c = fma (i, b, i);
294 a = pow (i, c);
295 #endif
296 x = a + b + c + i + j + k;
298 saved_count = count;
299 if (ccount != 0)
300 ccount = -10000;
302 d = cos (cos (z));
303 z = acos (acos (d));
304 d = sin (sin (z));
305 z = asin (asin (d));
306 d = tan (tan (z));
307 z = atan (atan (d));
308 d = cosh (cosh (z));
309 z = acosh (acosh (d));
310 d = sinh (sinh (z));
311 z = asinh (asinh (d));
312 d = tanh (tanh (z));
313 z = atanh (atanh (d));
314 d = exp (exp (z));
315 z = log (log (d));
316 d = sqrt (sqrt (z));
317 z = conj (conj (d));
318 d = fabs (conj (a));
319 z = pow (pow (a, d), pow (b, z));
320 d = cproj (cproj (z));
321 z += fabs (cproj (a));
322 a = carg (carg (z));
323 b = creal (creal (d));
324 c = cimag (cimag (z));
325 x += a + b + c + i + j + k;
326 z += d;
328 if (saved_count != count)
329 count = -10000;
331 if (0)
333 a = cos (y);
334 a = acos (y);
335 a = sin (y);
336 a = asin (y);
337 a = tan (y);
338 a = atan (y);
339 a = atan2 (y, y);
340 a = cosh (y);
341 a = acosh (y);
342 a = sinh (y);
343 a = asinh (y);
344 a = tanh (y);
345 a = atanh (y);
346 a = exp (y);
347 a = log (y);
348 a = log10 (y);
349 a = ldexp (y, 5);
350 a = frexp (y, &i);
351 a = expm1 (y);
352 a = log1p (y);
353 a = logb (y);
354 a = exp2 (y);
355 a = log2 (y);
356 a = pow (y, y);
357 a = sqrt (y);
358 a = hypot (y, y);
359 a = cbrt (y);
360 a = ceil (y);
361 a = fabs (y);
362 a = floor (y);
363 a = fmod (y, y);
364 a = nearbyint (y);
365 a = round (y);
366 a = trunc (y);
367 a = remquo (y, y, &i);
368 j = lrint (y) + lround (y);
369 k = llrint (y) + llround (y);
370 a = erf (y);
371 a = erfc (y);
372 a = tgamma (y);
373 a = lgamma (y);
374 a = rint (y);
375 a = nextafter (y, y);
376 a = nexttoward (y, y);
377 a = remainder (y, y);
378 a = scalb (y, (const TYPE) (6));
379 k = scalbn (y, 7) + scalbln (y, 10l);
380 i = ilogb (y);
381 a = fdim (y, y);
382 a = fmax (y, y);
383 a = fmin (y, y);
384 a = fma (y, y, y);
385 a = totalorder (y, y);
387 #ifdef TEST_INT
388 a = atan2 (i, y);
389 a = remquo (i, y, &i);
390 a = fma (i, y, i);
391 a = pow (i, y);
392 #endif
394 d = cos ((const complex TYPE) z);
395 d = acos ((const complex TYPE) z);
396 d = sin ((const complex TYPE) z);
397 d = asin ((const complex TYPE) z);
398 d = tan ((const complex TYPE) z);
399 d = atan ((const complex TYPE) z);
400 d = cosh ((const complex TYPE) z);
401 d = acosh ((const complex TYPE) z);
402 d = sinh ((const complex TYPE) z);
403 d = asinh ((const complex TYPE) z);
404 d = tanh ((const complex TYPE) z);
405 d = atanh ((const complex TYPE) z);
406 d = exp ((const complex TYPE) z);
407 d = log ((const complex TYPE) z);
408 d = sqrt ((const complex TYPE) z);
409 d = pow ((const complex TYPE) z, (const complex TYPE) z);
410 d = fabs ((const complex TYPE) z);
411 d = carg ((const complex TYPE) z);
412 d = creal ((const complex TYPE) z);
413 d = cimag ((const complex TYPE) z);
414 d = conj ((const complex TYPE) z);
415 d = cproj ((const complex TYPE) z);
418 #undef x
419 #undef y
420 #undef z
423 TYPE
424 (F(cos)) (TYPE x)
426 ++count;
427 P ();
428 return x;
431 TYPE
432 (F(acos)) (TYPE x)
434 ++count;
435 P ();
436 return x;
439 TYPE
440 (F(sin)) (TYPE x)
442 ++count;
443 P ();
444 return x;
447 TYPE
448 (F(asin)) (TYPE x)
450 ++count;
451 P ();
452 return x;
455 TYPE
456 (F(tan)) (TYPE x)
458 ++count;
459 P ();
460 return x;
463 TYPE
464 (F(atan)) (TYPE x)
466 ++count;
467 P ();
468 return x;
471 TYPE
472 (F(atan2)) (TYPE x, TYPE y)
474 ++count;
475 P ();
476 return x + y;
479 TYPE
480 (F(cosh)) (TYPE x)
482 ++count;
483 P ();
484 return x;
487 TYPE
488 (F(acosh)) (TYPE x)
490 ++count;
491 P ();
492 return x;
495 TYPE
496 (F(sinh)) (TYPE x)
498 ++count;
499 P ();
500 return x;
503 TYPE
504 (F(asinh)) (TYPE x)
506 ++count;
507 P ();
508 return x;
511 TYPE
512 (F(tanh)) (TYPE x)
514 ++count;
515 P ();
516 return x;
519 TYPE
520 (F(atanh)) (TYPE x)
522 ++count;
523 P ();
524 return x;
527 TYPE
528 (F(exp)) (TYPE x)
530 ++count;
531 P ();
532 return x;
535 TYPE
536 (F(log)) (TYPE x)
538 ++count;
539 P ();
540 return x;
543 TYPE
544 (F(log10)) (TYPE x)
546 ++count;
547 P ();
548 return x;
551 TYPE
552 (F(ldexp)) (TYPE x, int y)
554 ++count;
555 P ();
556 return x + y;
559 TYPE
560 (F(frexp)) (TYPE x, int *y)
562 ++count;
563 P ();
564 return x + *y;
567 TYPE
568 (F(expm1)) (TYPE x)
570 ++count;
571 P ();
572 return x;
575 TYPE
576 (F(log1p)) (TYPE x)
578 ++count;
579 P ();
580 return x;
583 TYPE
584 (F(logb)) (TYPE x)
586 ++count;
587 P ();
588 return x;
591 TYPE
592 (F(exp2)) (TYPE x)
594 ++count;
595 P ();
596 return x;
599 TYPE
600 (F(log2)) (TYPE x)
602 ++count;
603 P ();
604 return x;
607 TYPE
608 (F(pow)) (TYPE x, TYPE y)
610 ++count;
611 P ();
612 return x + y;
615 TYPE
616 (F(sqrt)) (TYPE x)
618 ++count;
619 P ();
620 return x;
623 TYPE
624 (F(hypot)) (TYPE x, TYPE y)
626 ++count;
627 P ();
628 return x + y;
631 TYPE
632 (F(cbrt)) (TYPE x)
634 ++count;
635 P ();
636 return x;
639 TYPE
640 (F(ceil)) (TYPE x)
642 ++count;
643 P ();
644 return x;
647 TYPE
648 (F(fabs)) (TYPE x)
650 ++count;
651 P ();
652 return x;
655 TYPE
656 (F(floor)) (TYPE x)
658 ++count;
659 P ();
660 return x;
663 TYPE
664 (F(fmod)) (TYPE x, TYPE y)
666 ++count;
667 P ();
668 return x + y;
671 TYPE
672 (F(nearbyint)) (TYPE x)
674 ++count;
675 P ();
676 return x;
679 TYPE
680 (F(round)) (TYPE x)
682 ++count;
683 P ();
684 return x;
687 TYPE
688 (F(trunc)) (TYPE x)
690 ++count;
691 P ();
692 return x;
695 TYPE
696 (F(remquo)) (TYPE x, TYPE y, int *i)
698 ++count;
699 P ();
700 return x + y + *i;
703 long int
704 (F(lrint)) (TYPE x)
706 ++count;
707 P ();
708 return x;
711 long int
712 (F(lround)) (TYPE x)
714 ++count;
715 P ();
716 return x;
719 long long int
720 (F(llrint)) (TYPE x)
722 ++count;
723 P ();
724 return x;
727 long long int
728 (F(llround)) (TYPE x)
730 ++count;
731 P ();
732 return x;
735 TYPE
736 (F(erf)) (TYPE x)
738 ++count;
739 P ();
740 return x;
743 TYPE
744 (F(erfc)) (TYPE x)
746 ++count;
747 P ();
748 return x;
751 TYPE
752 (F(tgamma)) (TYPE x)
754 ++count;
755 P ();
756 return x;
759 TYPE
760 (F(lgamma)) (TYPE x)
762 ++count;
763 P ();
764 return x;
767 TYPE
768 (F(rint)) (TYPE x)
770 ++count;
771 P ();
772 return x;
775 TYPE
776 (F(nextafter)) (TYPE x, TYPE y)
778 ++count;
779 P ();
780 return x + y;
783 TYPE
784 (F(nextdown)) (TYPE x)
786 ++count;
787 P ();
788 return x;
791 TYPE
792 (F(nexttoward)) (TYPE x, long double y)
794 ++count;
795 P ();
796 return x + y;
799 TYPE
800 (F(nextup)) (TYPE x)
802 ++count;
803 P ();
804 return x;
807 TYPE
808 (F(remainder)) (TYPE x, TYPE y)
810 ++count;
811 P ();
812 return x + y;
815 TYPE
816 (F(scalb)) (TYPE x, TYPE y)
818 ++count;
819 P ();
820 return x + y;
823 TYPE
824 (F(scalbn)) (TYPE x, int y)
826 ++count;
827 P ();
828 return x + y;
831 TYPE
832 (F(scalbln)) (TYPE x, long int y)
834 ++count;
835 P ();
836 return x + y;
840 (F(ilogb)) (TYPE x)
842 ++count;
843 P ();
844 return x;
847 TYPE
848 (F(fdim)) (TYPE x, TYPE y)
850 ++count;
851 P ();
852 return x + y;
855 TYPE
856 (F(fmin)) (TYPE x, TYPE y)
858 ++count;
859 P ();
860 return x + y;
863 TYPE
864 (F(fmax)) (TYPE x, TYPE y)
866 ++count;
867 P ();
868 return x + y;
871 TYPE
872 (F(fma)) (TYPE x, TYPE y, TYPE z)
874 ++count;
875 P ();
876 return x + y + z;
880 (F(totalorder)) (TYPE x, TYPE y)
882 ++count;
883 P ();
884 return x + y;
887 complex TYPE
888 (F(cacos)) (complex TYPE x)
890 ++ccount;
891 P ();
892 return x;
895 complex TYPE
896 (F(casin)) (complex TYPE x)
898 ++ccount;
899 P ();
900 return x;
903 complex TYPE
904 (F(catan)) (complex TYPE x)
906 ++ccount;
907 P ();
908 return x;
911 complex TYPE
912 (F(ccos)) (complex TYPE x)
914 ++ccount;
915 P ();
916 return x;
919 complex TYPE
920 (F(csin)) (complex TYPE x)
922 ++ccount;
923 P ();
924 return x;
927 complex TYPE
928 (F(ctan)) (complex TYPE x)
930 ++ccount;
931 P ();
932 return x;
935 complex TYPE
936 (F(cacosh)) (complex TYPE x)
938 ++ccount;
939 P ();
940 return x;
943 complex TYPE
944 (F(casinh)) (complex TYPE x)
946 ++ccount;
947 P ();
948 return x;
951 complex TYPE
952 (F(catanh)) (complex TYPE x)
954 ++ccount;
955 P ();
956 return x;
959 complex TYPE
960 (F(ccosh)) (complex TYPE x)
962 ++ccount;
963 P ();
964 return x;
967 complex TYPE
968 (F(csinh)) (complex TYPE x)
970 ++ccount;
971 P ();
972 return x;
975 complex TYPE
976 (F(ctanh)) (complex TYPE x)
978 ++ccount;
979 P ();
980 return x;
983 complex TYPE
984 (F(cexp)) (complex TYPE x)
986 ++ccount;
987 P ();
988 return x;
991 complex TYPE
992 (F(clog)) (complex TYPE x)
994 ++ccount;
995 P ();
996 return x;
999 complex TYPE
1000 (F(csqrt)) (complex TYPE x)
1002 ++ccount;
1003 P ();
1004 return x;
1007 complex TYPE
1008 (F(cpow)) (complex TYPE x, complex TYPE y)
1010 ++ccount;
1011 P ();
1012 return x + y;
1015 TYPE
1016 (F(cabs)) (complex TYPE x)
1018 ++ccount;
1019 P ();
1020 return x;
1023 TYPE
1024 (F(carg)) (complex TYPE x)
1026 ++ccount;
1027 P ();
1028 return x;
1031 TYPE
1032 (F(creal)) (complex TYPE x)
1034 ++ccount;
1035 P ();
1036 return __real__ x;
1039 TYPE
1040 (F(cimag)) (complex TYPE x)
1042 ++ccount;
1043 P ();
1044 return __imag__ x;
1047 complex TYPE
1048 (F(conj)) (complex TYPE x)
1050 ++ccount;
1051 P ();
1052 return x;
1055 complex TYPE
1056 (F(cproj)) (complex TYPE x)
1058 ++ccount;
1059 P ();
1060 return x;
1063 #undef F
1064 #undef TYPE
1065 #undef count
1066 #undef ccount
1067 #undef TEST_INT
1068 #endif