Updated to fedora-glibc-20090320T1944
[glibc.git] / math / test-tgmath.c
blob8ec7fc45d0c4f73d27c87b39b702f55a59de84f8
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001, 2003, 2004, 2007 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, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #ifndef HAVE_MAIN
23 #undef __NO_MATH_INLINES
24 #define __NO_MATH_INLINES 1
25 #include <math.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 115
55 #define NCALLS_INT 4
56 #define NCCALLS 47
58 int
59 main (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 #else
216 #ifdef DEBUG
217 #define P() puts (__FUNCTION__)
218 #else
219 #define P()
220 #endif
222 static void
223 F(compile_test) (void)
225 TYPE a, b, c = 1.0;
226 complex TYPE d;
227 int i;
228 int saved_count;
229 long int j;
230 long long int k;
232 a = cos (cos (x));
233 b = acos (acos (a));
234 a = sin (sin (x));
235 b = asin (asin (a));
236 a = tan (tan (x));
237 b = atan (atan (a));
238 c = atan2 (atan2 (a, c), atan2 (b, x));
239 a = cosh (cosh (x));
240 b = acosh (acosh (a));
241 a = sinh (sinh (x));
242 b = asinh (asinh (a));
243 a = tanh (tanh (x));
244 b = atanh (atanh (a));
245 a = exp (exp (x));
246 b = log (log (a));
247 a = log10 (log10 (x));
248 b = ldexp (ldexp (a, 1), 5);
249 a = frexp (frexp (x, &i), &i);
250 b = expm1 (expm1 (a));
251 a = log1p (log1p (x));
252 b = logb (logb (a));
253 a = exp2 (exp2 (x));
254 b = log2 (log2 (a));
255 a = pow (pow (x, a), pow (c, b));
256 b = sqrt (sqrt (a));
257 a = hypot (hypot (x, b), hypot (c, a));
258 b = cbrt (cbrt (a));
259 a = ceil (ceil (x));
260 b = fabs (fabs (a));
261 a = floor (floor (x));
262 b = fmod (fmod (a, b), fmod (c, x));
263 a = nearbyint (nearbyint (x));
264 b = round (round (a));
265 a = trunc (trunc (x));
266 b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
267 j = lrint (x) + lround (a);
268 k = llrint (b) + llround (c);
269 a = erf (erf (x));
270 b = erfc (erfc (a));
271 a = tgamma (tgamma (x));
272 b = lgamma (lgamma (a));
273 a = rint (rint (x));
274 b = nextafter (nextafter (a, b), nextafter (c, x));
275 a = nexttoward (nexttoward (x, a), c);
276 b = remainder (remainder (a, b), remainder (c, x));
277 a = scalb (scalb (x, a), (TYPE) (6));
278 k = scalbn (a, 7) + scalbln (c, 10l);
279 i = ilogb (x);
280 a = fdim (fdim (x, a), fdim (c, b));
281 b = fmax (fmax (a, x), fmax (c, b));
282 a = fmin (fmin (x, a), fmin (c, b));
283 b = fma (sin (a), sin (x), sin (c));
285 #ifdef TEST_INT
286 a = atan2 (i, b);
287 b = remquo (i, a, &i);
288 c = fma (i, b, i);
289 a = pow (i, c);
290 #endif
291 x = a + b + c + i + j + k;
293 saved_count = count;
294 if (ccount != 0)
295 ccount = -10000;
297 d = cos (cos (z));
298 z = acos (acos (d));
299 d = sin (sin (z));
300 z = asin (asin (d));
301 d = tan (tan (z));
302 z = atan (atan (d));
303 d = cosh (cosh (z));
304 z = acosh (acosh (d));
305 d = sinh (sinh (z));
306 z = asinh (asinh (d));
307 d = tanh (tanh (z));
308 z = atanh (atanh (d));
309 d = exp (exp (z));
310 z = log (log (d));
311 d = sqrt (sqrt (z));
312 z = conj (conj (d));
313 d = fabs (conj (a));
314 z = pow (pow (a, d), pow (b, z));
315 d = cproj (cproj (z));
316 z += fabs (cproj (a));
317 a = carg (carg (z));
318 b = creal (creal (d));
319 c = cimag (cimag (z));
320 x += a + b + c + i + j + k;
321 z += d;
323 if (saved_count != count)
324 count = -10000;
326 if (0)
328 a = cos (y);
329 a = acos (y);
330 a = sin (y);
331 a = asin (y);
332 a = tan (y);
333 a = atan (y);
334 a = atan2 (y, y);
335 a = cosh (y);
336 a = acosh (y);
337 a = sinh (y);
338 a = asinh (y);
339 a = tanh (y);
340 a = atanh (y);
341 a = exp (y);
342 a = log (y);
343 a = log10 (y);
344 a = ldexp (y, 5);
345 a = frexp (y, &i);
346 a = expm1 (y);
347 a = log1p (y);
348 a = logb (y);
349 a = exp2 (y);
350 a = log2 (y);
351 a = pow (y, y);
352 a = sqrt (y);
353 a = hypot (y, y);
354 a = cbrt (y);
355 a = ceil (y);
356 a = fabs (y);
357 a = floor (y);
358 a = fmod (y, y);
359 a = nearbyint (y);
360 a = round (y);
361 a = trunc (y);
362 a = remquo (y, y, &i);
363 j = lrint (y) + lround (y);
364 k = llrint (y) + llround (y);
365 a = erf (y);
366 a = erfc (y);
367 a = tgamma (y);
368 a = lgamma (y);
369 a = rint (y);
370 a = nextafter (y, y);
371 a = nexttoward (y, y);
372 a = remainder (y, y);
373 a = scalb (y, (const TYPE) (6));
374 k = scalbn (y, 7) + scalbln (y, 10l);
375 i = ilogb (y);
376 a = fdim (y, y);
377 a = fmax (y, y);
378 a = fmin (y, y);
379 a = fma (y, y, y);
381 #ifdef TEST_INT
382 a = atan2 (i, y);
383 a = remquo (i, y, &i);
384 a = fma (i, y, i);
385 a = pow (i, y);
386 #endif
388 d = cos ((const complex TYPE) z);
389 d = acos ((const complex TYPE) z);
390 d = sin ((const complex TYPE) z);
391 d = asin ((const complex TYPE) z);
392 d = tan ((const complex TYPE) z);
393 d = atan ((const complex TYPE) z);
394 d = cosh ((const complex TYPE) z);
395 d = acosh ((const complex TYPE) z);
396 d = sinh ((const complex TYPE) z);
397 d = asinh ((const complex TYPE) z);
398 d = tanh ((const complex TYPE) z);
399 d = atanh ((const complex TYPE) z);
400 d = exp ((const complex TYPE) z);
401 d = log ((const complex TYPE) z);
402 d = sqrt ((const complex TYPE) z);
403 d = pow ((const complex TYPE) z, (const complex TYPE) z);
404 d = fabs ((const complex TYPE) z);
405 d = carg ((const complex TYPE) z);
406 d = creal ((const complex TYPE) z);
407 d = cimag ((const complex TYPE) z);
408 d = conj ((const complex TYPE) z);
409 d = cproj ((const complex TYPE) z);
412 #undef x
413 #undef y
414 #undef z
417 TYPE
418 (F(cos)) (TYPE x)
420 ++count;
421 P ();
422 return x;
425 TYPE
426 (F(acos)) (TYPE x)
428 ++count;
429 P ();
430 return x;
433 TYPE
434 (F(sin)) (TYPE x)
436 ++count;
437 P ();
438 return x;
441 TYPE
442 (F(asin)) (TYPE x)
444 ++count;
445 P ();
446 return x;
449 TYPE
450 (F(tan)) (TYPE x)
452 ++count;
453 P ();
454 return x;
457 TYPE
458 (F(atan)) (TYPE x)
460 ++count;
461 P ();
462 return x;
465 TYPE
466 (F(atan2)) (TYPE x, TYPE y)
468 ++count;
469 P ();
470 return x + y;
473 TYPE
474 (F(cosh)) (TYPE x)
476 ++count;
477 P ();
478 return x;
481 TYPE
482 (F(acosh)) (TYPE x)
484 ++count;
485 P ();
486 return x;
489 TYPE
490 (F(sinh)) (TYPE x)
492 ++count;
493 P ();
494 return x;
497 TYPE
498 (F(asinh)) (TYPE x)
500 ++count;
501 P ();
502 return x;
505 TYPE
506 (F(tanh)) (TYPE x)
508 ++count;
509 P ();
510 return x;
513 TYPE
514 (F(atanh)) (TYPE x)
516 ++count;
517 P ();
518 return x;
521 TYPE
522 (F(exp)) (TYPE x)
524 ++count;
525 P ();
526 return x;
529 TYPE
530 (F(log)) (TYPE x)
532 ++count;
533 P ();
534 return x;
537 TYPE
538 (F(log10)) (TYPE x)
540 ++count;
541 P ();
542 return x;
545 TYPE
546 (F(ldexp)) (TYPE x, int y)
548 ++count;
549 P ();
550 return x + y;
553 TYPE
554 (F(frexp)) (TYPE x, int *y)
556 ++count;
557 P ();
558 return x + *y;
561 TYPE
562 (F(expm1)) (TYPE x)
564 ++count;
565 P ();
566 return x;
569 TYPE
570 (F(log1p)) (TYPE x)
572 ++count;
573 P ();
574 return x;
577 TYPE
578 (F(logb)) (TYPE x)
580 ++count;
581 P ();
582 return x;
585 TYPE
586 (F(exp2)) (TYPE x)
588 ++count;
589 P ();
590 return x;
593 TYPE
594 (F(log2)) (TYPE x)
596 ++count;
597 P ();
598 return x;
601 TYPE
602 (F(pow)) (TYPE x, TYPE y)
604 ++count;
605 P ();
606 return x + y;
609 TYPE
610 (F(sqrt)) (TYPE x)
612 ++count;
613 P ();
614 return x;
617 TYPE
618 (F(hypot)) (TYPE x, TYPE y)
620 ++count;
621 P ();
622 return x + y;
625 TYPE
626 (F(cbrt)) (TYPE x)
628 ++count;
629 P ();
630 return x;
633 TYPE
634 (F(ceil)) (TYPE x)
636 ++count;
637 P ();
638 return x;
641 TYPE
642 (F(fabs)) (TYPE x)
644 ++count;
645 P ();
646 return x;
649 TYPE
650 (F(floor)) (TYPE x)
652 ++count;
653 P ();
654 return x;
657 TYPE
658 (F(fmod)) (TYPE x, TYPE y)
660 ++count;
661 P ();
662 return x + y;
665 TYPE
666 (F(nearbyint)) (TYPE x)
668 ++count;
669 P ();
670 return x;
673 TYPE
674 (F(round)) (TYPE x)
676 ++count;
677 P ();
678 return x;
681 TYPE
682 (F(trunc)) (TYPE x)
684 ++count;
685 P ();
686 return x;
689 TYPE
690 (F(remquo)) (TYPE x, TYPE y, int *i)
692 ++count;
693 P ();
694 return x + y + *i;
697 long int
698 (F(lrint)) (TYPE x)
700 ++count;
701 P ();
702 return x;
705 long int
706 (F(lround)) (TYPE x)
708 ++count;
709 P ();
710 return x;
713 long long int
714 (F(llrint)) (TYPE x)
716 ++count;
717 P ();
718 return x;
721 long long int
722 (F(llround)) (TYPE x)
724 ++count;
725 P ();
726 return x;
729 TYPE
730 (F(erf)) (TYPE x)
732 ++count;
733 P ();
734 return x;
737 TYPE
738 (F(erfc)) (TYPE x)
740 ++count;
741 P ();
742 return x;
745 TYPE
746 (F(tgamma)) (TYPE x)
748 ++count;
749 P ();
750 return x;
753 TYPE
754 (F(lgamma)) (TYPE x)
756 ++count;
757 P ();
758 return x;
761 TYPE
762 (F(rint)) (TYPE x)
764 ++count;
765 P ();
766 return x;
769 TYPE
770 (F(nextafter)) (TYPE x, TYPE y)
772 ++count;
773 P ();
774 return x + y;
777 TYPE
778 (F(nexttoward)) (TYPE x, long double y)
780 ++count;
781 P ();
782 return x + y;
785 TYPE
786 (F(remainder)) (TYPE x, TYPE y)
788 ++count;
789 P ();
790 return x + y;
793 TYPE
794 (F(scalb)) (TYPE x, TYPE y)
796 ++count;
797 P ();
798 return x + y;
801 TYPE
802 (F(scalbn)) (TYPE x, int y)
804 ++count;
805 P ();
806 return x + y;
809 TYPE
810 (F(scalbln)) (TYPE x, long int y)
812 ++count;
813 P ();
814 return x + y;
818 (F(ilogb)) (TYPE x)
820 ++count;
821 P ();
822 return x;
825 TYPE
826 (F(fdim)) (TYPE x, TYPE y)
828 ++count;
829 P ();
830 return x + y;
833 TYPE
834 (F(fmin)) (TYPE x, TYPE y)
836 ++count;
837 P ();
838 return x + y;
841 TYPE
842 (F(fmax)) (TYPE x, TYPE y)
844 ++count;
845 P ();
846 return x + y;
849 TYPE
850 (F(fma)) (TYPE x, TYPE y, TYPE z)
852 ++count;
853 P ();
854 return x + y + z;
857 complex TYPE
858 (F(cacos)) (complex TYPE x)
860 ++ccount;
861 P ();
862 return x;
865 complex TYPE
866 (F(casin)) (complex TYPE x)
868 ++ccount;
869 P ();
870 return x;
873 complex TYPE
874 (F(catan)) (complex TYPE x)
876 ++ccount;
877 P ();
878 return x;
881 complex TYPE
882 (F(ccos)) (complex TYPE x)
884 ++ccount;
885 P ();
886 return x;
889 complex TYPE
890 (F(csin)) (complex TYPE x)
892 ++ccount;
893 P ();
894 return x;
897 complex TYPE
898 (F(ctan)) (complex TYPE x)
900 ++ccount;
901 P ();
902 return x;
905 complex TYPE
906 (F(cacosh)) (complex TYPE x)
908 ++ccount;
909 P ();
910 return x;
913 complex TYPE
914 (F(casinh)) (complex TYPE x)
916 ++ccount;
917 P ();
918 return x;
921 complex TYPE
922 (F(catanh)) (complex TYPE x)
924 ++ccount;
925 P ();
926 return x;
929 complex TYPE
930 (F(ccosh)) (complex TYPE x)
932 ++ccount;
933 P ();
934 return x;
937 complex TYPE
938 (F(csinh)) (complex TYPE x)
940 ++ccount;
941 P ();
942 return x;
945 complex TYPE
946 (F(ctanh)) (complex TYPE x)
948 ++ccount;
949 P ();
950 return x;
953 complex TYPE
954 (F(cexp)) (complex TYPE x)
956 ++ccount;
957 P ();
958 return x;
961 complex TYPE
962 (F(clog)) (complex TYPE x)
964 ++ccount;
965 P ();
966 return x;
969 complex TYPE
970 (F(csqrt)) (complex TYPE x)
972 ++ccount;
973 P ();
974 return x;
977 complex TYPE
978 (F(cpow)) (complex TYPE x, complex TYPE y)
980 ++ccount;
981 P ();
982 return x + y;
985 TYPE
986 (F(cabs)) (complex TYPE x)
988 ++ccount;
989 P ();
990 return x;
993 TYPE
994 (F(carg)) (complex TYPE x)
996 ++ccount;
997 P ();
998 return x;
1001 TYPE
1002 (F(creal)) (complex TYPE x)
1004 ++ccount;
1005 P ();
1006 return __real__ x;
1009 TYPE
1010 (F(cimag)) (complex TYPE x)
1012 ++ccount;
1013 P ();
1014 return __imag__ x;
1017 complex TYPE
1018 (F(conj)) (complex TYPE x)
1020 ++ccount;
1021 P ();
1022 return x;
1025 complex TYPE
1026 (F(cproj)) (complex TYPE x)
1028 ++ccount;
1029 P ();
1030 return x;
1033 #undef F
1034 #undef TYPE
1035 #undef count
1036 #undef ccount
1037 #undef TEST_INT
1038 #endif