]> git.ipfire.org Git - thirdparty/glibc.git/blob - math/test-tgmath.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / math / test-tgmath.c
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.
6
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.
11
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.
16
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/>. */
20
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>
27
28 //#define DEBUG
29
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
35
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;
45
46 int count_double;
47 int count_float;
48 int count_ldouble;
49 int count_cdouble;
50 int count_cfloat;
51 int count_cldouble;
52
53 #define NCALLS 115
54 #define NCALLS_INT 4
55 #define NCCALLS 47
56
57 static int
58 do_test (void)
59 {
60 int result = 0;
61
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)
66 {
67 puts ("float function called for double test");
68 result = 1;
69 }
70 if (count_ldouble != 0 || count_cldouble != 0)
71 {
72 puts ("long double function called for double test");
73 result = 1;
74 }
75 if (count_double < NCALLS + NCALLS_INT)
76 {
77 printf ("double functions not called often enough (%d)\n",
78 count_double);
79 result = 1;
80 }
81 else if (count_double > NCALLS + NCALLS_INT)
82 {
83 printf ("double functions called too often (%d)\n",
84 count_double);
85 result = 1;
86 }
87 if (count_cdouble < NCCALLS)
88 {
89 printf ("double complex functions not called often enough (%d)\n",
90 count_cdouble);
91 result = 1;
92 }
93 else if (count_cdouble > NCCALLS)
94 {
95 printf ("double complex functions called too often (%d)\n",
96 count_cdouble);
97 result = 1;
98 }
99
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)
104 {
105 puts ("double function called for float test");
106 result = 1;
107 }
108 if (count_ldouble != 0 || count_cldouble != 0)
109 {
110 puts ("long double function called for float test");
111 result = 1;
112 }
113 if (count_float < NCALLS)
114 {
115 printf ("float functions not called often enough (%d)\n", count_float);
116 result = 1;
117 }
118 else if (count_float > NCALLS)
119 {
120 printf ("float functions called too often (%d)\n",
121 count_double);
122 result = 1;
123 }
124 if (count_cfloat < NCCALLS)
125 {
126 printf ("float complex functions not called often enough (%d)\n",
127 count_cfloat);
128 result = 1;
129 }
130 else if (count_cfloat > NCCALLS)
131 {
132 printf ("float complex functions called too often (%d)\n",
133 count_cfloat);
134 result = 1;
135 }
136
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)
142 {
143 puts ("float function called for long double test");
144 result = 1;
145 }
146 if (count_double != 0 || count_cdouble != 0)
147 {
148 puts ("double function called for long double test");
149 result = 1;
150 }
151 if (count_ldouble < NCALLS)
152 {
153 printf ("long double functions not called often enough (%d)\n",
154 count_ldouble);
155 result = 1;
156 }
157 else if (count_ldouble > NCALLS)
158 {
159 printf ("long double functions called too often (%d)\n",
160 count_double);
161 result = 1;
162 }
163 if (count_cldouble < NCCALLS)
164 {
165 printf ("long double complex functions not called often enough (%d)\n",
166 count_cldouble);
167 result = 1;
168 }
169 else if (count_cldouble > NCCALLS)
170 {
171 printf ("long double complex functions called too often (%d)\n",
172 count_cldouble);
173 result = 1;
174 }
175 #endif
176
177 return result;
178 }
179
180 /* Now generate the three functions. */
181 #define HAVE_MAIN
182
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"
192
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"
201
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
212
213 #define TEST_FUNCTION do_test ()
214 #include "../test-skeleton.c"
215
216 #else
217
218 #ifdef DEBUG
219 #define P() puts (__FUNCTION__)
220 #else
221 #define P()
222 #endif
223
224 static void
225 F(compile_test) (void)
226 {
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;
233
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 = nexttoward (nexttoward (x, a), c);
278 b = remainder (remainder (a, b), remainder (c, x));
279 a = scalb (scalb (x, a), (TYPE) (6));
280 k = scalbn (a, 7) + scalbln (c, 10l);
281 i = ilogb (x);
282 a = fdim (fdim (x, a), fdim (c, b));
283 b = fmax (fmax (a, x), fmax (c, b));
284 a = fmin (fmin (x, a), fmin (c, b));
285 b = fma (sin (a), sin (x), sin (c));
286
287 #ifdef TEST_INT
288 a = atan2 (i, b);
289 b = remquo (i, a, &i);
290 c = fma (i, b, i);
291 a = pow (i, c);
292 #endif
293 x = a + b + c + i + j + k;
294
295 saved_count = count;
296 if (ccount != 0)
297 ccount = -10000;
298
299 d = cos (cos (z));
300 z = acos (acos (d));
301 d = sin (sin (z));
302 z = asin (asin (d));
303 d = tan (tan (z));
304 z = atan (atan (d));
305 d = cosh (cosh (z));
306 z = acosh (acosh (d));
307 d = sinh (sinh (z));
308 z = asinh (asinh (d));
309 d = tanh (tanh (z));
310 z = atanh (atanh (d));
311 d = exp (exp (z));
312 z = log (log (d));
313 d = sqrt (sqrt (z));
314 z = conj (conj (d));
315 d = fabs (conj (a));
316 z = pow (pow (a, d), pow (b, z));
317 d = cproj (cproj (z));
318 z += fabs (cproj (a));
319 a = carg (carg (z));
320 b = creal (creal (d));
321 c = cimag (cimag (z));
322 x += a + b + c + i + j + k;
323 z += d;
324
325 if (saved_count != count)
326 count = -10000;
327
328 if (0)
329 {
330 a = cos (y);
331 a = acos (y);
332 a = sin (y);
333 a = asin (y);
334 a = tan (y);
335 a = atan (y);
336 a = atan2 (y, y);
337 a = cosh (y);
338 a = acosh (y);
339 a = sinh (y);
340 a = asinh (y);
341 a = tanh (y);
342 a = atanh (y);
343 a = exp (y);
344 a = log (y);
345 a = log10 (y);
346 a = ldexp (y, 5);
347 a = frexp (y, &i);
348 a = expm1 (y);
349 a = log1p (y);
350 a = logb (y);
351 a = exp2 (y);
352 a = log2 (y);
353 a = pow (y, y);
354 a = sqrt (y);
355 a = hypot (y, y);
356 a = cbrt (y);
357 a = ceil (y);
358 a = fabs (y);
359 a = floor (y);
360 a = fmod (y, y);
361 a = nearbyint (y);
362 a = round (y);
363 a = trunc (y);
364 a = remquo (y, y, &i);
365 j = lrint (y) + lround (y);
366 k = llrint (y) + llround (y);
367 a = erf (y);
368 a = erfc (y);
369 a = tgamma (y);
370 a = lgamma (y);
371 a = rint (y);
372 a = nextafter (y, y);
373 a = nexttoward (y, y);
374 a = remainder (y, y);
375 a = scalb (y, (const TYPE) (6));
376 k = scalbn (y, 7) + scalbln (y, 10l);
377 i = ilogb (y);
378 a = fdim (y, y);
379 a = fmax (y, y);
380 a = fmin (y, y);
381 a = fma (y, y, y);
382
383 #ifdef TEST_INT
384 a = atan2 (i, y);
385 a = remquo (i, y, &i);
386 a = fma (i, y, i);
387 a = pow (i, y);
388 #endif
389
390 d = cos ((const complex TYPE) z);
391 d = acos ((const complex TYPE) z);
392 d = sin ((const complex TYPE) z);
393 d = asin ((const complex TYPE) z);
394 d = tan ((const complex TYPE) z);
395 d = atan ((const complex TYPE) z);
396 d = cosh ((const complex TYPE) z);
397 d = acosh ((const complex TYPE) z);
398 d = sinh ((const complex TYPE) z);
399 d = asinh ((const complex TYPE) z);
400 d = tanh ((const complex TYPE) z);
401 d = atanh ((const complex TYPE) z);
402 d = exp ((const complex TYPE) z);
403 d = log ((const complex TYPE) z);
404 d = sqrt ((const complex TYPE) z);
405 d = pow ((const complex TYPE) z, (const complex TYPE) z);
406 d = fabs ((const complex TYPE) z);
407 d = carg ((const complex TYPE) z);
408 d = creal ((const complex TYPE) z);
409 d = cimag ((const complex TYPE) z);
410 d = conj ((const complex TYPE) z);
411 d = cproj ((const complex TYPE) z);
412 }
413 }
414 #undef x
415 #undef y
416 #undef z
417
418
419 TYPE
420 (F(cos)) (TYPE x)
421 {
422 ++count;
423 P ();
424 return x;
425 }
426
427 TYPE
428 (F(acos)) (TYPE x)
429 {
430 ++count;
431 P ();
432 return x;
433 }
434
435 TYPE
436 (F(sin)) (TYPE x)
437 {
438 ++count;
439 P ();
440 return x;
441 }
442
443 TYPE
444 (F(asin)) (TYPE x)
445 {
446 ++count;
447 P ();
448 return x;
449 }
450
451 TYPE
452 (F(tan)) (TYPE x)
453 {
454 ++count;
455 P ();
456 return x;
457 }
458
459 TYPE
460 (F(atan)) (TYPE x)
461 {
462 ++count;
463 P ();
464 return x;
465 }
466
467 TYPE
468 (F(atan2)) (TYPE x, TYPE y)
469 {
470 ++count;
471 P ();
472 return x + y;
473 }
474
475 TYPE
476 (F(cosh)) (TYPE x)
477 {
478 ++count;
479 P ();
480 return x;
481 }
482
483 TYPE
484 (F(acosh)) (TYPE x)
485 {
486 ++count;
487 P ();
488 return x;
489 }
490
491 TYPE
492 (F(sinh)) (TYPE x)
493 {
494 ++count;
495 P ();
496 return x;
497 }
498
499 TYPE
500 (F(asinh)) (TYPE x)
501 {
502 ++count;
503 P ();
504 return x;
505 }
506
507 TYPE
508 (F(tanh)) (TYPE x)
509 {
510 ++count;
511 P ();
512 return x;
513 }
514
515 TYPE
516 (F(atanh)) (TYPE x)
517 {
518 ++count;
519 P ();
520 return x;
521 }
522
523 TYPE
524 (F(exp)) (TYPE x)
525 {
526 ++count;
527 P ();
528 return x;
529 }
530
531 TYPE
532 (F(log)) (TYPE x)
533 {
534 ++count;
535 P ();
536 return x;
537 }
538
539 TYPE
540 (F(log10)) (TYPE x)
541 {
542 ++count;
543 P ();
544 return x;
545 }
546
547 TYPE
548 (F(ldexp)) (TYPE x, int y)
549 {
550 ++count;
551 P ();
552 return x + y;
553 }
554
555 TYPE
556 (F(frexp)) (TYPE x, int *y)
557 {
558 ++count;
559 P ();
560 return x + *y;
561 }
562
563 TYPE
564 (F(expm1)) (TYPE x)
565 {
566 ++count;
567 P ();
568 return x;
569 }
570
571 TYPE
572 (F(log1p)) (TYPE x)
573 {
574 ++count;
575 P ();
576 return x;
577 }
578
579 TYPE
580 (F(logb)) (TYPE x)
581 {
582 ++count;
583 P ();
584 return x;
585 }
586
587 TYPE
588 (F(exp2)) (TYPE x)
589 {
590 ++count;
591 P ();
592 return x;
593 }
594
595 TYPE
596 (F(log2)) (TYPE x)
597 {
598 ++count;
599 P ();
600 return x;
601 }
602
603 TYPE
604 (F(pow)) (TYPE x, TYPE y)
605 {
606 ++count;
607 P ();
608 return x + y;
609 }
610
611 TYPE
612 (F(sqrt)) (TYPE x)
613 {
614 ++count;
615 P ();
616 return x;
617 }
618
619 TYPE
620 (F(hypot)) (TYPE x, TYPE y)
621 {
622 ++count;
623 P ();
624 return x + y;
625 }
626
627 TYPE
628 (F(cbrt)) (TYPE x)
629 {
630 ++count;
631 P ();
632 return x;
633 }
634
635 TYPE
636 (F(ceil)) (TYPE x)
637 {
638 ++count;
639 P ();
640 return x;
641 }
642
643 TYPE
644 (F(fabs)) (TYPE x)
645 {
646 ++count;
647 P ();
648 return x;
649 }
650
651 TYPE
652 (F(floor)) (TYPE x)
653 {
654 ++count;
655 P ();
656 return x;
657 }
658
659 TYPE
660 (F(fmod)) (TYPE x, TYPE y)
661 {
662 ++count;
663 P ();
664 return x + y;
665 }
666
667 TYPE
668 (F(nearbyint)) (TYPE x)
669 {
670 ++count;
671 P ();
672 return x;
673 }
674
675 TYPE
676 (F(round)) (TYPE x)
677 {
678 ++count;
679 P ();
680 return x;
681 }
682
683 TYPE
684 (F(trunc)) (TYPE x)
685 {
686 ++count;
687 P ();
688 return x;
689 }
690
691 TYPE
692 (F(remquo)) (TYPE x, TYPE y, int *i)
693 {
694 ++count;
695 P ();
696 return x + y + *i;
697 }
698
699 long int
700 (F(lrint)) (TYPE x)
701 {
702 ++count;
703 P ();
704 return x;
705 }
706
707 long int
708 (F(lround)) (TYPE x)
709 {
710 ++count;
711 P ();
712 return x;
713 }
714
715 long long int
716 (F(llrint)) (TYPE x)
717 {
718 ++count;
719 P ();
720 return x;
721 }
722
723 long long int
724 (F(llround)) (TYPE x)
725 {
726 ++count;
727 P ();
728 return x;
729 }
730
731 TYPE
732 (F(erf)) (TYPE x)
733 {
734 ++count;
735 P ();
736 return x;
737 }
738
739 TYPE
740 (F(erfc)) (TYPE x)
741 {
742 ++count;
743 P ();
744 return x;
745 }
746
747 TYPE
748 (F(tgamma)) (TYPE x)
749 {
750 ++count;
751 P ();
752 return x;
753 }
754
755 TYPE
756 (F(lgamma)) (TYPE x)
757 {
758 ++count;
759 P ();
760 return x;
761 }
762
763 TYPE
764 (F(rint)) (TYPE x)
765 {
766 ++count;
767 P ();
768 return x;
769 }
770
771 TYPE
772 (F(nextafter)) (TYPE x, TYPE y)
773 {
774 ++count;
775 P ();
776 return x + y;
777 }
778
779 TYPE
780 (F(nexttoward)) (TYPE x, long double y)
781 {
782 ++count;
783 P ();
784 return x + y;
785 }
786
787 TYPE
788 (F(remainder)) (TYPE x, TYPE y)
789 {
790 ++count;
791 P ();
792 return x + y;
793 }
794
795 TYPE
796 (F(scalb)) (TYPE x, TYPE y)
797 {
798 ++count;
799 P ();
800 return x + y;
801 }
802
803 TYPE
804 (F(scalbn)) (TYPE x, int y)
805 {
806 ++count;
807 P ();
808 return x + y;
809 }
810
811 TYPE
812 (F(scalbln)) (TYPE x, long int y)
813 {
814 ++count;
815 P ();
816 return x + y;
817 }
818
819 int
820 (F(ilogb)) (TYPE x)
821 {
822 ++count;
823 P ();
824 return x;
825 }
826
827 TYPE
828 (F(fdim)) (TYPE x, TYPE y)
829 {
830 ++count;
831 P ();
832 return x + y;
833 }
834
835 TYPE
836 (F(fmin)) (TYPE x, TYPE y)
837 {
838 ++count;
839 P ();
840 return x + y;
841 }
842
843 TYPE
844 (F(fmax)) (TYPE x, TYPE y)
845 {
846 ++count;
847 P ();
848 return x + y;
849 }
850
851 TYPE
852 (F(fma)) (TYPE x, TYPE y, TYPE z)
853 {
854 ++count;
855 P ();
856 return x + y + z;
857 }
858
859 complex TYPE
860 (F(cacos)) (complex TYPE x)
861 {
862 ++ccount;
863 P ();
864 return x;
865 }
866
867 complex TYPE
868 (F(casin)) (complex TYPE x)
869 {
870 ++ccount;
871 P ();
872 return x;
873 }
874
875 complex TYPE
876 (F(catan)) (complex TYPE x)
877 {
878 ++ccount;
879 P ();
880 return x;
881 }
882
883 complex TYPE
884 (F(ccos)) (complex TYPE x)
885 {
886 ++ccount;
887 P ();
888 return x;
889 }
890
891 complex TYPE
892 (F(csin)) (complex TYPE x)
893 {
894 ++ccount;
895 P ();
896 return x;
897 }
898
899 complex TYPE
900 (F(ctan)) (complex TYPE x)
901 {
902 ++ccount;
903 P ();
904 return x;
905 }
906
907 complex TYPE
908 (F(cacosh)) (complex TYPE x)
909 {
910 ++ccount;
911 P ();
912 return x;
913 }
914
915 complex TYPE
916 (F(casinh)) (complex TYPE x)
917 {
918 ++ccount;
919 P ();
920 return x;
921 }
922
923 complex TYPE
924 (F(catanh)) (complex TYPE x)
925 {
926 ++ccount;
927 P ();
928 return x;
929 }
930
931 complex TYPE
932 (F(ccosh)) (complex TYPE x)
933 {
934 ++ccount;
935 P ();
936 return x;
937 }
938
939 complex TYPE
940 (F(csinh)) (complex TYPE x)
941 {
942 ++ccount;
943 P ();
944 return x;
945 }
946
947 complex TYPE
948 (F(ctanh)) (complex TYPE x)
949 {
950 ++ccount;
951 P ();
952 return x;
953 }
954
955 complex TYPE
956 (F(cexp)) (complex TYPE x)
957 {
958 ++ccount;
959 P ();
960 return x;
961 }
962
963 complex TYPE
964 (F(clog)) (complex TYPE x)
965 {
966 ++ccount;
967 P ();
968 return x;
969 }
970
971 complex TYPE
972 (F(csqrt)) (complex TYPE x)
973 {
974 ++ccount;
975 P ();
976 return x;
977 }
978
979 complex TYPE
980 (F(cpow)) (complex TYPE x, complex TYPE y)
981 {
982 ++ccount;
983 P ();
984 return x + y;
985 }
986
987 TYPE
988 (F(cabs)) (complex TYPE x)
989 {
990 ++ccount;
991 P ();
992 return x;
993 }
994
995 TYPE
996 (F(carg)) (complex TYPE x)
997 {
998 ++ccount;
999 P ();
1000 return x;
1001 }
1002
1003 TYPE
1004 (F(creal)) (complex TYPE x)
1005 {
1006 ++ccount;
1007 P ();
1008 return __real__ x;
1009 }
1010
1011 TYPE
1012 (F(cimag)) (complex TYPE x)
1013 {
1014 ++ccount;
1015 P ();
1016 return __imag__ x;
1017 }
1018
1019 complex TYPE
1020 (F(conj)) (complex TYPE x)
1021 {
1022 ++ccount;
1023 P ();
1024 return x;
1025 }
1026
1027 complex TYPE
1028 (F(cproj)) (complex TYPE x)
1029 {
1030 ++ccount;
1031 P ();
1032 return x;
1033 }
1034
1035 #undef F
1036 #undef TYPE
1037 #undef count
1038 #undef ccount
1039 #undef TEST_INT
1040 #endif