packaging: add 64bit libs on 32bit build env
[platform/upstream/linaro-glibc.git] / math / test-tgmath.c
1 /* Test compilation of tgmath macros.
2    Copyright (C) 2001-2014 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 int
58 main (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 #else
214
215 #ifdef DEBUG
216 #define P() puts (__FUNCTION__)
217 #else
218 #define P()
219 #endif
220
221 static void
222 F(compile_test) (void)
223 {
224   TYPE a, b, c = 1.0;
225   complex TYPE d;
226   int i;
227   int saved_count;
228   long int j;
229   long long int k;
230
231   a = cos (cos (x));
232   b = acos (acos (a));
233   a = sin (sin (x));
234   b = asin (asin (a));
235   a = tan (tan (x));
236   b = atan (atan (a));
237   c = atan2 (atan2 (a, c), atan2 (b, x));
238   a = cosh (cosh (x));
239   b = acosh (acosh (a));
240   a = sinh (sinh (x));
241   b = asinh (asinh (a));
242   a = tanh (tanh (x));
243   b = atanh (atanh (a));
244   a = exp (exp (x));
245   b = log (log (a));
246   a = log10 (log10 (x));
247   b = ldexp (ldexp (a, 1), 5);
248   a = frexp (frexp (x, &i), &i);
249   b = expm1 (expm1 (a));
250   a = log1p (log1p (x));
251   b = logb (logb (a));
252   a = exp2 (exp2 (x));
253   b = log2 (log2 (a));
254   a = pow (pow (x, a), pow (c, b));
255   b = sqrt (sqrt (a));
256   a = hypot (hypot (x, b), hypot (c, a));
257   b = cbrt (cbrt (a));
258   a = ceil (ceil (x));
259   b = fabs (fabs (a));
260   a = floor (floor (x));
261   b = fmod (fmod (a, b), fmod (c, x));
262   a = nearbyint (nearbyint (x));
263   b = round (round (a));
264   a = trunc (trunc (x));
265   b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
266   j = lrint (x) + lround (a);
267   k = llrint (b) + llround (c);
268   a = erf (erf (x));
269   b = erfc (erfc (a));
270   a = tgamma (tgamma (x));
271   b = lgamma (lgamma (a));
272   a = rint (rint (x));
273   b = nextafter (nextafter (a, b), nextafter (c, x));
274   a = nexttoward (nexttoward (x, a), c);
275   b = remainder (remainder (a, b), remainder (c, x));
276   a = scalb (scalb (x, a), (TYPE) (6));
277   k = scalbn (a, 7) + scalbln (c, 10l);
278   i = ilogb (x);
279   a = fdim (fdim (x, a), fdim (c, b));
280   b = fmax (fmax (a, x), fmax (c, b));
281   a = fmin (fmin (x, a), fmin (c, b));
282   b = fma (sin (a), sin (x), sin (c));
283
284 #ifdef TEST_INT
285   a = atan2 (i, b);
286   b = remquo (i, a, &i);
287   c = fma (i, b, i);
288   a = pow (i, c);
289 #endif
290   x = a + b + c + i + j + k;
291
292   saved_count = count;
293   if (ccount != 0)
294     ccount = -10000;
295
296   d = cos (cos (z));
297   z = acos (acos (d));
298   d = sin (sin (z));
299   z = asin (asin (d));
300   d = tan (tan (z));
301   z = atan (atan (d));
302   d = cosh (cosh (z));
303   z = acosh (acosh (d));
304   d = sinh (sinh (z));
305   z = asinh (asinh (d));
306   d = tanh (tanh (z));
307   z = atanh (atanh (d));
308   d = exp (exp (z));
309   z = log (log (d));
310   d = sqrt (sqrt (z));
311   z = conj (conj (d));
312   d = fabs (conj (a));
313   z = pow (pow (a, d), pow (b, z));
314   d = cproj (cproj (z));
315   z += fabs (cproj (a));
316   a = carg (carg (z));
317   b = creal (creal (d));
318   c = cimag (cimag (z));
319   x += a + b + c + i + j + k;
320   z += d;
321
322   if (saved_count != count)
323     count = -10000;
324
325   if (0)
326     {
327       a = cos (y);
328       a = acos (y);
329       a = sin (y);
330       a = asin (y);
331       a = tan (y);
332       a = atan (y);
333       a = atan2 (y, y);
334       a = cosh (y);
335       a = acosh (y);
336       a = sinh (y);
337       a = asinh (y);
338       a = tanh (y);
339       a = atanh (y);
340       a = exp (y);
341       a = log (y);
342       a = log10 (y);
343       a = ldexp (y, 5);
344       a = frexp (y, &i);
345       a = expm1 (y);
346       a = log1p (y);
347       a = logb (y);
348       a = exp2 (y);
349       a = log2 (y);
350       a = pow (y, y);
351       a = sqrt (y);
352       a = hypot (y, y);
353       a = cbrt (y);
354       a = ceil (y);
355       a = fabs (y);
356       a = floor (y);
357       a = fmod (y, y);
358       a = nearbyint (y);
359       a = round (y);
360       a = trunc (y);
361       a = remquo (y, y, &i);
362       j = lrint (y) + lround (y);
363       k = llrint (y) + llround (y);
364       a = erf (y);
365       a = erfc (y);
366       a = tgamma (y);
367       a = lgamma (y);
368       a = rint (y);
369       a = nextafter (y, y);
370       a = nexttoward (y, y);
371       a = remainder (y, y);
372       a = scalb (y, (const TYPE) (6));
373       k = scalbn (y, 7) + scalbln (y, 10l);
374       i = ilogb (y);
375       a = fdim (y, y);
376       a = fmax (y, y);
377       a = fmin (y, y);
378       a = fma (y, y, y);
379
380 #ifdef TEST_INT
381       a = atan2 (i, y);
382       a = remquo (i, y, &i);
383       a = fma (i, y, i);
384       a = pow (i, y);
385 #endif
386
387       d = cos ((const complex TYPE) z);
388       d = acos ((const complex TYPE) z);
389       d = sin ((const complex TYPE) z);
390       d = asin ((const complex TYPE) z);
391       d = tan ((const complex TYPE) z);
392       d = atan ((const complex TYPE) z);
393       d = cosh ((const complex TYPE) z);
394       d = acosh ((const complex TYPE) z);
395       d = sinh ((const complex TYPE) z);
396       d = asinh ((const complex TYPE) z);
397       d = tanh ((const complex TYPE) z);
398       d = atanh ((const complex TYPE) z);
399       d = exp ((const complex TYPE) z);
400       d = log ((const complex TYPE) z);
401       d = sqrt ((const complex TYPE) z);
402       d = pow ((const complex TYPE) z, (const complex TYPE) z);
403       d = fabs ((const complex TYPE) z);
404       d = carg ((const complex TYPE) z);
405       d = creal ((const complex TYPE) z);
406       d = cimag ((const complex TYPE) z);
407       d = conj ((const complex TYPE) z);
408       d = cproj ((const complex TYPE) z);
409     }
410 }
411 #undef x
412 #undef y
413 #undef z
414
415
416 TYPE
417 (F(cos)) (TYPE x)
418 {
419   ++count;
420   P ();
421   return x;
422 }
423
424 TYPE
425 (F(acos)) (TYPE x)
426 {
427   ++count;
428   P ();
429   return x;
430 }
431
432 TYPE
433 (F(sin)) (TYPE x)
434 {
435   ++count;
436   P ();
437   return x;
438 }
439
440 TYPE
441 (F(asin)) (TYPE x)
442 {
443   ++count;
444   P ();
445   return x;
446 }
447
448 TYPE
449 (F(tan)) (TYPE x)
450 {
451   ++count;
452   P ();
453   return x;
454 }
455
456 TYPE
457 (F(atan)) (TYPE x)
458 {
459   ++count;
460   P ();
461   return x;
462 }
463
464 TYPE
465 (F(atan2)) (TYPE x, TYPE y)
466 {
467   ++count;
468   P ();
469   return x + y;
470 }
471
472 TYPE
473 (F(cosh)) (TYPE x)
474 {
475   ++count;
476   P ();
477   return x;
478 }
479
480 TYPE
481 (F(acosh)) (TYPE x)
482 {
483   ++count;
484   P ();
485   return x;
486 }
487
488 TYPE
489 (F(sinh)) (TYPE x)
490 {
491   ++count;
492   P ();
493   return x;
494 }
495
496 TYPE
497 (F(asinh)) (TYPE x)
498 {
499   ++count;
500   P ();
501   return x;
502 }
503
504 TYPE
505 (F(tanh)) (TYPE x)
506 {
507   ++count;
508   P ();
509   return x;
510 }
511
512 TYPE
513 (F(atanh)) (TYPE x)
514 {
515   ++count;
516   P ();
517   return x;
518 }
519
520 TYPE
521 (F(exp)) (TYPE x)
522 {
523   ++count;
524   P ();
525   return x;
526 }
527
528 TYPE
529 (F(log)) (TYPE x)
530 {
531   ++count;
532   P ();
533   return x;
534 }
535
536 TYPE
537 (F(log10)) (TYPE x)
538 {
539   ++count;
540   P ();
541   return x;
542 }
543
544 TYPE
545 (F(ldexp)) (TYPE x, int y)
546 {
547   ++count;
548   P ();
549   return x + y;
550 }
551
552 TYPE
553 (F(frexp)) (TYPE x, int *y)
554 {
555   ++count;
556   P ();
557   return x + *y;
558 }
559
560 TYPE
561 (F(expm1)) (TYPE x)
562 {
563   ++count;
564   P ();
565   return x;
566 }
567
568 TYPE
569 (F(log1p)) (TYPE x)
570 {
571   ++count;
572   P ();
573   return x;
574 }
575
576 TYPE
577 (F(logb)) (TYPE x)
578 {
579   ++count;
580   P ();
581   return x;
582 }
583
584 TYPE
585 (F(exp2)) (TYPE x)
586 {
587   ++count;
588   P ();
589   return x;
590 }
591
592 TYPE
593 (F(log2)) (TYPE x)
594 {
595   ++count;
596   P ();
597   return x;
598 }
599
600 TYPE
601 (F(pow)) (TYPE x, TYPE y)
602 {
603   ++count;
604   P ();
605   return x + y;
606 }
607
608 TYPE
609 (F(sqrt)) (TYPE x)
610 {
611   ++count;
612   P ();
613   return x;
614 }
615
616 TYPE
617 (F(hypot)) (TYPE x, TYPE y)
618 {
619   ++count;
620   P ();
621   return x + y;
622 }
623
624 TYPE
625 (F(cbrt)) (TYPE x)
626 {
627   ++count;
628   P ();
629   return x;
630 }
631
632 TYPE
633 (F(ceil)) (TYPE x)
634 {
635   ++count;
636   P ();
637   return x;
638 }
639
640 TYPE
641 (F(fabs)) (TYPE x)
642 {
643   ++count;
644   P ();
645   return x;
646 }
647
648 TYPE
649 (F(floor)) (TYPE x)
650 {
651   ++count;
652   P ();
653   return x;
654 }
655
656 TYPE
657 (F(fmod)) (TYPE x, TYPE y)
658 {
659   ++count;
660   P ();
661   return x + y;
662 }
663
664 TYPE
665 (F(nearbyint)) (TYPE x)
666 {
667   ++count;
668   P ();
669   return x;
670 }
671
672 TYPE
673 (F(round)) (TYPE x)
674 {
675   ++count;
676   P ();
677   return x;
678 }
679
680 TYPE
681 (F(trunc)) (TYPE x)
682 {
683   ++count;
684   P ();
685   return x;
686 }
687
688 TYPE
689 (F(remquo)) (TYPE x, TYPE y, int *i)
690 {
691   ++count;
692   P ();
693   return x + y + *i;
694 }
695
696 long int
697 (F(lrint)) (TYPE x)
698 {
699   ++count;
700   P ();
701   return x;
702 }
703
704 long int
705 (F(lround)) (TYPE x)
706 {
707   ++count;
708   P ();
709   return x;
710 }
711
712 long long int
713 (F(llrint)) (TYPE x)
714 {
715   ++count;
716   P ();
717   return x;
718 }
719
720 long long int
721 (F(llround)) (TYPE x)
722 {
723   ++count;
724   P ();
725   return x;
726 }
727
728 TYPE
729 (F(erf)) (TYPE x)
730 {
731   ++count;
732   P ();
733   return x;
734 }
735
736 TYPE
737 (F(erfc)) (TYPE x)
738 {
739   ++count;
740   P ();
741   return x;
742 }
743
744 TYPE
745 (F(tgamma)) (TYPE x)
746 {
747   ++count;
748   P ();
749   return x;
750 }
751
752 TYPE
753 (F(lgamma)) (TYPE x)
754 {
755   ++count;
756   P ();
757   return x;
758 }
759
760 TYPE
761 (F(rint)) (TYPE x)
762 {
763   ++count;
764   P ();
765   return x;
766 }
767
768 TYPE
769 (F(nextafter)) (TYPE x, TYPE y)
770 {
771   ++count;
772   P ();
773   return x + y;
774 }
775
776 TYPE
777 (F(nexttoward)) (TYPE x, long double y)
778 {
779   ++count;
780   P ();
781   return x + y;
782 }
783
784 TYPE
785 (F(remainder)) (TYPE x, TYPE y)
786 {
787   ++count;
788   P ();
789   return x + y;
790 }
791
792 TYPE
793 (F(scalb)) (TYPE x, TYPE y)
794 {
795   ++count;
796   P ();
797   return x + y;
798 }
799
800 TYPE
801 (F(scalbn)) (TYPE x, int y)
802 {
803   ++count;
804   P ();
805   return x + y;
806 }
807
808 TYPE
809 (F(scalbln)) (TYPE x, long int y)
810 {
811   ++count;
812   P ();
813   return x + y;
814 }
815
816 int
817 (F(ilogb)) (TYPE x)
818 {
819   ++count;
820   P ();
821   return x;
822 }
823
824 TYPE
825 (F(fdim)) (TYPE x, TYPE y)
826 {
827   ++count;
828   P ();
829   return x + y;
830 }
831
832 TYPE
833 (F(fmin)) (TYPE x, TYPE y)
834 {
835   ++count;
836   P ();
837   return x + y;
838 }
839
840 TYPE
841 (F(fmax)) (TYPE x, TYPE y)
842 {
843   ++count;
844   P ();
845   return x + y;
846 }
847
848 TYPE
849 (F(fma)) (TYPE x, TYPE y, TYPE z)
850 {
851   ++count;
852   P ();
853   return x + y + z;
854 }
855
856 complex TYPE
857 (F(cacos)) (complex TYPE x)
858 {
859   ++ccount;
860   P ();
861   return x;
862 }
863
864 complex TYPE
865 (F(casin)) (complex TYPE x)
866 {
867   ++ccount;
868   P ();
869   return x;
870 }
871
872 complex TYPE
873 (F(catan)) (complex TYPE x)
874 {
875   ++ccount;
876   P ();
877   return x;
878 }
879
880 complex TYPE
881 (F(ccos)) (complex TYPE x)
882 {
883   ++ccount;
884   P ();
885   return x;
886 }
887
888 complex TYPE
889 (F(csin)) (complex TYPE x)
890 {
891   ++ccount;
892   P ();
893   return x;
894 }
895
896 complex TYPE
897 (F(ctan)) (complex TYPE x)
898 {
899   ++ccount;
900   P ();
901   return x;
902 }
903
904 complex TYPE
905 (F(cacosh)) (complex TYPE x)
906 {
907   ++ccount;
908   P ();
909   return x;
910 }
911
912 complex TYPE
913 (F(casinh)) (complex TYPE x)
914 {
915   ++ccount;
916   P ();
917   return x;
918 }
919
920 complex TYPE
921 (F(catanh)) (complex TYPE x)
922 {
923   ++ccount;
924   P ();
925   return x;
926 }
927
928 complex TYPE
929 (F(ccosh)) (complex TYPE x)
930 {
931   ++ccount;
932   P ();
933   return x;
934 }
935
936 complex TYPE
937 (F(csinh)) (complex TYPE x)
938 {
939   ++ccount;
940   P ();
941   return x;
942 }
943
944 complex TYPE
945 (F(ctanh)) (complex TYPE x)
946 {
947   ++ccount;
948   P ();
949   return x;
950 }
951
952 complex TYPE
953 (F(cexp)) (complex TYPE x)
954 {
955   ++ccount;
956   P ();
957   return x;
958 }
959
960 complex TYPE
961 (F(clog)) (complex TYPE x)
962 {
963   ++ccount;
964   P ();
965   return x;
966 }
967
968 complex TYPE
969 (F(csqrt)) (complex TYPE x)
970 {
971   ++ccount;
972   P ();
973   return x;
974 }
975
976 complex TYPE
977 (F(cpow)) (complex TYPE x, complex TYPE y)
978 {
979   ++ccount;
980   P ();
981   return x + y;
982 }
983
984 TYPE
985 (F(cabs)) (complex TYPE x)
986 {
987   ++ccount;
988   P ();
989   return x;
990 }
991
992 TYPE
993 (F(carg)) (complex TYPE x)
994 {
995   ++ccount;
996   P ();
997   return x;
998 }
999
1000 TYPE
1001 (F(creal)) (complex TYPE x)
1002 {
1003   ++ccount;
1004   P ();
1005   return __real__ x;
1006 }
1007
1008 TYPE
1009 (F(cimag)) (complex TYPE x)
1010 {
1011   ++ccount;
1012   P ();
1013   return __imag__ x;
1014 }
1015
1016 complex TYPE
1017 (F(conj)) (complex TYPE x)
1018 {
1019   ++ccount;
1020   P ();
1021   return x;
1022 }
1023
1024 complex TYPE
1025 (F(cproj)) (complex TYPE x)
1026 {
1027   ++ccount;
1028   P ();
1029   return x;
1030 }
1031
1032 #undef F
1033 #undef TYPE
1034 #undef count
1035 #undef ccount
1036 #undef TEST_INT
1037 #endif