typos
[glibc.git] / math / test-tgmath.c
blobf8453d08354ca986fb88bc4b5061b5b35e49785d
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001, 2003, 2004 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;
41 int count_double;
42 int count_float;
43 int count_ldouble;
45 #define NCALLS 115
46 #define NCALLS_INT 4
48 int
49 main (void)
51 int result = 0;
53 count_float = count_double = count_ldouble = 0;
54 compile_test ();
55 if (count_float != 0)
57 puts ("float function called for double test");
58 result = 1;
60 if (count_ldouble != 0)
62 puts ("long double function called for double test");
63 result = 1;
65 if (count_double < NCALLS + NCALLS_INT)
67 printf ("double functions not called often enough (%d)\n",
68 count_double);
69 result = 1;
71 else if (count_double > NCALLS + NCALLS_INT)
73 printf ("double functions called too often (%d)\n",
74 count_double);
75 result = 1;
78 count_float = count_double = count_ldouble = 0;
79 compile_testf ();
80 if (count_double != 0)
82 puts ("double function called for float test");
83 result = 1;
85 if (count_ldouble != 0)
87 puts ("long double function called for float test");
88 result = 1;
90 if (count_float < NCALLS)
92 printf ("float functions not called often enough (%d)\n", count_float);
93 result = 1;
95 else if (count_float > NCALLS)
97 printf ("float functions called too often (%d)\n",
98 count_double);
99 result = 1;
102 #ifndef NO_LONG_DOUBLE
103 count_float = count_double = count_ldouble = 0;
104 compile_testl ();
105 if (count_float != 0)
107 puts ("float function called for long double test");
108 result = 1;
110 if (count_double != 0)
112 puts ("double function called for long double test");
113 result = 1;
115 if (count_ldouble < NCALLS)
117 printf ("long double functions not called often enough (%d)\n",
118 count_ldouble);
119 result = 1;
121 else if (count_ldouble > NCALLS)
123 printf ("long double functions called too often (%d)\n",
124 count_double);
125 result = 1;
127 #endif
129 return result;
132 /* Now generate the three functions. */
133 #define HAVE_MAIN
135 #define F(name) name
136 #define TYPE double
137 #define TEST_INT 1
138 #define x dx
139 #define count count_double
140 #include "test-tgmath.c"
142 #define F(name) name##f
143 #define TYPE float
144 #define x fx
145 #define count count_float
146 #include "test-tgmath.c"
148 #ifndef NO_LONG_DOUBLE
149 #define F(name) name##l
150 #define TYPE long double
151 #define x lx
152 #define count count_ldouble
153 #include "test-tgmath.c"
154 #endif
156 #else
158 #ifdef DEBUG
159 #define P() puts (__FUNCTION__)
160 #else
161 #define P()
162 #endif
164 static void
165 F(compile_test) (void)
167 TYPE a, b, c = 1.0;
168 int i;
169 long int j;
170 long long int k;
172 a = cos (cos (x));
173 b = acos (acos (a));
174 a = sin (sin (x));
175 b = asin (asin (a));
176 a = tan (tan (x));
177 b = atan (atan (a));
178 c = atan2 (atan2 (a, c), atan2 (b, x));
179 a = cosh (cosh (x));
180 b = acosh (acosh (a));
181 a = sinh (sinh (x));
182 b = asinh (asinh (a));
183 a = tanh (tanh (x));
184 b = atanh (atanh (a));
185 a = exp (exp (x));
186 b = log (log (a));
187 a = log10 (log10 (x));
188 b = ldexp (ldexp (a, 1), 5);
189 a = frexp (frexp (x, &i), &i);
190 b = expm1 (expm1 (a));
191 a = log1p (log1p (x));
192 b = logb (logb (a));
193 a = exp2 (exp2 (x));
194 b = log2 (log2 (a));
195 a = pow (pow (x, a), pow (c, b));
196 b = sqrt (sqrt (a));
197 a = hypot (hypot (x, b), hypot (c, a));
198 b = cbrt (cbrt (a));
199 a = ceil (ceil (x));
200 b = fabs (fabs (a));
201 a = floor (floor (x));
202 b = fmod (fmod (a, b), fmod (c, x));
203 a = nearbyint (nearbyint (x));
204 b = round (round (a));
205 a = trunc (trunc (x));
206 b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
207 j = lrint (x) + lround (a);
208 k = llrint (b) + llround (c);
209 a = erf (erf (x));
210 b = erfc (erfc (a));
211 a = tgamma (tgamma (x));
212 b = lgamma (lgamma (a));
213 a = rint (rint (x));
214 b = nextafter (nextafter (a, b), nextafter (c, x));
215 a = nexttoward (nexttoward (x, a), c);
216 b = remainder (remainder (a, b), remainder (c, x));
217 a = scalb (scalb (x, a), (TYPE) (6));
218 k = scalbn (a, 7) + scalbln (c, 10l);
219 i = ilogb (x);
220 a = fdim (fdim (x, a), fdim (c, b));
221 b = fmax (fmax (a, x), fmax (c, b));
222 a = fmin (fmin (x, a), fmin (c, b));
223 b = fma (sin (a), sin (x), sin (c));
225 #ifdef TEST_INT
226 a = atan2 (i, b);
227 b = remquo (i, a, &i);
228 c = fma (i, b, i);
229 a = pow (i, c);
230 #endif
232 #undef x
235 TYPE
236 (F(cos)) (TYPE x)
238 ++count;
239 return x;
242 TYPE
243 (F(acos)) (TYPE x)
245 ++count;
246 P();
247 return x;
250 TYPE
251 (F(sin)) (TYPE x)
253 ++count;
254 P();
255 return x;
258 TYPE
259 (F(asin)) (TYPE x)
261 ++count;
262 P();
263 return x;
266 TYPE
267 (F(tan)) (TYPE x)
269 ++count;
270 P();
271 return x;
274 TYPE
275 (F(atan)) (TYPE x)
277 ++count;
278 P();
279 return x;
282 TYPE
283 (F(atan2)) (TYPE x, TYPE y)
285 ++count;
286 P();
287 return x + y;
290 TYPE
291 (F(cosh)) (TYPE x)
293 ++count;
294 P();
295 return x;
298 TYPE
299 (F(acosh)) (TYPE x)
301 ++count;
302 P();
303 return x;
306 TYPE
307 (F(sinh)) (TYPE x)
309 ++count;
310 P();
311 return x;
314 TYPE
315 (F(asinh)) (TYPE x)
317 ++count;
318 P();
319 return x;
322 TYPE
323 (F(tanh)) (TYPE x)
325 ++count;
326 P();
327 return x;
330 TYPE
331 (F(atanh)) (TYPE x)
333 ++count;
334 P();
335 return x;
338 TYPE
339 (F(exp)) (TYPE x)
341 ++count;
342 P();
343 return x;
346 TYPE
347 (F(log)) (TYPE x)
349 ++count;
350 P();
351 return x;
354 TYPE
355 (F(log10)) (TYPE x)
357 ++count;
358 P();
359 return x;
362 TYPE
363 (F(ldexp)) (TYPE x, int y)
365 ++count;
366 P();
367 return x;
370 TYPE
371 (F(frexp)) (TYPE x, int *y)
373 ++count;
374 P();
375 return x;
378 TYPE
379 (F(expm1)) (TYPE x)
381 ++count;
382 P();
383 return x;
386 TYPE
387 (F(log1p)) (TYPE x)
389 ++count;
390 P();
391 return x;
394 TYPE
395 (F(logb)) (TYPE x)
397 ++count;
398 P();
399 return x;
402 TYPE
403 (F(exp2)) (TYPE x)
405 ++count;
406 P();
407 return x;
410 TYPE
411 (F(log2)) (TYPE x)
413 ++count;
414 P();
415 return x;
418 TYPE
419 (F(pow)) (TYPE x, TYPE y)
421 ++count;
422 P();
423 return x + y;
426 TYPE
427 (F(sqrt)) (TYPE x)
429 ++count;
430 P();
431 return x;
434 TYPE
435 (F(hypot)) (TYPE x, TYPE y)
437 ++count;
438 P();
439 return x + y;
442 TYPE
443 (F(cbrt)) (TYPE x)
445 ++count;
446 P();
447 return x;
450 TYPE
451 (F(ceil)) (TYPE x)
453 ++count;
454 P();
455 return x;
458 TYPE
459 (F(fabs)) (TYPE x)
461 ++count;
462 P();
463 return x;
466 TYPE
467 (F(floor)) (TYPE x)
469 ++count;
470 P();
471 return x;
474 TYPE
475 (F(fmod)) (TYPE x, TYPE y)
477 ++count;
478 P();
479 return x + y;
482 TYPE
483 (F(nearbyint)) (TYPE x)
485 ++count;
486 P();
487 return x;
490 TYPE
491 (F(round)) (TYPE x)
493 ++count;
494 P();
495 return x;
498 TYPE
499 (F(trunc)) (TYPE x)
501 ++count;
502 P();
503 return x;
506 TYPE
507 (F(remquo)) (TYPE x, TYPE y, int *i)
509 ++count;
510 P();
511 return x + y;
514 long int
515 (F(lrint)) (TYPE x)
517 ++count;
518 P();
519 return x;
522 long int
523 (F(lround)) (TYPE x)
525 ++count;
526 P();
527 return x;
530 long long int
531 (F(llrint)) (TYPE x)
533 ++count;
534 P();
535 return x;
538 long long int
539 (F(llround)) (TYPE x)
541 ++count;
542 P();
543 return x;
546 TYPE
547 (F(erf)) (TYPE x)
549 ++count;
550 P();
551 return x;
554 TYPE
555 (F(erfc)) (TYPE x)
557 ++count;
558 P();
559 return x;
562 TYPE
563 (F(tgamma)) (TYPE x)
565 ++count;
566 P();
567 return x;
570 TYPE
571 (F(lgamma)) (TYPE x)
573 ++count;
574 P();
575 return x;
578 TYPE
579 (F(rint)) (TYPE x)
581 ++count;
582 P();
583 return x;
586 TYPE
587 (F(nextafter)) (TYPE x, TYPE y)
589 ++count;
590 P();
591 return x + y;
594 TYPE
595 (F(nexttoward)) (TYPE x, long double y)
597 ++count;
598 P();
599 return x;
602 TYPE
603 (F(remainder)) (TYPE x, TYPE y)
605 ++count;
606 P();
607 return x + y;
610 TYPE
611 (F(scalb)) (TYPE x, TYPE y)
613 ++count;
614 P();
615 return x + y;
618 TYPE
619 (F(scalbn)) (TYPE x, int y)
621 ++count;
622 P();
623 return x;
626 TYPE
627 (F(scalbln)) (TYPE x, long int y)
629 ++count;
630 P();
631 return x;
635 (F(ilogb)) (TYPE x)
637 ++count;
638 P();
639 return x;
642 TYPE
643 (F(fdim)) (TYPE x, TYPE y)
645 ++count;
646 P();
647 return x + y;
650 TYPE
651 (F(fmin)) (TYPE x, TYPE y)
653 ++count;
654 P();
655 return x + y;
658 TYPE
659 (F(fmax)) (TYPE x, TYPE y)
661 ++count;
662 P();
663 return x + y;
666 TYPE
667 (F(fma)) (TYPE x, TYPE y, TYPE z)
669 ++count;
670 P();
671 return x + y + z;
674 #undef F
675 #undef TYPE
676 #undef count
677 #undef TEST_INT
678 #endif