Rejigger i386 dl-sysdep.h files.
[glibc.git] / math / test-tgmath.c
blob5aa5b32e4786f623862ade52a390fdf886918378
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001-2013 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 115
54 #define NCALLS_INT 4
55 #define NCCALLS 47
57 int
58 main (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 #else
215 #ifdef DEBUG
216 #define P() puts (__FUNCTION__)
217 #else
218 #define P()
219 #endif
221 static void
222 F(compile_test) (void)
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;
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));
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;
292 saved_count = count;
293 if (ccount != 0)
294 ccount = -10000;
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;
322 if (saved_count != count)
323 count = -10000;
325 if (0)
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);
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
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);
411 #undef x
412 #undef y
413 #undef z
416 TYPE
417 (F(cos)) (TYPE x)
419 ++count;
420 P ();
421 return x;
424 TYPE
425 (F(acos)) (TYPE x)
427 ++count;
428 P ();
429 return x;
432 TYPE
433 (F(sin)) (TYPE x)
435 ++count;
436 P ();
437 return x;
440 TYPE
441 (F(asin)) (TYPE x)
443 ++count;
444 P ();
445 return x;
448 TYPE
449 (F(tan)) (TYPE x)
451 ++count;
452 P ();
453 return x;
456 TYPE
457 (F(atan)) (TYPE x)
459 ++count;
460 P ();
461 return x;
464 TYPE
465 (F(atan2)) (TYPE x, TYPE y)
467 ++count;
468 P ();
469 return x + y;
472 TYPE
473 (F(cosh)) (TYPE x)
475 ++count;
476 P ();
477 return x;
480 TYPE
481 (F(acosh)) (TYPE x)
483 ++count;
484 P ();
485 return x;
488 TYPE
489 (F(sinh)) (TYPE x)
491 ++count;
492 P ();
493 return x;
496 TYPE
497 (F(asinh)) (TYPE x)
499 ++count;
500 P ();
501 return x;
504 TYPE
505 (F(tanh)) (TYPE x)
507 ++count;
508 P ();
509 return x;
512 TYPE
513 (F(atanh)) (TYPE x)
515 ++count;
516 P ();
517 return x;
520 TYPE
521 (F(exp)) (TYPE x)
523 ++count;
524 P ();
525 return x;
528 TYPE
529 (F(log)) (TYPE x)
531 ++count;
532 P ();
533 return x;
536 TYPE
537 (F(log10)) (TYPE x)
539 ++count;
540 P ();
541 return x;
544 TYPE
545 (F(ldexp)) (TYPE x, int y)
547 ++count;
548 P ();
549 return x + y;
552 TYPE
553 (F(frexp)) (TYPE x, int *y)
555 ++count;
556 P ();
557 return x + *y;
560 TYPE
561 (F(expm1)) (TYPE x)
563 ++count;
564 P ();
565 return x;
568 TYPE
569 (F(log1p)) (TYPE x)
571 ++count;
572 P ();
573 return x;
576 TYPE
577 (F(logb)) (TYPE x)
579 ++count;
580 P ();
581 return x;
584 TYPE
585 (F(exp2)) (TYPE x)
587 ++count;
588 P ();
589 return x;
592 TYPE
593 (F(log2)) (TYPE x)
595 ++count;
596 P ();
597 return x;
600 TYPE
601 (F(pow)) (TYPE x, TYPE y)
603 ++count;
604 P ();
605 return x + y;
608 TYPE
609 (F(sqrt)) (TYPE x)
611 ++count;
612 P ();
613 return x;
616 TYPE
617 (F(hypot)) (TYPE x, TYPE y)
619 ++count;
620 P ();
621 return x + y;
624 TYPE
625 (F(cbrt)) (TYPE x)
627 ++count;
628 P ();
629 return x;
632 TYPE
633 (F(ceil)) (TYPE x)
635 ++count;
636 P ();
637 return x;
640 TYPE
641 (F(fabs)) (TYPE x)
643 ++count;
644 P ();
645 return x;
648 TYPE
649 (F(floor)) (TYPE x)
651 ++count;
652 P ();
653 return x;
656 TYPE
657 (F(fmod)) (TYPE x, TYPE y)
659 ++count;
660 P ();
661 return x + y;
664 TYPE
665 (F(nearbyint)) (TYPE x)
667 ++count;
668 P ();
669 return x;
672 TYPE
673 (F(round)) (TYPE x)
675 ++count;
676 P ();
677 return x;
680 TYPE
681 (F(trunc)) (TYPE x)
683 ++count;
684 P ();
685 return x;
688 TYPE
689 (F(remquo)) (TYPE x, TYPE y, int *i)
691 ++count;
692 P ();
693 return x + y + *i;
696 long int
697 (F(lrint)) (TYPE x)
699 ++count;
700 P ();
701 return x;
704 long int
705 (F(lround)) (TYPE x)
707 ++count;
708 P ();
709 return x;
712 long long int
713 (F(llrint)) (TYPE x)
715 ++count;
716 P ();
717 return x;
720 long long int
721 (F(llround)) (TYPE x)
723 ++count;
724 P ();
725 return x;
728 TYPE
729 (F(erf)) (TYPE x)
731 ++count;
732 P ();
733 return x;
736 TYPE
737 (F(erfc)) (TYPE x)
739 ++count;
740 P ();
741 return x;
744 TYPE
745 (F(tgamma)) (TYPE x)
747 ++count;
748 P ();
749 return x;
752 TYPE
753 (F(lgamma)) (TYPE x)
755 ++count;
756 P ();
757 return x;
760 TYPE
761 (F(rint)) (TYPE x)
763 ++count;
764 P ();
765 return x;
768 TYPE
769 (F(nextafter)) (TYPE x, TYPE y)
771 ++count;
772 P ();
773 return x + y;
776 TYPE
777 (F(nexttoward)) (TYPE x, long double y)
779 ++count;
780 P ();
781 return x + y;
784 TYPE
785 (F(remainder)) (TYPE x, TYPE y)
787 ++count;
788 P ();
789 return x + y;
792 TYPE
793 (F(scalb)) (TYPE x, TYPE y)
795 ++count;
796 P ();
797 return x + y;
800 TYPE
801 (F(scalbn)) (TYPE x, int y)
803 ++count;
804 P ();
805 return x + y;
808 TYPE
809 (F(scalbln)) (TYPE x, long int y)
811 ++count;
812 P ();
813 return x + y;
817 (F(ilogb)) (TYPE x)
819 ++count;
820 P ();
821 return x;
824 TYPE
825 (F(fdim)) (TYPE x, TYPE y)
827 ++count;
828 P ();
829 return x + y;
832 TYPE
833 (F(fmin)) (TYPE x, TYPE y)
835 ++count;
836 P ();
837 return x + y;
840 TYPE
841 (F(fmax)) (TYPE x, TYPE y)
843 ++count;
844 P ();
845 return x + y;
848 TYPE
849 (F(fma)) (TYPE x, TYPE y, TYPE z)
851 ++count;
852 P ();
853 return x + y + z;
856 complex TYPE
857 (F(cacos)) (complex TYPE x)
859 ++ccount;
860 P ();
861 return x;
864 complex TYPE
865 (F(casin)) (complex TYPE x)
867 ++ccount;
868 P ();
869 return x;
872 complex TYPE
873 (F(catan)) (complex TYPE x)
875 ++ccount;
876 P ();
877 return x;
880 complex TYPE
881 (F(ccos)) (complex TYPE x)
883 ++ccount;
884 P ();
885 return x;
888 complex TYPE
889 (F(csin)) (complex TYPE x)
891 ++ccount;
892 P ();
893 return x;
896 complex TYPE
897 (F(ctan)) (complex TYPE x)
899 ++ccount;
900 P ();
901 return x;
904 complex TYPE
905 (F(cacosh)) (complex TYPE x)
907 ++ccount;
908 P ();
909 return x;
912 complex TYPE
913 (F(casinh)) (complex TYPE x)
915 ++ccount;
916 P ();
917 return x;
920 complex TYPE
921 (F(catanh)) (complex TYPE x)
923 ++ccount;
924 P ();
925 return x;
928 complex TYPE
929 (F(ccosh)) (complex TYPE x)
931 ++ccount;
932 P ();
933 return x;
936 complex TYPE
937 (F(csinh)) (complex TYPE x)
939 ++ccount;
940 P ();
941 return x;
944 complex TYPE
945 (F(ctanh)) (complex TYPE x)
947 ++ccount;
948 P ();
949 return x;
952 complex TYPE
953 (F(cexp)) (complex TYPE x)
955 ++ccount;
956 P ();
957 return x;
960 complex TYPE
961 (F(clog)) (complex TYPE x)
963 ++ccount;
964 P ();
965 return x;
968 complex TYPE
969 (F(csqrt)) (complex TYPE x)
971 ++ccount;
972 P ();
973 return x;
976 complex TYPE
977 (F(cpow)) (complex TYPE x, complex TYPE y)
979 ++ccount;
980 P ();
981 return x + y;
984 TYPE
985 (F(cabs)) (complex TYPE x)
987 ++ccount;
988 P ();
989 return x;
992 TYPE
993 (F(carg)) (complex TYPE x)
995 ++ccount;
996 P ();
997 return x;
1000 TYPE
1001 (F(creal)) (complex TYPE x)
1003 ++ccount;
1004 P ();
1005 return __real__ x;
1008 TYPE
1009 (F(cimag)) (complex TYPE x)
1011 ++ccount;
1012 P ();
1013 return __imag__ x;
1016 complex TYPE
1017 (F(conj)) (complex TYPE x)
1019 ++ccount;
1020 P ();
1021 return x;
1024 complex TYPE
1025 (F(cproj)) (complex TYPE x)
1027 ++ccount;
1028 P ();
1029 return x;
1032 #undef F
1033 #undef TYPE
1034 #undef count
1035 #undef ccount
1036 #undef TEST_INT
1037 #endif