Fix missing backslash in last change.
[glibc.git] / math / test-tgmath.c
blobad63f717373dd4c7c2995c0aa5239d95427c9776
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001 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 Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 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 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 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
45 int
46 main (void)
48 int result = 0;
50 count_float = count_double = count_ldouble = 0;
51 compile_test ();
52 if (count_float != 0)
54 puts ("float function called for double test");
55 result = 1;
57 if (count_ldouble != 0)
59 puts ("long double function called for double test");
60 result = 1;
62 if (count_double < NCALLS)
64 printf ("double functions not called often enough (%d)\n",
65 count_double);
66 result = 1;
68 else if (count_double > NCALLS)
70 printf ("double functions called too often (%d)\n",
71 count_double);
72 result = 1;
75 count_float = count_double = count_ldouble = 0;
76 compile_testf ();
77 if (count_double != 0)
79 puts ("double function called for float test");
80 result = 1;
82 if (count_ldouble != 0)
84 puts ("long double function called for float test");
85 result = 1;
87 if (count_float < NCALLS)
89 printf ("float functions not called often enough (%d)\n", count_float);
90 result = 1;
92 else if (count_float > NCALLS)
94 printf ("float functions called too often (%d)\n",
95 count_double);
96 result = 1;
99 #ifndef NO_LONG_DOUBLE
100 count_float = count_double = count_ldouble = 0;
101 compile_testl ();
102 if (count_float != 0)
104 puts ("float function called for long double test");
105 result = 1;
107 if (count_double != 0)
109 puts ("double function called for long double test");
110 result = 1;
112 if (count_ldouble < NCALLS)
114 printf ("long double functions not called often enough (%d)\n",
115 count_ldouble);
116 result = 1;
118 else if (count_ldouble > NCALLS)
120 printf ("long double functions called too often (%d)\n",
121 count_double);
122 result = 1;
124 #endif
126 return result;
129 /* Now generate the three functions. */
130 #define HAVE_MAIN
132 #define F(name) name
133 #define TYPE double
134 #define x dx
135 #define count count_double
136 #include "test-tgmath.c"
138 #define F(name) name##f
139 #define TYPE float
140 #define x fx
141 #define count count_float
142 #include "test-tgmath.c"
144 #ifndef NO_LONG_DOUBLE
145 #define F(name) name##l
146 #define TYPE long double
147 #define x lx
148 #define count count_ldouble
149 #include "test-tgmath.c"
150 #endif
152 #else
154 #ifdef DEBUG
155 #define P() puts (__FUNCTION__)
156 #else
157 #define P()
158 #endif
160 static void
161 F(compile_test) (void)
163 TYPE a, b, c;
164 int i;
165 long int j;
166 long long int k;
168 a = cos (cos (x));
169 b = acos (acos (a));
170 a = sin (sin (x));
171 b = asin (asin (a));
172 a = tan (tan (x));
173 b = atan (atan (a));
174 c = atan2 (atan2 (a, c), atan2 (b, x));
175 a = cosh (cosh (x));
176 b = acosh (acosh (a));
177 a = sinh (sinh (x));
178 b = asinh (asinh (a));
179 a = tanh (tanh (x));
180 b = atanh (atanh (a));
181 a = exp (exp (x));
182 b = log (log (a));
183 a = log10 (log10 (x));
184 b = ldexp (ldexp (a, 1), 5);
185 a = frexp (frexp (x, &i), &i);
186 b = expm1 (expm1 (a));
187 a = log1p (log1p (x));
188 b = logb (logb (a));
189 a = exp2 (exp2 (x));
190 b = log2 (log2 (a));
191 a = pow (pow (x, a), pow (c, b));
192 b = sqrt (sqrt (a));
193 a = hypot (hypot (x, b), hypot (c, a));
194 b = cbrt (cbrt (a));
195 a = ceil (ceil (x));
196 b = fabs (fabs (a));
197 a = floor (floor (x));
198 b = fmod (fmod (a, b), fmod (c, x));
199 a = nearbyint (nearbyint (x));
200 b = round (round (a));
201 a = trunc (trunc (x));
202 b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
203 j = lrint (x) + lround (a);
204 k = llrint (b) + llround (c);
205 a = erf (erf (x));
206 b = erfc (erfc (a));
207 a = tgamma (tgamma (x));
208 b = lgamma (lgamma (a));
209 a = rint (rint (x));
210 b = nextafter (nextafter (a, b), nextafter (c, x));
211 a = nexttoward (nexttoward (x, a), c);
212 b = remainder (remainder (a, b), remainder (c, x));
213 a = scalb (scalb (x, a), (TYPE) (6));
214 k = scalbn (a, 7) + scalbln (c, 10l);
215 i = ilogb (x);
216 a = fdim (fdim (x, a), fdim (c, b));
217 b = fmax (fmax (a, x), fmax (c, b));
218 a = fmin (fmin (x, a), fmin (c, b));
219 b = fma (sin (a), sin (x), sin (c));
221 #undef x
224 TYPE
225 (F(cos)) (TYPE x)
227 ++count;
228 return x;
231 TYPE
232 (F(acos)) (TYPE x)
234 ++count;
235 P();
236 return x;
239 TYPE
240 (F(sin)) (TYPE x)
242 ++count;
243 P();
244 return x;
247 TYPE
248 (F(asin)) (TYPE x)
250 ++count;
251 P();
252 return x;
255 TYPE
256 (F(tan)) (TYPE x)
258 ++count;
259 P();
260 return x;
263 TYPE
264 (F(atan)) (TYPE x)
266 ++count;
267 P();
268 return x;
271 TYPE
272 (F(atan2)) (TYPE x, TYPE y)
274 ++count;
275 P();
276 return x + y;
279 TYPE
280 (F(cosh)) (TYPE x)
282 ++count;
283 P();
284 return x;
287 TYPE
288 (F(acosh)) (TYPE x)
290 ++count;
291 P();
292 return x;
295 TYPE
296 (F(sinh)) (TYPE x)
298 ++count;
299 P();
300 return x;
303 TYPE
304 (F(asinh)) (TYPE x)
306 ++count;
307 P();
308 return x;
311 TYPE
312 (F(tanh)) (TYPE x)
314 ++count;
315 P();
316 return x;
319 TYPE
320 (F(atanh)) (TYPE x)
322 ++count;
323 P();
324 return x;
327 TYPE
328 (F(exp)) (TYPE x)
330 ++count;
331 P();
332 return x;
335 TYPE
336 (F(log)) (TYPE x)
338 ++count;
339 P();
340 return x;
343 TYPE
344 (F(log10)) (TYPE x)
346 ++count;
347 P();
348 return x;
351 TYPE
352 (F(ldexp)) (TYPE x, int y)
354 ++count;
355 P();
356 return x;
359 TYPE
360 (F(frexp)) (TYPE x, int *y)
362 ++count;
363 P();
364 return x;
367 TYPE
368 (F(expm1)) (TYPE x)
370 ++count;
371 P();
372 return x;
375 TYPE
376 (F(log1p)) (TYPE x)
378 ++count;
379 P();
380 return x;
383 TYPE
384 (F(logb)) (TYPE x)
386 ++count;
387 P();
388 return x;
391 TYPE
392 (F(exp2)) (TYPE x)
394 ++count;
395 P();
396 return x;
399 TYPE
400 (F(log2)) (TYPE x)
402 ++count;
403 P();
404 return x;
407 TYPE
408 (F(pow)) (TYPE x, TYPE y)
410 ++count;
411 P();
412 return x + y;
415 TYPE
416 (F(sqrt)) (TYPE x)
418 ++count;
419 P();
420 return x;
423 TYPE
424 (F(hypot)) (TYPE x, TYPE y)
426 ++count;
427 P();
428 return x + y;
431 TYPE
432 (F(cbrt)) (TYPE x)
434 ++count;
435 P();
436 return x;
439 TYPE
440 (F(ceil)) (TYPE x)
442 ++count;
443 P();
444 return x;
447 TYPE
448 (F(fabs)) (TYPE x)
450 ++count;
451 P();
452 return x;
455 TYPE
456 (F(floor)) (TYPE x)
458 ++count;
459 P();
460 return x;
463 TYPE
464 (F(fmod)) (TYPE x, TYPE y)
466 ++count;
467 P();
468 return x + y;
471 TYPE
472 (F(nearbyint)) (TYPE x)
474 ++count;
475 P();
476 return x;
479 TYPE
480 (F(round)) (TYPE x)
482 ++count;
483 P();
484 return x;
487 TYPE
488 (F(trunc)) (TYPE x)
490 ++count;
491 P();
492 return x;
495 TYPE
496 (F(remquo)) (TYPE x, TYPE y, int *i)
498 ++count;
499 P();
500 return x + y;
503 long int
504 (F(lrint)) (TYPE x)
506 ++count;
507 P();
508 return x;
511 long int
512 (F(lround)) (TYPE x)
514 ++count;
515 P();
516 return x;
519 long long int
520 (F(llrint)) (TYPE x)
522 ++count;
523 P();
524 return x;
527 long long int
528 (F(llround)) (TYPE x)
530 ++count;
531 P();
532 return x;
535 TYPE
536 (F(erf)) (TYPE x)
538 ++count;
539 P();
540 return x;
543 TYPE
544 (F(erfc)) (TYPE x)
546 ++count;
547 P();
548 return x;
551 TYPE
552 (F(tgamma)) (TYPE x)
554 ++count;
555 P();
556 return x;
559 TYPE
560 (F(lgamma)) (TYPE x)
562 ++count;
563 P();
564 return x;
567 TYPE
568 (F(rint)) (TYPE x)
570 ++count;
571 P();
572 return x;
575 TYPE
576 (F(nextafter)) (TYPE x, TYPE y)
578 ++count;
579 P();
580 return x + y;
583 TYPE
584 (F(nexttoward)) (TYPE x, long double y)
586 ++count;
587 P();
588 return x;
591 TYPE
592 (F(remainder)) (TYPE x, TYPE y)
594 ++count;
595 P();
596 return x + y;
599 TYPE
600 (F(scalb)) (TYPE x, TYPE y)
602 ++count;
603 P();
604 return x + y;
607 TYPE
608 (F(scalbn)) (TYPE x, int y)
610 ++count;
611 P();
612 return x;
615 TYPE
616 (F(scalbln)) (TYPE x, long int y)
618 ++count;
619 P();
620 return x;
624 (F(ilogb)) (TYPE x)
626 ++count;
627 P();
628 return x;
631 TYPE
632 (F(fdim)) (TYPE x, TYPE y)
634 ++count;
635 P();
636 return x + y;
639 TYPE
640 (F(fmin)) (TYPE x, TYPE y)
642 ++count;
643 P();
644 return x + y;
647 TYPE
648 (F(fmax)) (TYPE x, TYPE y)
650 ++count;
651 P();
652 return x + y;
655 TYPE
656 (F(fma)) (TYPE x, TYPE y, TYPE z)
658 ++count;
659 P();
660 return x + y + z;
663 #undef F
664 #undef TYPE
665 #undef count
666 #endif