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