Add test infrastructure for narrowing libm functions.
[glibc.git] / math / libm-test-driver.c
blob3713e7074f9fc4b934f920f4b29aeee07bb5677a
1 /* Support code for testing libm functions (driver).
2 Copyright (C) 1997-2018 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 #define STRX(x) #x
31 #define STR(x) STRX (x)
32 #define STR_FLOAT STR (FLOAT)
33 #define STR_ARG_FLOAT STR (ARG_FLOAT)
34 #define STR_VEC_LEN STR (VEC_LEN)
36 /* Informal description of the functions being tested. */
37 #if TEST_MATHVEC
38 # define TEST_MSG "testing " STR_FLOAT " (vector length " STR_VEC_LEN ")\n"
39 #elif TEST_INLINE
40 # define TEST_MSG "testing " STR_FLOAT " (inline functions)\n"
41 #elif TEST_FINITE
42 # define TEST_MSG "testing " STR_FLOAT " (finite-math-only)\n"
43 #elif TEST_NARROW
44 # define TEST_MSG "testing " STR_FLOAT " (argument " STR_ARG_FLOAT ")\n"
45 #else
46 # define TEST_MSG "testing " STR_FLOAT " (without inline functions)\n"
47 #endif
48 const char test_msg[] = TEST_MSG;
50 /* Allow platforms without all rounding modes to test properly,
51 assuming they provide an __FE_UNDEFINED in <bits/fenv.h> which
52 causes fesetround() to return failure. */
53 #ifndef FE_TONEAREST
54 # define FE_TONEAREST __FE_UNDEFINED
55 #endif
56 #ifndef FE_TOWARDZERO
57 # define FE_TOWARDZERO __FE_UNDEFINED
58 #endif
59 #ifndef FE_UPWARD
60 # define FE_UPWARD __FE_UNDEFINED
61 #endif
62 #ifndef FE_DOWNWARD
63 # define FE_DOWNWARD __FE_UNDEFINED
64 #endif
66 #define TEST_NAN_PAYLOAD_CANONICALIZE (SNAN_TESTS_PRESERVE_PAYLOAD \
67 ? TEST_NAN_PAYLOAD \
68 : 0)
70 #if TEST_INLINE
71 const char qtype_str[] = "i" TYPE_STR;
72 #else
73 const char qtype_str[] = TYPE_STR;
74 #endif
76 /* Various constants derived from pi. We must supply them precalculated for
77 accuracy. They are written as a series of postfix operations to keep
78 them concise yet somewhat readable. */
80 /* (pi * 3) / 4 */
81 #define lit_pi_3_m_4_d LIT (2.356194490192344928846982537459627163)
82 /* pi * 3 / (4 * ln(10)) */
83 #define lit_pi_3_m_4_ln10_m_d LIT (1.023282265381381010614337719073516828)
84 /* pi / (2 * ln(10)) */
85 #define lit_pi_2_ln10_m_d LIT (0.682188176920920673742891812715677885)
86 /* pi / (4 * ln(10)) */
87 #define lit_pi_4_ln10_m_d LIT (0.341094088460460336871445906357838943)
88 /* pi / ln(10) */
89 #define lit_pi_ln10_d LIT (1.364376353841841347485783625431355770)
90 /* pi / 2 */
91 #define lit_pi_2_d LITM (M_PI_2)
92 /* pi / 4 */
93 #define lit_pi_4_d LITM (M_PI_4)
94 /* pi */
95 #define lit_pi LITM (M_PI)
97 /* Other useful constants. */
99 /* e */
100 #define lit_e LITM (M_E)
102 #define plus_zero LIT (0.0)
103 #define minus_zero LIT (-0.0)
104 #define plus_infty FUNC (__builtin_inf) ()
105 #define minus_infty -(FUNC (__builtin_inf) ())
106 #define qnan_value_pl(S) FUNC (__builtin_nan) (S)
107 #define qnan_value qnan_value_pl ("")
108 #define snan_value_pl(S) FUNC (__builtin_nans) (S)
109 #define snan_value snan_value_pl ("")
110 #define max_value TYPE_MAX
111 #define min_value TYPE_MIN
112 #define min_subnorm_value TYPE_TRUE_MIN
114 #define arg_plus_zero ARG_LIT (0.0)
115 #define arg_minus_zero ARG_LIT (-0.0)
116 #define arg_plus_infty ARG_FUNC (__builtin_inf) ()
117 #define arg_minus_infty -(ARG_FUNC (__builtin_inf) ())
118 #define arg_qnan_value_pl(S) ARG_FUNC (__builtin_nan) (S)
119 #define arg_qnan_value arg_qnan_value_pl ("")
120 #define arg_snan_value_pl(S) ARG_FUNC (__builtin_nans) (S)
121 #define arg_snan_value arg_snan_value_pl ("")
122 #define arg_max_value ARG_TYPE_MAX
123 #define arg_min_value ARG_TYPE_MIN
124 #define arg_min_subnorm_value ARG_TYPE_TRUE_MIN
126 /* For nexttoward tests. */
127 #define snan_value_ld __builtin_nansl ("")
129 /* Structures for each kind of test. */
130 /* Used for both RUN_TEST_LOOP_f_f and RUN_TEST_LOOP_fp_f. */
131 struct test_f_f_data
133 const char *arg_str;
134 FLOAT arg;
135 struct
137 FLOAT expected;
138 int exceptions;
139 } rd, rn, rz, ru;
141 struct test_ff_f_data
143 const char *arg_str;
144 FLOAT arg1, arg2;
145 struct
147 FLOAT expected;
148 int exceptions;
149 } rd, rn, rz, ru;
151 /* Strictly speaking, a j type argument is one gen-libm-test.pl will not
152 attempt to muck with. For now, it is only used to prevent it from
153 mucking up an explicitly long double argument. */
154 struct test_fj_f_data
156 const char *arg_str;
157 FLOAT arg1;
158 long double arg2;
159 struct
161 FLOAT expected;
162 int exceptions;
163 } rd, rn, rz, ru;
165 #ifdef ARG_FLOAT
166 struct test_aa_f_data
168 const char *arg_str;
169 ARG_FLOAT arg1, arg2;
170 struct
172 FLOAT expected;
173 int exceptions;
174 } rd, rn, rz, ru;
176 #endif
177 struct test_fi_f_data
179 const char *arg_str;
180 FLOAT arg1;
181 int arg2;
182 struct
184 FLOAT expected;
185 int exceptions;
186 } rd, rn, rz, ru;
188 struct test_fl_f_data
190 const char *arg_str;
191 FLOAT arg1;
192 long int arg2;
193 struct
195 FLOAT expected;
196 int exceptions;
197 } rd, rn, rz, ru;
199 struct test_if_f_data
201 const char *arg_str;
202 int arg1;
203 FLOAT arg2;
204 struct
206 FLOAT expected;
207 int exceptions;
208 } rd, rn, rz, ru;
210 struct test_fff_f_data
212 const char *arg_str;
213 FLOAT arg1, arg2, arg3;
214 struct
216 FLOAT expected;
217 int exceptions;
218 } rd, rn, rz, ru;
220 struct test_fiu_M_data
222 const char *arg_str;
223 FLOAT arg1;
224 int arg2;
225 unsigned int arg3;
226 struct
228 intmax_t expected;
229 int exceptions;
230 } rd, rn, rz, ru;
232 struct test_fiu_U_data
234 const char *arg_str;
235 FLOAT arg1;
236 int arg2;
237 unsigned int arg3;
238 struct
240 uintmax_t expected;
241 int exceptions;
242 } rd, rn, rz, ru;
244 struct test_c_f_data
246 const char *arg_str;
247 FLOAT argr, argc;
248 struct
250 FLOAT expected;
251 int exceptions;
252 } rd, rn, rz, ru;
254 /* Used for both RUN_TEST_LOOP_f_f1 and RUN_TEST_LOOP_fI_f1. */
255 struct test_f_f1_data
257 const char *arg_str;
258 FLOAT arg;
259 struct
261 FLOAT expected;
262 int exceptions;
263 int extra_test;
264 int extra_expected;
265 } rd, rn, rz, ru;
267 struct test_fF_f1_data
269 const char *arg_str;
270 FLOAT arg;
271 struct
273 FLOAT expected;
274 int exceptions;
275 int extra_test;
276 FLOAT extra_expected;
277 } rd, rn, rz, ru;
279 struct test_ffI_f1_data
281 const char *arg_str;
282 FLOAT arg1, arg2;
283 struct
285 FLOAT expected;
286 int exceptions;
287 int extra_test;
288 int extra_expected;
289 } rd, rn, rz, ru;
291 struct test_c_c_data
293 const char *arg_str;
294 FLOAT argr, argc;
295 struct
297 FLOAT expr, expc;
298 int exceptions;
299 } rd, rn, rz, ru;
301 struct test_cc_c_data
303 const char *arg_str;
304 FLOAT arg1r, arg1c, arg2r, arg2c;
305 struct
307 FLOAT expr, expc;
308 int exceptions;
309 } rd, rn, rz, ru;
311 /* Used for all of RUN_TEST_LOOP_f_i, RUN_TEST_LOOP_f_i_tg,
312 RUN_TEST_LOOP_f_b and RUN_TEST_LOOP_f_b_tg. */
313 struct test_f_i_data
315 const char *arg_str;
316 FLOAT arg;
317 struct
319 int expected;
320 int exceptions;
321 } rd, rn, rz, ru;
323 /* Used for both RUN_TEST_LOOP_ff_b and RUN_TEST_LOOP_ff_i_tg. */
324 struct test_ff_i_data
326 const char *arg_str;
327 FLOAT arg1, arg2;
328 struct
330 int expected;
331 int exceptions;
332 } rd, rn, rz, ru;
334 struct test_f_l_data
336 const char *arg_str;
337 FLOAT arg;
338 struct
340 long int expected;
341 int exceptions;
342 } rd, rn, rz, ru;
344 struct test_f_L_data
346 const char *arg_str;
347 FLOAT arg;
348 struct
350 long long int expected;
351 int exceptions;
352 } rd, rn, rz, ru;
354 struct test_fFF_11_data
356 const char *arg_str;
357 FLOAT arg;
358 struct
360 int exceptions;
361 int extra1_test;
362 FLOAT extra1_expected;
363 int extra2_test;
364 FLOAT extra2_expected;
365 } rd, rn, rz, ru;
367 /* Used for both RUN_TEST_LOOP_Ff_b1 and RUN_TEST_LOOP_Ffp_b1. */
368 struct test_Ff_b1_data
370 const char *arg_str;
371 FLOAT arg;
372 struct
374 int expected;
375 int exceptions;
376 int extra_test;
377 FLOAT extra_expected;
378 } rd, rn, rz, ru;
381 /* Set the rounding mode, or restore the saved value. */
382 #define IF_ROUND_INIT_ /* Empty. */
383 #define IF_ROUND_INIT_FE_DOWNWARD \
384 int save_round_mode = fegetround (); \
385 if (ROUNDING_TESTS (FLOAT, FE_DOWNWARD) \
386 && fesetround (FE_DOWNWARD) == 0)
387 #define IF_ROUND_INIT_FE_TONEAREST \
388 int save_round_mode = fegetround (); \
389 if (ROUNDING_TESTS (FLOAT, FE_TONEAREST) \
390 && fesetround (FE_TONEAREST) == 0)
391 #define IF_ROUND_INIT_FE_TOWARDZERO \
392 int save_round_mode = fegetround (); \
393 if (ROUNDING_TESTS (FLOAT, FE_TOWARDZERO) \
394 && fesetround (FE_TOWARDZERO) == 0)
395 #define IF_ROUND_INIT_FE_UPWARD \
396 int save_round_mode = fegetround (); \
397 if (ROUNDING_TESTS (FLOAT, FE_UPWARD) \
398 && fesetround (FE_UPWARD) == 0)
399 #define ROUND_RESTORE_ /* Empty. */
400 #define ROUND_RESTORE_FE_DOWNWARD \
401 fesetround (save_round_mode)
402 #define ROUND_RESTORE_FE_TONEAREST \
403 fesetround (save_round_mode)
404 #define ROUND_RESTORE_FE_TOWARDZERO \
405 fesetround (save_round_mode)
406 #define ROUND_RESTORE_FE_UPWARD \
407 fesetround (save_round_mode)
409 /* Field name to use for a given rounding mode. */
410 #define RM_ rn
411 #define RM_FE_DOWNWARD rd
412 #define RM_FE_TONEAREST rn
413 #define RM_FE_TOWARDZERO rz
414 #define RM_FE_UPWARD ru
416 /* Common setup for an individual test. */
417 #define COMMON_TEST_SETUP(ARG_STR) \
418 char *test_name; \
419 if (asprintf (&test_name, "%s (%s)", this_func, (ARG_STR)) == -1) \
420 abort ()
422 /* Setup for a test with an extra output. */
423 #define EXTRA_OUTPUT_TEST_SETUP(ARG_STR, N) \
424 char *extra##N##_name; \
425 if (asprintf (&extra##N##_name, "%s (%s) extra output " #N, \
426 this_func, (ARG_STR)) == -1) \
427 abort ()
429 /* Common cleanup after an individual test. */
430 #define COMMON_TEST_CLEANUP \
431 free (test_name)
433 /* Cleanup for a test with an extra output. */
434 #define EXTRA_OUTPUT_TEST_CLEANUP(N) \
435 free (extra##N##_name)
437 /* Run an individual test, including any required setup and checking
438 of results, or loop over all tests in an array. */
439 #define RUN_TEST_f_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
440 EXCEPTIONS) \
441 do \
442 if (enable_test (EXCEPTIONS)) \
444 COMMON_TEST_SETUP (ARG_STR); \
445 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
446 EXPECTED, EXCEPTIONS); \
447 COMMON_TEST_CLEANUP; \
449 while (0)
450 #define RUN_TEST_LOOP_f_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
451 IF_ROUND_INIT_ ## ROUNDING_MODE \
452 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
453 RUN_TEST_f_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
454 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
455 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
456 ROUND_RESTORE_ ## ROUNDING_MODE
457 #define RUN_TEST_fp_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
458 EXCEPTIONS) \
459 do \
460 if (enable_test (EXCEPTIONS)) \
462 COMMON_TEST_SETUP (ARG_STR); \
463 check_float (test_name, FUNC_TEST (FUNC_NAME) (&(ARG)), \
464 EXPECTED, EXCEPTIONS); \
465 COMMON_TEST_CLEANUP; \
467 while (0)
468 #define RUN_TEST_LOOP_fp_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
469 IF_ROUND_INIT_ ## ROUNDING_MODE \
470 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
471 RUN_TEST_fp_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
472 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
473 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
474 ROUND_RESTORE_ ## ROUNDING_MODE
475 #define RUN_TEST_2_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
476 EXCEPTIONS) \
477 do \
478 if (enable_test (EXCEPTIONS)) \
480 COMMON_TEST_SETUP (ARG_STR); \
481 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
482 EXPECTED, EXCEPTIONS); \
483 COMMON_TEST_CLEANUP; \
485 while (0)
486 #define RUN_TEST_LOOP_2_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
487 IF_ROUND_INIT_ ## ROUNDING_MODE \
488 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
489 RUN_TEST_2_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
490 (ARRAY)[i].arg2, \
491 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
492 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
493 ROUND_RESTORE_ ## ROUNDING_MODE
494 #define RUN_TEST_ff_f RUN_TEST_2_f
495 #define RUN_TEST_LOOP_ff_f RUN_TEST_LOOP_2_f
496 #define RUN_TEST_LOOP_fj_f RUN_TEST_LOOP_2_f
497 #define RUN_TEST_LOOP_aa_f RUN_TEST_LOOP_2_f
498 #define RUN_TEST_fi_f RUN_TEST_2_f
499 #define RUN_TEST_LOOP_fi_f RUN_TEST_LOOP_2_f
500 #define RUN_TEST_fl_f RUN_TEST_2_f
501 #define RUN_TEST_LOOP_fl_f RUN_TEST_LOOP_2_f
502 #define RUN_TEST_if_f RUN_TEST_2_f
503 #define RUN_TEST_LOOP_if_f RUN_TEST_LOOP_2_f
504 #define RUN_TEST_fff_f(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
505 EXPECTED, EXCEPTIONS) \
506 do \
507 if (enable_test (EXCEPTIONS)) \
509 COMMON_TEST_SETUP (ARG_STR); \
510 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
511 EXPECTED, EXCEPTIONS); \
512 COMMON_TEST_CLEANUP; \
514 while (0)
515 #define RUN_TEST_LOOP_fff_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
516 IF_ROUND_INIT_ ## ROUNDING_MODE \
517 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
518 RUN_TEST_fff_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
519 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
520 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
521 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
522 ROUND_RESTORE_ ## ROUNDING_MODE
523 #define RUN_TEST_fiu_M(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
524 EXPECTED, EXCEPTIONS) \
525 do \
526 if (enable_test (EXCEPTIONS)) \
528 COMMON_TEST_SETUP (ARG_STR); \
529 check_intmax_t (test_name, \
530 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
531 EXPECTED, EXCEPTIONS); \
532 COMMON_TEST_CLEANUP; \
534 while (0)
535 #define RUN_TEST_LOOP_fiu_M(FUNC_NAME, ARRAY, ROUNDING_MODE) \
536 IF_ROUND_INIT_ ## ROUNDING_MODE \
537 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
538 RUN_TEST_fiu_M ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
539 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
540 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
541 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
542 ROUND_RESTORE_ ## ROUNDING_MODE
543 #define RUN_TEST_fiu_U(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
544 EXPECTED, EXCEPTIONS) \
545 do \
546 if (enable_test (EXCEPTIONS)) \
548 COMMON_TEST_SETUP (ARG_STR); \
549 check_uintmax_t (test_name, \
550 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
551 EXPECTED, EXCEPTIONS); \
552 COMMON_TEST_CLEANUP; \
554 while (0)
555 #define RUN_TEST_LOOP_fiu_U(FUNC_NAME, ARRAY, ROUNDING_MODE) \
556 IF_ROUND_INIT_ ## ROUNDING_MODE \
557 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
558 RUN_TEST_fiu_U ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
559 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
560 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
561 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
562 ROUND_RESTORE_ ## ROUNDING_MODE
563 #define RUN_TEST_c_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
564 EXCEPTIONS) \
565 do \
566 if (enable_test (EXCEPTIONS)) \
568 COMMON_TEST_SETUP (ARG_STR); \
569 check_float (test_name, \
570 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1, ARG2)),\
571 EXPECTED, EXCEPTIONS); \
572 COMMON_TEST_CLEANUP; \
574 while (0)
575 #define RUN_TEST_LOOP_c_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
576 IF_ROUND_INIT_ ## ROUNDING_MODE \
577 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
578 RUN_TEST_c_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
579 (ARRAY)[i].argc, \
580 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
581 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
582 ROUND_RESTORE_ ## ROUNDING_MODE
583 #define RUN_TEST_f_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
584 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
585 EXTRA_EXPECTED) \
586 do \
587 if (enable_test (EXCEPTIONS)) \
589 COMMON_TEST_SETUP (ARG_STR); \
590 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
591 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
592 EXCEPTIONS); \
593 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
594 if (EXTRA_TEST) \
595 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
596 EXTRA_OUTPUT_TEST_CLEANUP (1); \
597 COMMON_TEST_CLEANUP; \
599 while (0)
600 #define RUN_TEST_LOOP_f_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
601 IF_ROUND_INIT_ ## ROUNDING_MODE \
602 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
603 RUN_TEST_f_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
604 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
605 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
606 EXTRA_VAR, \
607 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
608 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
609 ROUND_RESTORE_ ## ROUNDING_MODE
610 #define RUN_TEST_fF_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
611 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
612 EXTRA_EXPECTED) \
613 do \
614 if (enable_test (EXCEPTIONS)) \
616 COMMON_TEST_SETUP (ARG_STR); \
617 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
618 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
619 EXPECTED, EXCEPTIONS); \
620 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
621 if (EXTRA_TEST) \
622 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
623 EXTRA_OUTPUT_TEST_CLEANUP (1); \
624 COMMON_TEST_CLEANUP; \
626 while (0)
627 #define RUN_TEST_LOOP_fF_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
628 IF_ROUND_INIT_ ## ROUNDING_MODE \
629 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
630 RUN_TEST_fF_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
631 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
632 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
633 EXTRA_VAR, \
634 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
635 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
636 ROUND_RESTORE_ ## ROUNDING_MODE
637 #define RUN_TEST_fI_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
638 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
639 EXTRA_EXPECTED) \
640 do \
641 if (enable_test (EXCEPTIONS)) \
643 COMMON_TEST_SETUP (ARG_STR); \
644 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
645 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
646 EXPECTED, EXCEPTIONS); \
647 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
648 if (EXTRA_TEST) \
649 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
650 EXTRA_OUTPUT_TEST_CLEANUP (1); \
651 COMMON_TEST_CLEANUP; \
653 while (0)
654 #define RUN_TEST_LOOP_fI_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
655 IF_ROUND_INIT_ ## ROUNDING_MODE \
656 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
657 RUN_TEST_fI_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
658 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
659 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
660 EXTRA_VAR, \
661 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
662 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
663 ROUND_RESTORE_ ## ROUNDING_MODE
664 #define RUN_TEST_ffI_f1_mod8(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
665 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
666 EXTRA_EXPECTED) \
667 do \
668 if (enable_test (EXCEPTIONS)) \
670 COMMON_TEST_SETUP (ARG_STR); \
671 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
672 check_float (test_name, \
673 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, &(EXTRA_VAR)), \
674 EXPECTED, EXCEPTIONS); \
675 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
676 if (EXTRA_TEST) \
677 check_int (extra1_name, (EXTRA_VAR) % 8, EXTRA_EXPECTED, 0); \
678 EXTRA_OUTPUT_TEST_CLEANUP (1); \
679 COMMON_TEST_CLEANUP; \
681 while (0)
682 #define RUN_TEST_LOOP_ffI_f1_mod8(FUNC_NAME, ARRAY, ROUNDING_MODE, \
683 EXTRA_VAR) \
684 IF_ROUND_INIT_ ## ROUNDING_MODE \
685 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
686 RUN_TEST_ffI_f1_mod8 ((ARRAY)[i].arg_str, FUNC_NAME, \
687 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
688 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
689 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
690 EXTRA_VAR, \
691 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
692 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
693 ROUND_RESTORE_ ## ROUNDING_MODE
694 #define RUN_TEST_Ff_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
695 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
696 EXTRA_EXPECTED) \
697 do \
698 if (enable_test (EXCEPTIONS)) \
700 COMMON_TEST_SETUP (ARG_STR); \
701 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
702 /* Clear any exceptions from comparison involving sNaN \
703 EXTRA_EXPECTED. */ \
704 feclearexcept (FE_ALL_EXCEPT); \
705 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
706 (ARG)), \
707 EXPECTED, EXCEPTIONS); \
708 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
709 if (EXTRA_TEST) \
710 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
711 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
712 EXTRA_OUTPUT_TEST_CLEANUP (1); \
713 COMMON_TEST_CLEANUP; \
715 while (0)
716 #define RUN_TEST_LOOP_Ff_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
717 EXTRA_VAR) \
718 IF_ROUND_INIT_ ## ROUNDING_MODE \
719 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
720 RUN_TEST_Ff_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
721 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
722 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
723 EXTRA_VAR, \
724 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
725 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
726 ROUND_RESTORE_ ## ROUNDING_MODE
727 #define RUN_TEST_Ffp_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
728 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
729 EXTRA_EXPECTED) \
730 do \
731 if (enable_test (EXCEPTIONS)) \
733 COMMON_TEST_SETUP (ARG_STR); \
734 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
735 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
736 &(ARG)), \
737 EXPECTED, EXCEPTIONS); \
738 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
739 if (EXTRA_TEST) \
740 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
741 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
742 EXTRA_OUTPUT_TEST_CLEANUP (1); \
743 COMMON_TEST_CLEANUP; \
745 while (0)
746 #define RUN_TEST_LOOP_Ffp_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
747 EXTRA_VAR) \
748 IF_ROUND_INIT_ ## ROUNDING_MODE \
749 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
750 RUN_TEST_Ffp_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
751 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
752 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
753 EXTRA_VAR, \
754 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
755 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
756 ROUND_RESTORE_ ## ROUNDING_MODE
757 #define RUN_TEST_c_c(ARG_STR, FUNC_NAME, ARGR, ARGC, EXPR, EXPC, \
758 EXCEPTIONS) \
759 do \
760 if (enable_test (EXCEPTIONS)) \
762 COMMON_TEST_SETUP (ARG_STR); \
763 check_complex (test_name, \
764 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARGR, ARGC)), \
765 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
766 COMMON_TEST_CLEANUP; \
768 while (0)
769 #define RUN_TEST_LOOP_c_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
770 IF_ROUND_INIT_ ## ROUNDING_MODE \
771 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
772 RUN_TEST_c_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
773 (ARRAY)[i].argc, \
774 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
775 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
776 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
777 ROUND_RESTORE_ ## ROUNDING_MODE
778 #define RUN_TEST_cc_c(ARG_STR, FUNC_NAME, ARG1R, ARG1C, ARG2R, ARG2C, \
779 EXPR, EXPC, EXCEPTIONS) \
780 do \
781 if (enable_test (EXCEPTIONS)) \
783 COMMON_TEST_SETUP (ARG_STR); \
784 check_complex (test_name, \
785 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1R, ARG1C), \
786 BUILD_COMPLEX (ARG2R, ARG2C)), \
787 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
788 COMMON_TEST_CLEANUP; \
790 while (0)
791 #define RUN_TEST_LOOP_cc_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
792 IF_ROUND_INIT_ ## ROUNDING_MODE \
793 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
794 RUN_TEST_cc_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1r, \
795 (ARRAY)[i].arg1c, (ARRAY)[i].arg2r, \
796 (ARRAY)[i].arg2c, \
797 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
798 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
799 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
800 ROUND_RESTORE_ ## ROUNDING_MODE
801 #define RUN_TEST_f_i(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
802 do \
803 if (enable_test (EXCEPTIONS)) \
805 COMMON_TEST_SETUP (ARG_STR); \
806 check_int (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
807 EXCEPTIONS); \
808 COMMON_TEST_CLEANUP; \
810 while (0)
811 #define RUN_TEST_LOOP_f_i(FUNC_NAME, ARRAY, ROUNDING_MODE) \
812 IF_ROUND_INIT_ ## ROUNDING_MODE \
813 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
814 RUN_TEST_f_i ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
815 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
816 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
817 ROUND_RESTORE_ ## ROUNDING_MODE
818 #define RUN_TEST_f_i_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
819 EXCEPTIONS) \
820 do \
821 if (enable_test (EXCEPTIONS)) \
823 COMMON_TEST_SETUP (ARG_STR); \
824 check_int (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
825 COMMON_TEST_CLEANUP; \
827 while (0)
828 #define RUN_TEST_LOOP_f_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
829 IF_ROUND_INIT_ ## ROUNDING_MODE \
830 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
831 RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
832 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
833 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
834 ROUND_RESTORE_ ## ROUNDING_MODE
835 #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
836 EXCEPTIONS) \
837 do \
838 if (enable_test (EXCEPTIONS)) \
840 COMMON_TEST_SETUP (ARG_STR); \
841 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
842 EXPECTED, EXCEPTIONS); \
843 COMMON_TEST_CLEANUP; \
845 while (0)
846 #define RUN_TEST_LOOP_ff_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
847 IF_ROUND_INIT_ ## ROUNDING_MODE \
848 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
849 RUN_TEST_ff_b ((ARRAY)[i].arg_str, FUNC_NAME, \
850 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
851 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
852 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
853 ROUND_RESTORE_ ## ROUNDING_MODE
854 #define RUN_TEST_ff_i_tg(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
855 EXCEPTIONS) \
856 do \
857 if (enable_test (EXCEPTIONS)) \
859 COMMON_TEST_SETUP (ARG_STR); \
860 check_int (test_name, FUNC_NAME (ARG1, ARG2), EXPECTED, \
861 EXCEPTIONS); \
862 COMMON_TEST_CLEANUP; \
864 while (0)
865 #define RUN_TEST_LOOP_ff_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
866 IF_ROUND_INIT_ ## ROUNDING_MODE \
867 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
868 RUN_TEST_ff_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, \
869 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
870 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
871 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
872 ROUND_RESTORE_ ## ROUNDING_MODE
873 #define RUN_TEST_f_b(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
874 do \
875 if (enable_test (EXCEPTIONS)) \
877 COMMON_TEST_SETUP (ARG_STR); \
878 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
879 EXCEPTIONS); \
880 COMMON_TEST_CLEANUP; \
882 while (0)
883 #define RUN_TEST_LOOP_f_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
884 IF_ROUND_INIT_ ## ROUNDING_MODE \
885 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
886 RUN_TEST_f_b ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
887 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
888 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
889 ROUND_RESTORE_ ## ROUNDING_MODE
890 #define RUN_TEST_f_b_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
891 EXCEPTIONS) \
892 do \
893 if (enable_test (EXCEPTIONS)) \
895 COMMON_TEST_SETUP (ARG_STR); \
896 check_bool (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
897 COMMON_TEST_CLEANUP; \
899 while (0)
900 #define RUN_TEST_LOOP_f_b_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
901 IF_ROUND_INIT_ ## ROUNDING_MODE \
902 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
903 RUN_TEST_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
904 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
905 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
906 ROUND_RESTORE_ ## ROUNDING_MODE
907 #define RUN_TEST_f_l(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
908 do \
909 if (enable_test (EXCEPTIONS)) \
911 COMMON_TEST_SETUP (ARG_STR); \
912 check_long (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
913 EXCEPTIONS); \
914 COMMON_TEST_CLEANUP; \
916 while (0)
917 #define RUN_TEST_LOOP_f_l(FUNC_NAME, ARRAY, ROUNDING_MODE) \
918 IF_ROUND_INIT_ ## ROUNDING_MODE \
919 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
920 RUN_TEST_f_l ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
921 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
922 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
923 ROUND_RESTORE_ ## ROUNDING_MODE
924 #define RUN_TEST_f_L(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
925 do \
926 if (enable_test (EXCEPTIONS)) \
928 COMMON_TEST_SETUP (ARG_STR); \
929 check_longlong (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
930 EXPECTED, EXCEPTIONS); \
931 COMMON_TEST_CLEANUP; \
933 while (0)
934 #define RUN_TEST_LOOP_f_L(FUNC_NAME, ARRAY, ROUNDING_MODE) \
935 IF_ROUND_INIT_ ## ROUNDING_MODE \
936 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
937 RUN_TEST_f_L ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
938 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
939 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
940 ROUND_RESTORE_ ## ROUNDING_MODE
941 #define RUN_TEST_fFF_11(ARG_STR, FUNC_NAME, ARG, EXCEPTIONS, \
942 EXTRA1_VAR, EXTRA1_TEST, \
943 EXTRA1_EXPECTED, EXTRA2_VAR, \
944 EXTRA2_TEST, EXTRA2_EXPECTED) \
945 do \
946 if (enable_test (EXCEPTIONS)) \
948 COMMON_TEST_SETUP (ARG_STR); \
949 FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA1_VAR), &(EXTRA2_VAR)); \
950 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
951 if (EXTRA1_TEST) \
952 check_float (extra1_name, EXTRA1_VAR, EXTRA1_EXPECTED, \
953 EXCEPTIONS); \
954 EXTRA_OUTPUT_TEST_CLEANUP (1); \
955 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 2); \
956 if (EXTRA2_TEST) \
957 check_float (extra2_name, EXTRA2_VAR, EXTRA2_EXPECTED, 0); \
958 EXTRA_OUTPUT_TEST_CLEANUP (2); \
959 COMMON_TEST_CLEANUP; \
961 while (0)
962 #define RUN_TEST_LOOP_fFF_11(FUNC_NAME, ARRAY, ROUNDING_MODE, \
963 EXTRA1_VAR, EXTRA2_VAR) \
964 IF_ROUND_INIT_ ## ROUNDING_MODE \
965 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
966 RUN_TEST_fFF_11 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
967 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
968 EXTRA1_VAR, \
969 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_test, \
970 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_expected, \
971 EXTRA2_VAR, \
972 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_test, \
973 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \
974 ROUND_RESTORE_ ## ROUNDING_MODE
976 #if TEST_MATHVEC
977 # define TEST_SUFF VEC_SUFF
978 # define TEST_SUFF_STR
979 #elif TEST_NARROW
980 # define TEST_SUFF
981 # define TEST_SUFF_STR "_" ARG_TYPE_STR
982 #else
983 # define TEST_SUFF
984 # define TEST_SUFF_STR
985 #endif
987 #define STR_CONCAT(a, b, c) __STRING (a##b##c)
988 #define STR_CON3(a, b, c) STR_CONCAT (a, b, c)
990 #if TEST_NARROW
991 # define TEST_COND_any_ibm128 (TEST_COND_ibm128 || TEST_COND_arg_ibm128)
992 #else
993 # define TEST_COND_any_ibm128 TEST_COND_ibm128
994 #endif
996 /* Start and end the tests for a given function. */
997 #define START(FUN, SUFF, EXACT) \
998 CHECK_ARCH_EXT; \
999 const char *this_func \
1000 = STR_CON3 (FUN, SUFF, TEST_SUFF) TEST_SUFF_STR; \
1001 init_max_error (this_func, EXACT, TEST_COND_any_ibm128)
1002 #define END \
1003 print_max_error (this_func)
1004 #define END_COMPLEX \
1005 print_complex_max_error (this_func)
1007 /* Run tests for a given function in all rounding modes. */
1008 #define ALL_RM_TEST(FUNC, EXACT, ARRAY, LOOP_MACRO, END_MACRO, ...) \
1009 do \
1011 do \
1013 START (FUNC,, EXACT); \
1014 LOOP_MACRO (FUNC, ARRAY, , ## __VA_ARGS__); \
1015 END_MACRO; \
1017 while (0); \
1018 do \
1020 START (FUNC, _downward, EXACT); \
1021 LOOP_MACRO (FUNC, ARRAY, FE_DOWNWARD, ## __VA_ARGS__); \
1022 END_MACRO; \
1024 while (0); \
1025 do \
1027 START (FUNC, _towardzero, EXACT); \
1028 LOOP_MACRO (FUNC, ARRAY, FE_TOWARDZERO, ## __VA_ARGS__); \
1029 END_MACRO; \
1031 while (0); \
1032 do \
1034 START (FUNC, _upward, EXACT); \
1035 LOOP_MACRO (FUNC, ARRAY, FE_UPWARD, ## __VA_ARGS__); \
1036 END_MACRO; \
1038 while (0); \
1040 while (0);
1042 /* Short description of program. */
1043 const char doc[] = "Math test suite: " TEST_MSG ;
1045 static void do_test (void);
1048 main (int argc, char **argv)
1050 libm_test_init (argc, argv);
1051 INIT_ARCH_EXT;
1052 do_test ();
1053 return libm_test_finish ();