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