]> git.ipfire.org Git - thirdparty/glibc.git/blob - math/test-tgmath.c
00407382443bf3f094ef0842b31716fa1e1a84fa
[thirdparty/glibc.git] / math / test-tgmath.c
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.
6
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.
11
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.
16
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. */
21
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>
28
29 #define DEBUG
30
31 static void compile_test (void);
32 static void compile_testf (void);
33 static void compile_testl (void);
34
35 float fx;
36 double dx;
37 long double lx;
38
39 int count_double;
40 int count_float;
41 int count_ldouble;
42
43 #define NCALLS 115
44
45 int
46 main (void)
47 {
48 int result = 0;
49
50 count_float = count_double = count_ldouble = 0;
51 compile_test ();
52 if (count_float != 0)
53 {
54 puts ("float function called for double test");
55 result = 1;
56 }
57 if (count_ldouble != 0)
58 {
59 puts ("long double function called for double test");
60 result = 1;
61 }
62 if (count_double < NCALLS)
63 {
64 printf ("double functions not called often enough (%d)\n",
65 count_double);
66 result = 1;
67 }
68 else if (count_double > NCALLS)
69 {
70 printf ("double functions called too often (%d)\n",
71 count_double);
72 result = 1;
73 }
74
75 count_float = count_double = count_ldouble = 0;
76 compile_testf ();
77 if (count_double != 0)
78 {
79 puts ("double function called for float test");
80 result = 1;
81 }
82 if (count_ldouble != 0)
83 {
84 puts ("long double function called for float test");
85 result = 1;
86 }
87 if (count_float < NCALLS)
88 {
89 printf ("float functions not called often enough (%d)\n", count_float);
90 result = 1;
91 }
92 else if (count_float > NCALLS)
93 {
94 printf ("float functions called too often (%d)\n",
95 count_double);
96 result = 1;
97 }
98
99 #ifndef NO_LONG_DOUBLE
100 count_float = count_double = count_ldouble = 0;
101 compile_testl ();
102 if (count_float != 0)
103 {
104 puts ("float function called for long double test");
105 result = 1;
106 }
107 if (count_double != 0)
108 {
109 puts ("double function called for long double test");
110 result = 1;
111 }
112 if (count_ldouble < NCALLS)
113 {
114 printf ("long double functions not called often enough (%d)\n",
115 count_ldouble);
116 result = 1;
117 }
118 else if (count_ldouble > NCALLS)
119 {
120 printf ("long double functions called too often (%d)\n",
121 count_double);
122 result = 1;
123 }
124 #endif
125
126 return result;
127 }
128
129 /* Now generate the three functions. */
130 #define HAVE_MAIN
131
132 #define F(name) name
133 #define TYPE double
134 #define x dx
135 #define count count_double
136 #include "test-tgmath.c"
137
138 #define F(name) name##f
139 #define TYPE float
140 #define x fx
141 #define count count_float
142 #include "test-tgmath.c"
143
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
151
152 #else
153
154 #ifdef DEBUG
155 #define P() puts (__FUNCTION__)
156 #else
157 #define P()
158 #endif
159
160 static void
161 F(compile_test) (void)
162 {
163 TYPE a, b, c;
164 int i;
165 long int j;
166 long long int k;
167
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));
220 }
221 #undef x
222
223
224 TYPE
225 (F(cos)) (TYPE x)
226 {
227 ++count;
228 return x;
229 }
230
231 TYPE
232 (F(acos)) (TYPE x)
233 {
234 ++count;
235 P();
236 return x;
237 }
238
239 TYPE
240 (F(sin)) (TYPE x)
241 {
242 ++count;
243 P();
244 return x;
245 }
246
247 TYPE
248 (F(asin)) (TYPE x)
249 {
250 ++count;
251 P();
252 return x;
253 }
254
255 TYPE
256 (F(tan)) (TYPE x)
257 {
258 ++count;
259 P();
260 return x;
261 }
262
263 TYPE
264 (F(atan)) (TYPE x)
265 {
266 ++count;
267 P();
268 return x;
269 }
270
271 TYPE
272 (F(atan2)) (TYPE x, TYPE y)
273 {
274 ++count;
275 P();
276 return x + y;
277 }
278
279 TYPE
280 (F(cosh)) (TYPE x)
281 {
282 ++count;
283 P();
284 return x;
285 }
286
287 TYPE
288 (F(acosh)) (TYPE x)
289 {
290 ++count;
291 P();
292 return x;
293 }
294
295 TYPE
296 (F(sinh)) (TYPE x)
297 {
298 ++count;
299 P();
300 return x;
301 }
302
303 TYPE
304 (F(asinh)) (TYPE x)
305 {
306 ++count;
307 P();
308 return x;
309 }
310
311 TYPE
312 (F(tanh)) (TYPE x)
313 {
314 ++count;
315 P();
316 return x;
317 }
318
319 TYPE
320 (F(atanh)) (TYPE x)
321 {
322 ++count;
323 P();
324 return x;
325 }
326
327 TYPE
328 (F(exp)) (TYPE x)
329 {
330 ++count;
331 P();
332 return x;
333 }
334
335 TYPE
336 (F(log)) (TYPE x)
337 {
338 ++count;
339 P();
340 return x;
341 }
342
343 TYPE
344 (F(log10)) (TYPE x)
345 {
346 ++count;
347 P();
348 return x;
349 }
350
351 TYPE
352 (F(ldexp)) (TYPE x, int y)
353 {
354 ++count;
355 P();
356 return x;
357 }
358
359 TYPE
360 (F(frexp)) (TYPE x, int *y)
361 {
362 ++count;
363 P();
364 return x;
365 }
366
367 TYPE
368 (F(expm1)) (TYPE x)
369 {
370 ++count;
371 P();
372 return x;
373 }
374
375 TYPE
376 (F(log1p)) (TYPE x)
377 {
378 ++count;
379 P();
380 return x;
381 }
382
383 TYPE
384 (F(logb)) (TYPE x)
385 {
386 ++count;
387 P();
388 return x;
389 }
390
391 TYPE
392 (F(exp2)) (TYPE x)
393 {
394 ++count;
395 P();
396 return x;
397 }
398
399 TYPE
400 (F(log2)) (TYPE x)
401 {
402 ++count;
403 P();
404 return x;
405 }
406
407 TYPE
408 (F(pow)) (TYPE x, TYPE y)
409 {
410 ++count;
411 P();
412 return x + y;
413 }
414
415 TYPE
416 (F(sqrt)) (TYPE x)
417 {
418 ++count;
419 P();
420 return x;
421 }
422
423 TYPE
424 (F(hypot)) (TYPE x, TYPE y)
425 {
426 ++count;
427 P();
428 return x + y;
429 }
430
431 TYPE
432 (F(cbrt)) (TYPE x)
433 {
434 ++count;
435 P();
436 return x;
437 }
438
439 TYPE
440 (F(ceil)) (TYPE x)
441 {
442 ++count;
443 P();
444 return x;
445 }
446
447 TYPE
448 (F(fabs)) (TYPE x)
449 {
450 ++count;
451 P();
452 return x;
453 }
454
455 TYPE
456 (F(floor)) (TYPE x)
457 {
458 ++count;
459 P();
460 return x;
461 }
462
463 TYPE
464 (F(fmod)) (TYPE x, TYPE y)
465 {
466 ++count;
467 P();
468 return x + y;
469 }
470
471 TYPE
472 (F(nearbyint)) (TYPE x)
473 {
474 ++count;
475 P();
476 return x;
477 }
478
479 TYPE
480 (F(round)) (TYPE x)
481 {
482 ++count;
483 P();
484 return x;
485 }
486
487 TYPE
488 (F(trunc)) (TYPE x)
489 {
490 ++count;
491 P();
492 return x;
493 }
494
495 TYPE
496 (F(remquo)) (TYPE x, TYPE y, int *i)
497 {
498 ++count;
499 P();
500 return x + y;
501 }
502
503 long int
504 (F(lrint)) (TYPE x)
505 {
506 ++count;
507 P();
508 return x;
509 }
510
511 long int
512 (F(lround)) (TYPE x)
513 {
514 ++count;
515 P();
516 return x;
517 }
518
519 long long int
520 (F(llrint)) (TYPE x)
521 {
522 ++count;
523 P();
524 return x;
525 }
526
527 long long int
528 (F(llround)) (TYPE x)
529 {
530 ++count;
531 P();
532 return x;
533 }
534
535 TYPE
536 (F(erf)) (TYPE x)
537 {
538 ++count;
539 P();
540 return x;
541 }
542
543 TYPE
544 (F(erfc)) (TYPE x)
545 {
546 ++count;
547 P();
548 return x;
549 }
550
551 TYPE
552 (F(tgamma)) (TYPE x)
553 {
554 ++count;
555 P();
556 return x;
557 }
558
559 TYPE
560 (F(lgamma)) (TYPE x)
561 {
562 ++count;
563 P();
564 return x;
565 }
566
567 TYPE
568 (F(rint)) (TYPE x)
569 {
570 ++count;
571 P();
572 return x;
573 }
574
575 TYPE
576 (F(nextafter)) (TYPE x, TYPE y)
577 {
578 ++count;
579 P();
580 return x + y;
581 }
582
583 TYPE
584 (F(nexttoward)) (TYPE x, long double y)
585 {
586 ++count;
587 P();
588 return x;
589 }
590
591 TYPE
592 (F(remainder)) (TYPE x, TYPE y)
593 {
594 ++count;
595 P();
596 return x + y;
597 }
598
599 TYPE
600 (F(scalb)) (TYPE x, TYPE y)
601 {
602 ++count;
603 P();
604 return x + y;
605 }
606
607 TYPE
608 (F(scalbn)) (TYPE x, int y)
609 {
610 ++count;
611 P();
612 return x;
613 }
614
615 TYPE
616 (F(scalbln)) (TYPE x, long int y)
617 {
618 ++count;
619 P();
620 return x;
621 }
622
623 int
624 (F(ilogb)) (TYPE x)
625 {
626 ++count;
627 P();
628 return x;
629 }
630
631 TYPE
632 (F(fdim)) (TYPE x, TYPE y)
633 {
634 ++count;
635 P();
636 return x + y;
637 }
638
639 TYPE
640 (F(fmin)) (TYPE x, TYPE y)
641 {
642 ++count;
643 P();
644 return x + y;
645 }
646
647 TYPE
648 (F(fmax)) (TYPE x, TYPE y)
649 {
650 ++count;
651 P();
652 return x + y;
653 }
654
655 TYPE
656 (F(fma)) (TYPE x, TYPE y, TYPE z)
657 {
658 ++count;
659 P();
660 return x + y + z;
661 }
662
663 #undef F
664 #undef TYPE
665 #undef count
666 #endif