2003-04-13 Jakub Jelinek <jakub@redhat.com>
[glibc.git] / math / test-tgmath.c
blob24474ce25442289f97df035e758dedfde81b2dd9
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001, 2003 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 static void compile_testl (void);
35 float fx;
36 double dx;
37 long double lx;
39 int count_double;
40 int count_float;
41 int count_ldouble;
43 #define NCALLS 115
44 #define NCALLS_INT 4
46 int
47 main (void)
49 int result = 0;
51 count_float = count_double = count_ldouble = 0;
52 compile_test ();
53 if (count_float != 0)
55 puts ("float function called for double test");
56 result = 1;
58 if (count_ldouble != 0)
60 puts ("long double function called for double test");
61 result = 1;
63 if (count_double < NCALLS + NCALLS_INT)
65 printf ("double functions not called often enough (%d)\n",
66 count_double);
67 result = 1;
69 else if (count_double > NCALLS + NCALLS_INT)
71 printf ("double functions called too often (%d)\n",
72 count_double);
73 result = 1;
76 count_float = count_double = count_ldouble = 0;
77 compile_testf ();
78 if (count_double != 0)
80 puts ("double function called for float test");
81 result = 1;
83 if (count_ldouble != 0)
85 puts ("long double function called for float test");
86 result = 1;
88 if (count_float < NCALLS)
90 printf ("float functions not called often enough (%d)\n", count_float);
91 result = 1;
93 else if (count_float > NCALLS)
95 printf ("float functions called too often (%d)\n",
96 count_double);
97 result = 1;
100 #ifndef NO_LONG_DOUBLE
101 count_float = count_double = count_ldouble = 0;
102 compile_testl ();
103 if (count_float != 0)
105 puts ("float function called for long double test");
106 result = 1;
108 if (count_double != 0)
110 puts ("double function called for long double test");
111 result = 1;
113 if (count_ldouble < NCALLS)
115 printf ("long double functions not called often enough (%d)\n",
116 count_ldouble);
117 result = 1;
119 else if (count_ldouble > NCALLS)
121 printf ("long double functions called too often (%d)\n",
122 count_double);
123 result = 1;
125 #endif
127 return result;
130 /* Now generate the three functions. */
131 #define HAVE_MAIN
133 #define F(name) name
134 #define TYPE double
135 #define TEST_INT 1
136 #define x dx
137 #define count count_double
138 #include "test-tgmath.c"
140 #define F(name) name##f
141 #define TYPE float
142 #define x fx
143 #define count count_float
144 #include "test-tgmath.c"
146 #ifndef NO_LONG_DOUBLE
147 #define F(name) name##l
148 #define TYPE long double
149 #define x lx
150 #define count count_ldouble
151 #include "test-tgmath.c"
152 #endif
154 #else
156 #ifdef DEBUG
157 #define P() puts (__FUNCTION__)
158 #else
159 #define P()
160 #endif
162 static void
163 F(compile_test) (void)
165 TYPE a, b, c = 1.0;
166 int i;
167 long int j;
168 long long int k;
170 a = cos (cos (x));
171 b = acos (acos (a));
172 a = sin (sin (x));
173 b = asin (asin (a));
174 a = tan (tan (x));
175 b = atan (atan (a));
176 c = atan2 (atan2 (a, c), atan2 (b, x));
177 a = cosh (cosh (x));
178 b = acosh (acosh (a));
179 a = sinh (sinh (x));
180 b = asinh (asinh (a));
181 a = tanh (tanh (x));
182 b = atanh (atanh (a));
183 a = exp (exp (x));
184 b = log (log (a));
185 a = log10 (log10 (x));
186 b = ldexp (ldexp (a, 1), 5);
187 a = frexp (frexp (x, &i), &i);
188 b = expm1 (expm1 (a));
189 a = log1p (log1p (x));
190 b = logb (logb (a));
191 a = exp2 (exp2 (x));
192 b = log2 (log2 (a));
193 a = pow (pow (x, a), pow (c, b));
194 b = sqrt (sqrt (a));
195 a = hypot (hypot (x, b), hypot (c, a));
196 b = cbrt (cbrt (a));
197 a = ceil (ceil (x));
198 b = fabs (fabs (a));
199 a = floor (floor (x));
200 b = fmod (fmod (a, b), fmod (c, x));
201 a = nearbyint (nearbyint (x));
202 b = round (round (a));
203 a = trunc (trunc (x));
204 b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
205 j = lrint (x) + lround (a);
206 k = llrint (b) + llround (c);
207 a = erf (erf (x));
208 b = erfc (erfc (a));
209 a = tgamma (tgamma (x));
210 b = lgamma (lgamma (a));
211 a = rint (rint (x));
212 b = nextafter (nextafter (a, b), nextafter (c, x));
213 a = nexttoward (nexttoward (x, a), c);
214 b = remainder (remainder (a, b), remainder (c, x));
215 a = scalb (scalb (x, a), (TYPE) (6));
216 k = scalbn (a, 7) + scalbln (c, 10l);
217 i = ilogb (x);
218 a = fdim (fdim (x, a), fdim (c, b));
219 b = fmax (fmax (a, x), fmax (c, b));
220 a = fmin (fmin (x, a), fmin (c, b));
221 b = fma (sin (a), sin (x), sin (c));
223 #ifdef TEST_INT
224 a = atan2 (i, b);
225 b = remquo (i, a, &i);
226 c = fma (i, b, i);
227 a = pow (i, c);
228 #endif
230 #undef x
233 TYPE
234 (F(cos)) (TYPE x)
236 ++count;
237 return x;
240 TYPE
241 (F(acos)) (TYPE x)
243 ++count;
244 P();
245 return x;
248 TYPE
249 (F(sin)) (TYPE x)
251 ++count;
252 P();
253 return x;
256 TYPE
257 (F(asin)) (TYPE x)
259 ++count;
260 P();
261 return x;
264 TYPE
265 (F(tan)) (TYPE x)
267 ++count;
268 P();
269 return x;
272 TYPE
273 (F(atan)) (TYPE x)
275 ++count;
276 P();
277 return x;
280 TYPE
281 (F(atan2)) (TYPE x, TYPE y)
283 ++count;
284 P();
285 return x + y;
288 TYPE
289 (F(cosh)) (TYPE x)
291 ++count;
292 P();
293 return x;
296 TYPE
297 (F(acosh)) (TYPE x)
299 ++count;
300 P();
301 return x;
304 TYPE
305 (F(sinh)) (TYPE x)
307 ++count;
308 P();
309 return x;
312 TYPE
313 (F(asinh)) (TYPE x)
315 ++count;
316 P();
317 return x;
320 TYPE
321 (F(tanh)) (TYPE x)
323 ++count;
324 P();
325 return x;
328 TYPE
329 (F(atanh)) (TYPE x)
331 ++count;
332 P();
333 return x;
336 TYPE
337 (F(exp)) (TYPE x)
339 ++count;
340 P();
341 return x;
344 TYPE
345 (F(log)) (TYPE x)
347 ++count;
348 P();
349 return x;
352 TYPE
353 (F(log10)) (TYPE x)
355 ++count;
356 P();
357 return x;
360 TYPE
361 (F(ldexp)) (TYPE x, int y)
363 ++count;
364 P();
365 return x;
368 TYPE
369 (F(frexp)) (TYPE x, int *y)
371 ++count;
372 P();
373 return x;
376 TYPE
377 (F(expm1)) (TYPE x)
379 ++count;
380 P();
381 return x;
384 TYPE
385 (F(log1p)) (TYPE x)
387 ++count;
388 P();
389 return x;
392 TYPE
393 (F(logb)) (TYPE x)
395 ++count;
396 P();
397 return x;
400 TYPE
401 (F(exp2)) (TYPE x)
403 ++count;
404 P();
405 return x;
408 TYPE
409 (F(log2)) (TYPE x)
411 ++count;
412 P();
413 return x;
416 TYPE
417 (F(pow)) (TYPE x, TYPE y)
419 ++count;
420 P();
421 return x + y;
424 TYPE
425 (F(sqrt)) (TYPE x)
427 ++count;
428 P();
429 return x;
432 TYPE
433 (F(hypot)) (TYPE x, TYPE y)
435 ++count;
436 P();
437 return x + y;
440 TYPE
441 (F(cbrt)) (TYPE x)
443 ++count;
444 P();
445 return x;
448 TYPE
449 (F(ceil)) (TYPE x)
451 ++count;
452 P();
453 return x;
456 TYPE
457 (F(fabs)) (TYPE x)
459 ++count;
460 P();
461 return x;
464 TYPE
465 (F(floor)) (TYPE x)
467 ++count;
468 P();
469 return x;
472 TYPE
473 (F(fmod)) (TYPE x, TYPE y)
475 ++count;
476 P();
477 return x + y;
480 TYPE
481 (F(nearbyint)) (TYPE x)
483 ++count;
484 P();
485 return x;
488 TYPE
489 (F(round)) (TYPE x)
491 ++count;
492 P();
493 return x;
496 TYPE
497 (F(trunc)) (TYPE x)
499 ++count;
500 P();
501 return x;
504 TYPE
505 (F(remquo)) (TYPE x, TYPE y, int *i)
507 ++count;
508 P();
509 return x + y;
512 long int
513 (F(lrint)) (TYPE x)
515 ++count;
516 P();
517 return x;
520 long int
521 (F(lround)) (TYPE x)
523 ++count;
524 P();
525 return x;
528 long long int
529 (F(llrint)) (TYPE x)
531 ++count;
532 P();
533 return x;
536 long long int
537 (F(llround)) (TYPE x)
539 ++count;
540 P();
541 return x;
544 TYPE
545 (F(erf)) (TYPE x)
547 ++count;
548 P();
549 return x;
552 TYPE
553 (F(erfc)) (TYPE x)
555 ++count;
556 P();
557 return x;
560 TYPE
561 (F(tgamma)) (TYPE x)
563 ++count;
564 P();
565 return x;
568 TYPE
569 (F(lgamma)) (TYPE x)
571 ++count;
572 P();
573 return x;
576 TYPE
577 (F(rint)) (TYPE x)
579 ++count;
580 P();
581 return x;
584 TYPE
585 (F(nextafter)) (TYPE x, TYPE y)
587 ++count;
588 P();
589 return x + y;
592 TYPE
593 (F(nexttoward)) (TYPE x, long double y)
595 ++count;
596 P();
597 return x;
600 TYPE
601 (F(remainder)) (TYPE x, TYPE y)
603 ++count;
604 P();
605 return x + y;
608 TYPE
609 (F(scalb)) (TYPE x, TYPE y)
611 ++count;
612 P();
613 return x + y;
616 TYPE
617 (F(scalbn)) (TYPE x, int y)
619 ++count;
620 P();
621 return x;
624 TYPE
625 (F(scalbln)) (TYPE x, long int y)
627 ++count;
628 P();
629 return x;
633 (F(ilogb)) (TYPE x)
635 ++count;
636 P();
637 return x;
640 TYPE
641 (F(fdim)) (TYPE x, TYPE y)
643 ++count;
644 P();
645 return x + y;
648 TYPE
649 (F(fmin)) (TYPE x, TYPE y)
651 ++count;
652 P();
653 return x + y;
656 TYPE
657 (F(fmax)) (TYPE x, TYPE y)
659 ++count;
660 P();
661 return x + y;
664 TYPE
665 (F(fma)) (TYPE x, TYPE y, TYPE z)
667 ++count;
668 P();
669 return x + y + z;
672 #undef F
673 #undef TYPE
674 #undef count
675 #undef TEST_INT
676 #endif