Refactor sigcontextinfo.h
[glibc.git] / math / libm-test-driver.c
blobd9b9b383ad67914534eb6d881904ea2e06d07925
1 /* Support code for testing libm functions (driver).
2 Copyright (C) 1997-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include "libm-test-support.h"
21 #include <math-tests-arch.h>
23 /* Flags set by the including file. */
24 const int flag_test_errno = TEST_ERRNO;
25 const int flag_test_exceptions = TEST_EXCEPTIONS;
26 const int flag_test_finite = TEST_FINITE;
27 const int flag_test_inline = TEST_INLINE;
28 const int flag_test_mathvec = TEST_MATHVEC;
30 #if TEST_NARROW
31 const int snan_tests_arg = SNAN_TESTS (ARG_FLOAT);
32 #else
33 const int snan_tests_arg = SNAN_TESTS (FLOAT);
34 #endif
36 #define STRX(x) #x
37 #define STR(x) STRX (x)
38 #define STR_FLOAT STR (FLOAT)
39 #define STR_ARG_FLOAT STR (ARG_FLOAT)
40 #define STR_VEC_LEN STR (VEC_LEN)
42 /* Informal description of the functions being tested. */
43 #if TEST_MATHVEC
44 # define TEST_MSG "testing " STR_FLOAT " (vector length " STR_VEC_LEN ")\n"
45 #elif TEST_INLINE
46 # define TEST_MSG "testing " STR_FLOAT " (inline functions)\n"
47 #elif TEST_FINITE
48 # define TEST_MSG "testing " STR_FLOAT " (finite-math-only)\n"
49 #elif TEST_NARROW
50 # define TEST_MSG "testing " STR_FLOAT " (argument " STR_ARG_FLOAT ")\n"
51 #else
52 # define TEST_MSG "testing " STR_FLOAT " (without inline functions)\n"
53 #endif
54 const char test_msg[] = TEST_MSG;
56 /* Allow platforms without all rounding modes to test properly,
57 assuming they provide an __FE_UNDEFINED in <bits/fenv.h> which
58 causes fesetround() to return failure. */
59 #ifndef FE_TONEAREST
60 # define FE_TONEAREST __FE_UNDEFINED
61 #endif
62 #ifndef FE_TOWARDZERO
63 # define FE_TOWARDZERO __FE_UNDEFINED
64 #endif
65 #ifndef FE_UPWARD
66 # define FE_UPWARD __FE_UNDEFINED
67 #endif
68 #ifndef FE_DOWNWARD
69 # define FE_DOWNWARD __FE_UNDEFINED
70 #endif
72 #define TEST_NAN_PAYLOAD_CANONICALIZE (SNAN_TESTS_PRESERVE_PAYLOAD \
73 ? TEST_NAN_PAYLOAD \
74 : 0)
76 #if TEST_INLINE
77 const char qtype_str[] = "i" TYPE_STR;
78 #else
79 const char qtype_str[] = TYPE_STR;
80 #endif
82 /* Various constants derived from pi. We must supply them precalculated for
83 accuracy. They are written as a series of postfix operations to keep
84 them concise yet somewhat readable. */
86 /* (pi * 3) / 4 */
87 #define lit_pi_3_m_4_d LIT (2.356194490192344928846982537459627163)
88 /* pi * 3 / (4 * ln(10)) */
89 #define lit_pi_3_m_4_ln10_m_d LIT (1.023282265381381010614337719073516828)
90 /* pi / (2 * ln(10)) */
91 #define lit_pi_2_ln10_m_d LIT (0.682188176920920673742891812715677885)
92 /* pi / (4 * ln(10)) */
93 #define lit_pi_4_ln10_m_d LIT (0.341094088460460336871445906357838943)
94 /* pi / ln(10) */
95 #define lit_pi_ln10_d LIT (1.364376353841841347485783625431355770)
96 /* pi / 2 */
97 #define lit_pi_2_d LITM (M_PI_2)
98 /* pi / 4 */
99 #define lit_pi_4_d LITM (M_PI_4)
100 /* pi */
101 #define lit_pi LITM (M_PI)
103 /* Other useful constants. */
105 /* e */
106 #define lit_e LITM (M_E)
108 #define plus_zero LIT (0.0)
109 #define minus_zero LIT (-0.0)
110 #define plus_infty FUNC (__builtin_inf) ()
111 #define minus_infty -(FUNC (__builtin_inf) ())
112 #define qnan_value_pl(S) FUNC (__builtin_nan) (S)
113 #define qnan_value qnan_value_pl ("")
114 #define snan_value_pl(S) FUNC (__builtin_nans) (S)
115 #define snan_value snan_value_pl ("")
116 #define max_value TYPE_MAX
117 #define min_value TYPE_MIN
118 #define min_subnorm_value TYPE_TRUE_MIN
120 #define arg_plus_zero ARG_LIT (0.0)
121 #define arg_minus_zero ARG_LIT (-0.0)
122 #define arg_plus_infty ARG_FUNC (__builtin_inf) ()
123 #define arg_minus_infty -(ARG_FUNC (__builtin_inf) ())
124 #define arg_qnan_value_pl(S) ARG_FUNC (__builtin_nan) (S)
125 #define arg_qnan_value arg_qnan_value_pl ("")
126 #define arg_snan_value_pl(S) ARG_FUNC (__builtin_nans) (S)
127 #define arg_snan_value arg_snan_value_pl ("")
128 #define arg_max_value ARG_TYPE_MAX
129 #define arg_min_value ARG_TYPE_MIN
130 #define arg_min_subnorm_value ARG_TYPE_TRUE_MIN
132 /* For nexttoward tests. */
133 #define snan_value_ld __builtin_nansl ("")
135 /* Structures for each kind of test. */
136 /* Used for both RUN_TEST_LOOP_f_f and RUN_TEST_LOOP_fp_f. */
137 struct test_f_f_data
139 const char *arg_str;
140 FLOAT arg;
141 struct
143 FLOAT expected;
144 int exceptions;
145 } rd, rn, rz, ru;
147 struct test_ff_f_data
149 const char *arg_str;
150 FLOAT arg1, arg2;
151 struct
153 FLOAT expected;
154 int exceptions;
155 } rd, rn, rz, ru;
157 /* Strictly speaking, a j type argument is one gen-libm-test.py will not
158 attempt to muck with. For now, it is only used to prevent it from
159 mucking up an explicitly long double argument. */
160 struct test_fj_f_data
162 const char *arg_str;
163 FLOAT arg1;
164 long double arg2;
165 struct
167 FLOAT expected;
168 int exceptions;
169 } rd, rn, rz, ru;
171 #ifdef ARG_FLOAT
172 struct test_aa_f_data
174 const char *arg_str;
175 ARG_FLOAT arg1, arg2;
176 struct
178 FLOAT expected;
179 int exceptions;
180 } rd, rn, rz, ru;
182 #endif
183 struct test_fi_f_data
185 const char *arg_str;
186 FLOAT arg1;
187 int arg2;
188 struct
190 FLOAT expected;
191 int exceptions;
192 } rd, rn, rz, ru;
194 struct test_fl_f_data
196 const char *arg_str;
197 FLOAT arg1;
198 long int arg2;
199 struct
201 FLOAT expected;
202 int exceptions;
203 } rd, rn, rz, ru;
205 struct test_if_f_data
207 const char *arg_str;
208 int arg1;
209 FLOAT arg2;
210 struct
212 FLOAT expected;
213 int exceptions;
214 } rd, rn, rz, ru;
216 struct test_fff_f_data
218 const char *arg_str;
219 FLOAT arg1, arg2, arg3;
220 struct
222 FLOAT expected;
223 int exceptions;
224 } rd, rn, rz, ru;
226 struct test_fiu_M_data
228 const char *arg_str;
229 FLOAT arg1;
230 int arg2;
231 unsigned int arg3;
232 struct
234 intmax_t expected;
235 int exceptions;
236 } rd, rn, rz, ru;
238 struct test_fiu_U_data
240 const char *arg_str;
241 FLOAT arg1;
242 int arg2;
243 unsigned int arg3;
244 struct
246 uintmax_t expected;
247 int exceptions;
248 } rd, rn, rz, ru;
250 struct test_c_f_data
252 const char *arg_str;
253 FLOAT argr, argc;
254 struct
256 FLOAT expected;
257 int exceptions;
258 } rd, rn, rz, ru;
260 /* Used for both RUN_TEST_LOOP_f_f1 and RUN_TEST_LOOP_fI_f1. */
261 struct test_f_f1_data
263 const char *arg_str;
264 FLOAT arg;
265 struct
267 FLOAT expected;
268 int exceptions;
269 int extra_test;
270 int extra_expected;
271 } rd, rn, rz, ru;
273 struct test_fF_f1_data
275 const char *arg_str;
276 FLOAT arg;
277 struct
279 FLOAT expected;
280 int exceptions;
281 int extra_test;
282 FLOAT extra_expected;
283 } rd, rn, rz, ru;
285 struct test_ffI_f1_data
287 const char *arg_str;
288 FLOAT arg1, arg2;
289 struct
291 FLOAT expected;
292 int exceptions;
293 int extra_test;
294 int extra_expected;
295 } rd, rn, rz, ru;
297 struct test_c_c_data
299 const char *arg_str;
300 FLOAT argr, argc;
301 struct
303 FLOAT expr, expc;
304 int exceptions;
305 } rd, rn, rz, ru;
307 struct test_cc_c_data
309 const char *arg_str;
310 FLOAT arg1r, arg1c, arg2r, arg2c;
311 struct
313 FLOAT expr, expc;
314 int exceptions;
315 } rd, rn, rz, ru;
317 /* Used for all of RUN_TEST_LOOP_f_i, RUN_TEST_LOOP_f_i_tg,
318 RUN_TEST_LOOP_f_b and RUN_TEST_LOOP_f_b_tg. */
319 struct test_f_i_data
321 const char *arg_str;
322 FLOAT arg;
323 struct
325 int expected;
326 int exceptions;
327 } rd, rn, rz, ru;
329 /* Used for RUN_TEST_LOOP_ff_b, RUN_TEST_LOOP_fpfp_b and
330 RUN_TEST_LOOP_ff_i_tg. */
331 struct test_ff_i_data
333 const char *arg_str;
334 FLOAT arg1, arg2;
335 struct
337 int expected;
338 int exceptions;
339 } rd, rn, rz, ru;
341 struct test_f_l_data
343 const char *arg_str;
344 FLOAT arg;
345 struct
347 long int expected;
348 int exceptions;
349 } rd, rn, rz, ru;
351 struct test_f_L_data
353 const char *arg_str;
354 FLOAT arg;
355 struct
357 long long int expected;
358 int exceptions;
359 } rd, rn, rz, ru;
361 struct test_fFF_11_data
363 const char *arg_str;
364 FLOAT arg;
365 struct
367 int exceptions;
368 int extra1_test;
369 FLOAT extra1_expected;
370 int extra2_test;
371 FLOAT extra2_expected;
372 } rd, rn, rz, ru;
374 /* Used for both RUN_TEST_LOOP_Ff_b1 and RUN_TEST_LOOP_Ffp_b1. */
375 struct test_Ff_b1_data
377 const char *arg_str;
378 FLOAT arg;
379 struct
381 int expected;
382 int exceptions;
383 int extra_test;
384 FLOAT extra_expected;
385 } rd, rn, rz, ru;
388 /* Set the rounding mode, or restore the saved value. */
389 #define IF_ROUND_INIT_ /* Empty. */
390 #define IF_ROUND_INIT_FE_DOWNWARD \
391 int save_round_mode = fegetround (); \
392 if (ROUNDING_TESTS (FLOAT, FE_DOWNWARD) \
393 && !TEST_MATHVEC \
394 && fesetround (FE_DOWNWARD) == 0)
395 #define IF_ROUND_INIT_FE_TONEAREST \
396 int save_round_mode = fegetround (); \
397 if (ROUNDING_TESTS (FLOAT, FE_TONEAREST) \
398 && fesetround (FE_TONEAREST) == 0)
399 #define IF_ROUND_INIT_FE_TOWARDZERO \
400 int save_round_mode = fegetround (); \
401 if (ROUNDING_TESTS (FLOAT, FE_TOWARDZERO) \
402 && !TEST_MATHVEC \
403 && fesetround (FE_TOWARDZERO) == 0)
404 #define IF_ROUND_INIT_FE_UPWARD \
405 int save_round_mode = fegetround (); \
406 if (ROUNDING_TESTS (FLOAT, FE_UPWARD) \
407 && !TEST_MATHVEC \
408 && fesetround (FE_UPWARD) == 0)
409 #define ROUND_RESTORE_ /* Empty. */
410 #define ROUND_RESTORE_FE_DOWNWARD \
411 fesetround (save_round_mode)
412 #define ROUND_RESTORE_FE_TONEAREST \
413 fesetround (save_round_mode)
414 #define ROUND_RESTORE_FE_TOWARDZERO \
415 fesetround (save_round_mode)
416 #define ROUND_RESTORE_FE_UPWARD \
417 fesetround (save_round_mode)
419 /* Field name to use for a given rounding mode. */
420 #define RM_ rn
421 #define RM_FE_DOWNWARD rd
422 #define RM_FE_TONEAREST rn
423 #define RM_FE_TOWARDZERO rz
424 #define RM_FE_UPWARD ru
426 /* Common setup for an individual test. */
427 #define COMMON_TEST_SETUP(ARG_STR) \
428 char *test_name; \
429 if (asprintf (&test_name, "%s (%s)", this_func, (ARG_STR)) == -1) \
430 abort ()
432 /* Setup for a test with an extra output. */
433 #define EXTRA_OUTPUT_TEST_SETUP(ARG_STR, N) \
434 char *extra##N##_name; \
435 if (asprintf (&extra##N##_name, "%s (%s) extra output " #N, \
436 this_func, (ARG_STR)) == -1) \
437 abort ()
439 /* Common cleanup after an individual test. */
440 #define COMMON_TEST_CLEANUP \
441 free (test_name)
443 /* Cleanup for a test with an extra output. */
444 #define EXTRA_OUTPUT_TEST_CLEANUP(N) \
445 free (extra##N##_name)
447 /* Run an individual test, including any required setup and checking
448 of results, or loop over all tests in an array. */
449 #define RUN_TEST_f_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
450 EXCEPTIONS) \
451 do \
452 if (enable_test (EXCEPTIONS)) \
454 COMMON_TEST_SETUP (ARG_STR); \
455 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
456 EXPECTED, EXCEPTIONS); \
457 COMMON_TEST_CLEANUP; \
459 while (0)
460 #define RUN_TEST_LOOP_f_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
461 IF_ROUND_INIT_ ## ROUNDING_MODE \
462 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
463 RUN_TEST_f_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
464 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
465 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
466 ROUND_RESTORE_ ## ROUNDING_MODE
467 #define RUN_TEST_fp_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
468 EXCEPTIONS) \
469 do \
470 if (enable_test (EXCEPTIONS)) \
472 COMMON_TEST_SETUP (ARG_STR); \
473 check_float (test_name, FUNC_TEST (FUNC_NAME) (&(ARG)), \
474 EXPECTED, EXCEPTIONS); \
475 COMMON_TEST_CLEANUP; \
477 while (0)
478 #define RUN_TEST_LOOP_fp_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
479 IF_ROUND_INIT_ ## ROUNDING_MODE \
480 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
481 RUN_TEST_fp_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
482 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
483 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
484 ROUND_RESTORE_ ## ROUNDING_MODE
485 #define RUN_TEST_2_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
486 EXCEPTIONS) \
487 do \
488 if (enable_test (EXCEPTIONS)) \
490 COMMON_TEST_SETUP (ARG_STR); \
491 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
492 EXPECTED, EXCEPTIONS); \
493 COMMON_TEST_CLEANUP; \
495 while (0)
496 #define RUN_TEST_LOOP_2_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
497 IF_ROUND_INIT_ ## ROUNDING_MODE \
498 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
499 RUN_TEST_2_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
500 (ARRAY)[i].arg2, \
501 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
502 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
503 ROUND_RESTORE_ ## ROUNDING_MODE
504 #define RUN_TEST_ff_f RUN_TEST_2_f
505 #define RUN_TEST_LOOP_ff_f RUN_TEST_LOOP_2_f
506 #define RUN_TEST_LOOP_fj_f RUN_TEST_LOOP_2_f
507 #define RUN_TEST_LOOP_aa_f RUN_TEST_LOOP_2_f
508 #define RUN_TEST_fi_f RUN_TEST_2_f
509 #define RUN_TEST_LOOP_fi_f RUN_TEST_LOOP_2_f
510 #define RUN_TEST_fl_f RUN_TEST_2_f
511 #define RUN_TEST_LOOP_fl_f RUN_TEST_LOOP_2_f
512 #define RUN_TEST_if_f RUN_TEST_2_f
513 #define RUN_TEST_LOOP_if_f RUN_TEST_LOOP_2_f
514 #define RUN_TEST_fff_f(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
515 EXPECTED, EXCEPTIONS) \
516 do \
517 if (enable_test (EXCEPTIONS)) \
519 COMMON_TEST_SETUP (ARG_STR); \
520 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
521 EXPECTED, EXCEPTIONS); \
522 COMMON_TEST_CLEANUP; \
524 while (0)
525 #define RUN_TEST_LOOP_fff_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
526 IF_ROUND_INIT_ ## ROUNDING_MODE \
527 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
528 RUN_TEST_fff_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
529 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
530 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
531 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
532 ROUND_RESTORE_ ## ROUNDING_MODE
533 #define RUN_TEST_fiu_M(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
534 EXPECTED, EXCEPTIONS) \
535 do \
536 if (enable_test (EXCEPTIONS)) \
538 COMMON_TEST_SETUP (ARG_STR); \
539 check_intmax_t (test_name, \
540 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
541 EXPECTED, EXCEPTIONS); \
542 COMMON_TEST_CLEANUP; \
544 while (0)
545 #define RUN_TEST_LOOP_fiu_M(FUNC_NAME, ARRAY, ROUNDING_MODE) \
546 IF_ROUND_INIT_ ## ROUNDING_MODE \
547 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
548 RUN_TEST_fiu_M ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
549 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
550 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
551 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
552 ROUND_RESTORE_ ## ROUNDING_MODE
553 #define RUN_TEST_fiu_U(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
554 EXPECTED, EXCEPTIONS) \
555 do \
556 if (enable_test (EXCEPTIONS)) \
558 COMMON_TEST_SETUP (ARG_STR); \
559 check_uintmax_t (test_name, \
560 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
561 EXPECTED, EXCEPTIONS); \
562 COMMON_TEST_CLEANUP; \
564 while (0)
565 #define RUN_TEST_LOOP_fiu_U(FUNC_NAME, ARRAY, ROUNDING_MODE) \
566 IF_ROUND_INIT_ ## ROUNDING_MODE \
567 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
568 RUN_TEST_fiu_U ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
569 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
570 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
571 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
572 ROUND_RESTORE_ ## ROUNDING_MODE
573 #define RUN_TEST_c_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
574 EXCEPTIONS) \
575 do \
576 if (enable_test (EXCEPTIONS)) \
578 COMMON_TEST_SETUP (ARG_STR); \
579 check_float (test_name, \
580 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1, ARG2)),\
581 EXPECTED, EXCEPTIONS); \
582 COMMON_TEST_CLEANUP; \
584 while (0)
585 #define RUN_TEST_LOOP_c_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
586 IF_ROUND_INIT_ ## ROUNDING_MODE \
587 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
588 RUN_TEST_c_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
589 (ARRAY)[i].argc, \
590 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
591 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
592 ROUND_RESTORE_ ## ROUNDING_MODE
593 #define RUN_TEST_f_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
594 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
595 EXTRA_EXPECTED) \
596 do \
597 if (enable_test (EXCEPTIONS)) \
599 COMMON_TEST_SETUP (ARG_STR); \
600 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
601 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
602 EXCEPTIONS); \
603 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
604 if (EXTRA_TEST) \
605 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
606 EXTRA_OUTPUT_TEST_CLEANUP (1); \
607 COMMON_TEST_CLEANUP; \
609 while (0)
610 #define RUN_TEST_LOOP_f_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
611 IF_ROUND_INIT_ ## ROUNDING_MODE \
612 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
613 RUN_TEST_f_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
614 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
615 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
616 EXTRA_VAR, \
617 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
618 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
619 ROUND_RESTORE_ ## ROUNDING_MODE
620 #define RUN_TEST_fF_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
621 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
622 EXTRA_EXPECTED) \
623 do \
624 if (enable_test (EXCEPTIONS)) \
626 COMMON_TEST_SETUP (ARG_STR); \
627 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
628 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
629 EXPECTED, EXCEPTIONS); \
630 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
631 if (EXTRA_TEST) \
632 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
633 EXTRA_OUTPUT_TEST_CLEANUP (1); \
634 COMMON_TEST_CLEANUP; \
636 while (0)
637 #define RUN_TEST_LOOP_fF_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
638 IF_ROUND_INIT_ ## ROUNDING_MODE \
639 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
640 RUN_TEST_fF_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
641 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
642 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
643 EXTRA_VAR, \
644 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
645 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
646 ROUND_RESTORE_ ## ROUNDING_MODE
647 #define RUN_TEST_fI_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
648 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
649 EXTRA_EXPECTED) \
650 do \
651 if (enable_test (EXCEPTIONS)) \
653 COMMON_TEST_SETUP (ARG_STR); \
654 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
655 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
656 EXPECTED, EXCEPTIONS); \
657 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
658 if (EXTRA_TEST) \
659 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
660 EXTRA_OUTPUT_TEST_CLEANUP (1); \
661 COMMON_TEST_CLEANUP; \
663 while (0)
664 #define RUN_TEST_LOOP_fI_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
665 IF_ROUND_INIT_ ## ROUNDING_MODE \
666 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
667 RUN_TEST_fI_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
668 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
669 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
670 EXTRA_VAR, \
671 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
672 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
673 ROUND_RESTORE_ ## ROUNDING_MODE
674 #define RUN_TEST_ffI_f1_mod8(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
675 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
676 EXTRA_EXPECTED) \
677 do \
678 if (enable_test (EXCEPTIONS)) \
680 COMMON_TEST_SETUP (ARG_STR); \
681 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
682 check_float (test_name, \
683 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, &(EXTRA_VAR)), \
684 EXPECTED, EXCEPTIONS); \
685 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
686 if (EXTRA_TEST) \
687 check_int (extra1_name, (EXTRA_VAR) % 8, EXTRA_EXPECTED, 0); \
688 EXTRA_OUTPUT_TEST_CLEANUP (1); \
689 COMMON_TEST_CLEANUP; \
691 while (0)
692 #define RUN_TEST_LOOP_ffI_f1_mod8(FUNC_NAME, ARRAY, ROUNDING_MODE, \
693 EXTRA_VAR) \
694 IF_ROUND_INIT_ ## ROUNDING_MODE \
695 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
696 RUN_TEST_ffI_f1_mod8 ((ARRAY)[i].arg_str, FUNC_NAME, \
697 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
698 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
699 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
700 EXTRA_VAR, \
701 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
702 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
703 ROUND_RESTORE_ ## ROUNDING_MODE
704 #define RUN_TEST_Ff_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
705 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
706 EXTRA_EXPECTED) \
707 do \
708 if (enable_test (EXCEPTIONS)) \
710 COMMON_TEST_SETUP (ARG_STR); \
711 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
712 /* Clear any exceptions from comparison involving sNaN \
713 EXTRA_EXPECTED. */ \
714 feclearexcept (FE_ALL_EXCEPT); \
715 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
716 (ARG)), \
717 EXPECTED, EXCEPTIONS); \
718 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
719 if (EXTRA_TEST) \
720 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
721 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
722 EXTRA_OUTPUT_TEST_CLEANUP (1); \
723 COMMON_TEST_CLEANUP; \
725 while (0)
726 #define RUN_TEST_LOOP_Ff_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
727 EXTRA_VAR) \
728 IF_ROUND_INIT_ ## ROUNDING_MODE \
729 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
730 RUN_TEST_Ff_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
731 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
732 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
733 EXTRA_VAR, \
734 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
735 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
736 ROUND_RESTORE_ ## ROUNDING_MODE
737 #define RUN_TEST_Ffp_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
738 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
739 EXTRA_EXPECTED) \
740 do \
741 if (enable_test (EXCEPTIONS)) \
743 COMMON_TEST_SETUP (ARG_STR); \
744 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
745 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
746 &(ARG)), \
747 EXPECTED, EXCEPTIONS); \
748 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
749 if (EXTRA_TEST) \
750 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
751 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
752 EXTRA_OUTPUT_TEST_CLEANUP (1); \
753 COMMON_TEST_CLEANUP; \
755 while (0)
756 #define RUN_TEST_LOOP_Ffp_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
757 EXTRA_VAR) \
758 IF_ROUND_INIT_ ## ROUNDING_MODE \
759 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
760 RUN_TEST_Ffp_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
761 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
762 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
763 EXTRA_VAR, \
764 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
765 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
766 ROUND_RESTORE_ ## ROUNDING_MODE
767 #define RUN_TEST_c_c(ARG_STR, FUNC_NAME, ARGR, ARGC, EXPR, EXPC, \
768 EXCEPTIONS) \
769 do \
770 if (enable_test (EXCEPTIONS)) \
772 COMMON_TEST_SETUP (ARG_STR); \
773 check_complex (test_name, \
774 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARGR, ARGC)), \
775 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
776 COMMON_TEST_CLEANUP; \
778 while (0)
779 #define RUN_TEST_LOOP_c_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
780 IF_ROUND_INIT_ ## ROUNDING_MODE \
781 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
782 RUN_TEST_c_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
783 (ARRAY)[i].argc, \
784 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
785 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
786 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
787 ROUND_RESTORE_ ## ROUNDING_MODE
788 #define RUN_TEST_cc_c(ARG_STR, FUNC_NAME, ARG1R, ARG1C, ARG2R, ARG2C, \
789 EXPR, EXPC, EXCEPTIONS) \
790 do \
791 if (enable_test (EXCEPTIONS)) \
793 COMMON_TEST_SETUP (ARG_STR); \
794 check_complex (test_name, \
795 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1R, ARG1C), \
796 BUILD_COMPLEX (ARG2R, ARG2C)), \
797 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
798 COMMON_TEST_CLEANUP; \
800 while (0)
801 #define RUN_TEST_LOOP_cc_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
802 IF_ROUND_INIT_ ## ROUNDING_MODE \
803 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
804 RUN_TEST_cc_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1r, \
805 (ARRAY)[i].arg1c, (ARRAY)[i].arg2r, \
806 (ARRAY)[i].arg2c, \
807 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
808 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
809 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
810 ROUND_RESTORE_ ## ROUNDING_MODE
811 #define RUN_TEST_f_i(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
812 do \
813 if (enable_test (EXCEPTIONS)) \
815 COMMON_TEST_SETUP (ARG_STR); \
816 check_int (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
817 EXCEPTIONS); \
818 COMMON_TEST_CLEANUP; \
820 while (0)
821 #define RUN_TEST_LOOP_f_i(FUNC_NAME, ARRAY, ROUNDING_MODE) \
822 IF_ROUND_INIT_ ## ROUNDING_MODE \
823 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
824 RUN_TEST_f_i ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
825 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
826 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
827 ROUND_RESTORE_ ## ROUNDING_MODE
828 #define RUN_TEST_f_i_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
829 EXCEPTIONS) \
830 do \
831 if (enable_test (EXCEPTIONS)) \
833 COMMON_TEST_SETUP (ARG_STR); \
834 check_int (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
835 COMMON_TEST_CLEANUP; \
837 while (0)
838 #define RUN_TEST_LOOP_f_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
839 IF_ROUND_INIT_ ## ROUNDING_MODE \
840 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
841 RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
842 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
843 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
844 ROUND_RESTORE_ ## ROUNDING_MODE
845 #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
846 EXCEPTIONS) \
847 do \
848 if (enable_test (EXCEPTIONS)) \
850 COMMON_TEST_SETUP (ARG_STR); \
851 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
852 EXPECTED, EXCEPTIONS); \
853 COMMON_TEST_CLEANUP; \
855 while (0)
856 #define RUN_TEST_LOOP_ff_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
857 IF_ROUND_INIT_ ## ROUNDING_MODE \
858 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
859 RUN_TEST_ff_b ((ARRAY)[i].arg_str, FUNC_NAME, \
860 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
861 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
862 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
863 ROUND_RESTORE_ ## ROUNDING_MODE
864 #define RUN_TEST_fpfp_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
865 EXCEPTIONS) \
866 do \
867 if (enable_test (EXCEPTIONS)) \
869 COMMON_TEST_SETUP (ARG_STR); \
870 check_bool (test_name, \
871 FUNC_TEST (FUNC_NAME) (&(ARG1), &(ARG2)), \
872 EXPECTED, EXCEPTIONS); \
873 COMMON_TEST_CLEANUP; \
875 while (0)
876 #define RUN_TEST_LOOP_fpfp_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
877 IF_ROUND_INIT_ ## ROUNDING_MODE \
878 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
879 RUN_TEST_fpfp_b ((ARRAY)[i].arg_str, FUNC_NAME, \
880 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
881 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
882 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
883 ROUND_RESTORE_ ## ROUNDING_MODE
884 #define RUN_TEST_ff_i_tg(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
885 EXCEPTIONS) \
886 do \
887 if (enable_test (EXCEPTIONS)) \
889 COMMON_TEST_SETUP (ARG_STR); \
890 check_int (test_name, FUNC_NAME (ARG1, ARG2), EXPECTED, \
891 EXCEPTIONS); \
892 COMMON_TEST_CLEANUP; \
894 while (0)
895 #define RUN_TEST_LOOP_ff_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
896 IF_ROUND_INIT_ ## ROUNDING_MODE \
897 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
898 RUN_TEST_ff_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, \
899 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
900 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
901 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
902 ROUND_RESTORE_ ## ROUNDING_MODE
903 #define RUN_TEST_f_b(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
904 do \
905 if (enable_test (EXCEPTIONS)) \
907 COMMON_TEST_SETUP (ARG_STR); \
908 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
909 EXCEPTIONS); \
910 COMMON_TEST_CLEANUP; \
912 while (0)
913 #define RUN_TEST_LOOP_f_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
914 IF_ROUND_INIT_ ## ROUNDING_MODE \
915 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
916 RUN_TEST_f_b ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
917 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
918 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
919 ROUND_RESTORE_ ## ROUNDING_MODE
920 #define RUN_TEST_f_b_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
921 EXCEPTIONS) \
922 do \
923 if (enable_test (EXCEPTIONS)) \
925 COMMON_TEST_SETUP (ARG_STR); \
926 check_bool (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
927 COMMON_TEST_CLEANUP; \
929 while (0)
930 #define RUN_TEST_LOOP_f_b_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
931 IF_ROUND_INIT_ ## ROUNDING_MODE \
932 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
933 RUN_TEST_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
934 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
935 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
936 ROUND_RESTORE_ ## ROUNDING_MODE
937 #define RUN_TEST_f_l(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
938 do \
939 if (enable_test (EXCEPTIONS)) \
941 COMMON_TEST_SETUP (ARG_STR); \
942 check_long (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
943 EXCEPTIONS); \
944 COMMON_TEST_CLEANUP; \
946 while (0)
947 #define RUN_TEST_LOOP_f_l(FUNC_NAME, ARRAY, ROUNDING_MODE) \
948 IF_ROUND_INIT_ ## ROUNDING_MODE \
949 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
950 RUN_TEST_f_l ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
951 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
952 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
953 ROUND_RESTORE_ ## ROUNDING_MODE
954 #define RUN_TEST_f_L(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
955 do \
956 if (enable_test (EXCEPTIONS)) \
958 COMMON_TEST_SETUP (ARG_STR); \
959 check_longlong (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
960 EXPECTED, EXCEPTIONS); \
961 COMMON_TEST_CLEANUP; \
963 while (0)
964 #define RUN_TEST_LOOP_f_L(FUNC_NAME, ARRAY, ROUNDING_MODE) \
965 IF_ROUND_INIT_ ## ROUNDING_MODE \
966 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
967 RUN_TEST_f_L ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
968 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
969 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
970 ROUND_RESTORE_ ## ROUNDING_MODE
971 #define RUN_TEST_fFF_11(ARG_STR, FUNC_NAME, ARG, EXCEPTIONS, \
972 EXTRA1_VAR, EXTRA1_TEST, \
973 EXTRA1_EXPECTED, EXTRA2_VAR, \
974 EXTRA2_TEST, EXTRA2_EXPECTED) \
975 do \
976 if (enable_test (EXCEPTIONS)) \
978 COMMON_TEST_SETUP (ARG_STR); \
979 FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA1_VAR), &(EXTRA2_VAR)); \
980 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
981 if (EXTRA1_TEST) \
982 check_float (extra1_name, EXTRA1_VAR, EXTRA1_EXPECTED, \
983 EXCEPTIONS); \
984 EXTRA_OUTPUT_TEST_CLEANUP (1); \
985 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 2); \
986 if (EXTRA2_TEST) \
987 check_float (extra2_name, EXTRA2_VAR, EXTRA2_EXPECTED, 0); \
988 EXTRA_OUTPUT_TEST_CLEANUP (2); \
989 COMMON_TEST_CLEANUP; \
991 while (0)
992 #define RUN_TEST_LOOP_fFF_11(FUNC_NAME, ARRAY, ROUNDING_MODE, \
993 EXTRA1_VAR, EXTRA2_VAR) \
994 IF_ROUND_INIT_ ## ROUNDING_MODE \
995 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
996 RUN_TEST_fFF_11 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
997 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
998 EXTRA1_VAR, \
999 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_test, \
1000 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_expected, \
1001 EXTRA2_VAR, \
1002 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_test, \
1003 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \
1004 ROUND_RESTORE_ ## ROUNDING_MODE
1006 #if TEST_MATHVEC
1007 # define TEST_SUFF VEC_SUFF
1008 # define TEST_SUFF_STR
1009 #elif TEST_NARROW
1010 # define TEST_SUFF
1011 # define TEST_SUFF_STR "_" ARG_TYPE_STR
1012 #else
1013 # define TEST_SUFF
1014 # define TEST_SUFF_STR
1015 #endif
1017 #define STR_CONCAT(a, b, c) __STRING (a##b##c)
1018 #define STR_CON3(a, b, c) STR_CONCAT (a, b, c)
1020 #if TEST_NARROW
1021 # define TEST_COND_any_ibm128 (TEST_COND_ibm128 || TEST_COND_arg_ibm128)
1022 #else
1023 # define TEST_COND_any_ibm128 TEST_COND_ibm128
1024 #endif
1026 /* Start and end the tests for a given function. */
1027 #define START(FUN, SUFF, EXACT) \
1028 CHECK_ARCH_EXT; \
1029 const char *this_func \
1030 = STR_CON3 (FUN, SUFF, TEST_SUFF) TEST_SUFF_STR; \
1031 init_max_error (this_func, EXACT, TEST_COND_any_ibm128)
1032 #define END \
1033 print_max_error (this_func)
1034 #define END_COMPLEX \
1035 print_complex_max_error (this_func)
1037 /* Run tests for a given function in all rounding modes. */
1038 #define ALL_RM_TEST(FUNC, EXACT, ARRAY, LOOP_MACRO, END_MACRO, ...) \
1039 do \
1041 do \
1043 START (FUNC,, EXACT); \
1044 LOOP_MACRO (FUNC, ARRAY, , ## __VA_ARGS__); \
1045 END_MACRO; \
1047 while (0); \
1048 do \
1050 START (FUNC, _downward, EXACT); \
1051 LOOP_MACRO (FUNC, ARRAY, FE_DOWNWARD, ## __VA_ARGS__); \
1052 END_MACRO; \
1054 while (0); \
1055 do \
1057 START (FUNC, _towardzero, EXACT); \
1058 LOOP_MACRO (FUNC, ARRAY, FE_TOWARDZERO, ## __VA_ARGS__); \
1059 END_MACRO; \
1061 while (0); \
1062 do \
1064 START (FUNC, _upward, EXACT); \
1065 LOOP_MACRO (FUNC, ARRAY, FE_UPWARD, ## __VA_ARGS__); \
1066 END_MACRO; \
1068 while (0); \
1070 while (0);
1072 /* Short description of program. */
1073 const char doc[] = "Math test suite: " TEST_MSG ;
1075 static void do_test (void);
1078 main (int argc, char **argv)
1080 libm_test_init (argc, argv);
1081 INIT_ARCH_EXT;
1082 do_test ();
1083 return libm_test_finish ();