1 /* Support code for testing libm functions (driver).
2 Copyright (C) 1997-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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 <https://www.gnu.org/licenses/>. */
18
19 #include "libm-test-support.h"
20
21 #include <math-tests-arch.h>
22
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_mathvec = TEST_MATHVEC;
27
28 #if TEST_NARROW
29 const int snan_tests_arg = SNAN_TESTS (ARG_FLOAT);
30 #else
31 const int snan_tests_arg = SNAN_TESTS (FLOAT);
32 #endif
33
34 #define STRX(x) #x
35 #define STR(x) STRX (x)
36 #define STR_FLOAT STR (FLOAT)
37 #define STR_ARG_FLOAT STR (ARG_FLOAT)
38 #define STR_VEC_LEN STR (VEC_LEN)
39
40 /* Informal description of the functions being tested. */
41 #if TEST_MATHVEC
42 # define TEST_MSG "testing " STR_FLOAT " (vector length " STR_VEC_LEN ")\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;
49
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
65
66 #define TEST_NAN_PAYLOAD_CANONICALIZE (SNAN_TESTS_PRESERVE_PAYLOAD \
67 ? TEST_NAN_PAYLOAD \
68 : 0)
69
70 const char qtype_str[] = TYPE_STR;
71
72 /* Various constants derived from pi. We must supply them precalculated for
73 accuracy. They are written as a series of postfix operations to keep
74 them concise yet somewhat readable. */
75
76 /* (pi * 3) / 4 */
77 #define lit_pi_3_m_4_d LIT (2.356194490192344928846982537459627163)
78 /* pi * 3 / (4 * ln(10)) */
79 #define lit_pi_3_m_4_ln10_m_d LIT (1.023282265381381010614337719073516828)
80 /* pi / (2 * ln(10)) */
81 #define lit_pi_2_ln10_m_d LIT (0.682188176920920673742891812715677885)
82 /* pi / (4 * ln(10)) */
83 #define lit_pi_4_ln10_m_d LIT (0.341094088460460336871445906357838943)
84 /* pi / ln(10) */
85 #define lit_pi_ln10_d LIT (1.364376353841841347485783625431355770)
86 /* pi / 2 */
87 #define lit_pi_2_d LITM (M_PI_2)
88 /* pi / 4 */
89 #define lit_pi_4_d LITM (M_PI_4)
90 /* pi */
91 #define lit_pi LITM (M_PI)
92
93 /* Other useful constants. */
94
95 /* e */
96 #define lit_e LITM (M_E)
97
98 #define plus_zero LIT (0.0)
99 #define minus_zero LIT (-0.0)
100 #define plus_infty FUNC (__builtin_inf) ()
101 #define minus_infty -(FUNC (__builtin_inf) ())
102 #define qnan_value_pl(S) FUNC (__builtin_nan) (S)
103 #define qnan_value qnan_value_pl ("")
104 #define snan_value_pl(S) FUNC (__builtin_nans) (S)
105 #define snan_value snan_value_pl ("")
106 #define max_value TYPE_MAX
107 #define min_value TYPE_MIN
108 #define min_subnorm_value TYPE_TRUE_MIN
109
110 #define arg_plus_zero ARG_LIT (0.0)
111 #define arg_minus_zero ARG_LIT (-0.0)
112 #define arg_plus_infty ARG_FUNC (__builtin_inf) ()
113 #define arg_minus_infty -(ARG_FUNC (__builtin_inf) ())
114 #define arg_qnan_value_pl(S) ARG_FUNC (__builtin_nan) (S)
115 #define arg_qnan_value arg_qnan_value_pl ("")
116 #define arg_snan_value_pl(S) ARG_FUNC (__builtin_nans) (S)
117 #define arg_snan_value arg_snan_value_pl ("")
118 #define arg_max_value ARG_TYPE_MAX
119 #define arg_min_value ARG_TYPE_MIN
120 #define arg_min_subnorm_value ARG_TYPE_TRUE_MIN
121
122 /* For nexttoward tests. */
123 #define snan_value_ld __builtin_nansl ("")
124
125 /* For pseudo-normal number tests. */
126 #if TEST_COND_intel96
127 # include <math_ldbl.h>
128 #define pseudo_inf { .parts = { 0x00000000, 0x00000000, 0x7fff }}
129 #define pseudo_zero { .parts = { 0x00000000, 0x00000000, 0x0100 }}
130 #define pseudo_qnan { .parts = { 0x00000001, 0x00000000, 0x7fff }}
131 #define pseudo_snan { .parts = { 0x00000001, 0x40000000, 0x7fff }}
132 #define pseudo_unnormal { .parts = { 0x00000001, 0x40000000, 0x0100 }}
133 #endif
134
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
138 {
139 const char *arg_str;
140 FLOAT arg;
141 struct
142 {
143 FLOAT expected;
144 int exceptions;
145 } rd, rn, rz, ru;
146 };
147 struct test_ff_f_data
148 {
149 const char *arg_str;
150 FLOAT arg1, arg2;
151 struct
152 {
153 FLOAT expected;
154 int exceptions;
155 } rd, rn, rz, ru;
156 };
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
161 {
162 const char *arg_str;
163 FLOAT arg1;
164 long double arg2;
165 struct
166 {
167 FLOAT expected;
168 int exceptions;
169 } rd, rn, rz, ru;
170 };
171 #ifdef ARG_FLOAT
172 struct test_a_f_data
173 {
174 const char *arg_str;
175 ARG_FLOAT arg;
176 struct
177 {
178 FLOAT expected;
179 int exceptions;
180 } rd, rn, rz, ru;
181 };
182 struct test_aa_f_data
183 {
184 const char *arg_str;
185 ARG_FLOAT arg1, arg2;
186 struct
187 {
188 FLOAT expected;
189 int exceptions;
190 } rd, rn, rz, ru;
191 };
192 struct test_aaa_f_data
193 {
194 const char *arg_str;
195 ARG_FLOAT arg1, arg2, arg3;
196 struct
197 {
198 FLOAT expected;
199 int exceptions;
200 } rd, rn, rz, ru;
201 };
202 #endif
203 struct test_fi_f_data
204 {
205 const char *arg_str;
206 FLOAT arg1;
207 int arg2;
208 struct
209 {
210 FLOAT expected;
211 int exceptions;
212 } rd, rn, rz, ru;
213 };
214 struct test_fl_f_data
215 {
216 const char *arg_str;
217 FLOAT arg1;
218 long int arg2;
219 struct
220 {
221 FLOAT expected;
222 int exceptions;
223 } rd, rn, rz, ru;
224 };
225 struct test_if_f_data
226 {
227 const char *arg_str;
228 int arg1;
229 FLOAT arg2;
230 struct
231 {
232 FLOAT expected;
233 int exceptions;
234 } rd, rn, rz, ru;
235 };
236 struct test_fff_f_data
237 {
238 const char *arg_str;
239 FLOAT arg1, arg2, arg3;
240 struct
241 {
242 FLOAT expected;
243 int exceptions;
244 } rd, rn, rz, ru;
245 };
246 struct test_fiu_M_data
247 {
248 const char *arg_str;
249 FLOAT arg1;
250 int arg2;
251 unsigned int arg3;
252 struct
253 {
254 intmax_t expected;
255 int exceptions;
256 } rd, rn, rz, ru;
257 };
258 struct test_fiu_U_data
259 {
260 const char *arg_str;
261 FLOAT arg1;
262 int arg2;
263 unsigned int arg3;
264 struct
265 {
266 uintmax_t expected;
267 int exceptions;
268 } rd, rn, rz, ru;
269 };
270 struct test_c_f_data
271 {
272 const char *arg_str;
273 FLOAT argr, argc;
274 struct
275 {
276 FLOAT expected;
277 int exceptions;
278 } rd, rn, rz, ru;
279 };
280 /* Used for both RUN_TEST_LOOP_f_f1 and RUN_TEST_LOOP_fI_f1. */
281 struct test_f_f1_data
282 {
283 const char *arg_str;
284 FLOAT arg;
285 struct
286 {
287 FLOAT expected;
288 int exceptions;
289 int extra_test;
290 int extra_expected;
291 } rd, rn, rz, ru;
292 };
293 struct test_fF_f1_data
294 {
295 const char *arg_str;
296 FLOAT arg;
297 struct
298 {
299 FLOAT expected;
300 int exceptions;
301 int extra_test;
302 FLOAT extra_expected;
303 } rd, rn, rz, ru;
304 };
305 struct test_ffI_f1_data
306 {
307 const char *arg_str;
308 FLOAT arg1, arg2;
309 struct
310 {
311 FLOAT expected;
312 int exceptions;
313 int extra_test;
314 int extra_expected;
315 } rd, rn, rz, ru;
316 };
317 struct test_c_c_data
318 {
319 const char *arg_str;
320 FLOAT argr, argc;
321 struct
322 {
323 FLOAT expr, expc;
324 int exceptions;
325 } rd, rn, rz, ru;
326 };
327 struct test_cc_c_data
328 {
329 const char *arg_str;
330 FLOAT arg1r, arg1c, arg2r, arg2c;
331 struct
332 {
333 FLOAT expr, expc;
334 int exceptions;
335 } rd, rn, rz, ru;
336 };
337 /* Used for all of RUN_TEST_LOOP_f_i, RUN_TEST_LOOP_f_i_tg,
338 RUN_TEST_LOOP_f_b and RUN_TEST_LOOP_f_b_tg. */
339 struct test_f_i_data
340 {
341 const char *arg_str;
342 FLOAT arg;
343 struct
344 {
345 int expected;
346 int exceptions;
347 } rd, rn, rz, ru;
348 };
349 /* Used for RUN_TEST_LOOP_f_i_tg_u and RUN_TEST_LOOP_f_b_tg_u. */
350 #if TEST_COND_intel96
351 struct test_j_i_data_u
352 {
353 const char *arg_str;
354 ieee_long_double_shape_type arg;
355 struct
356 {
357 int expected;
358 int exceptions;
359 } rd, rn, rz, ru;
360 };
361 #endif
362 /* Used for RUN_TEST_LOOP_ff_b, RUN_TEST_LOOP_fpfp_b and
363 RUN_TEST_LOOP_ff_i_tg. */
364 struct test_ff_i_data
365 {
366 const char *arg_str;
367 FLOAT arg1, arg2;
368 struct
369 {
370 int expected;
371 int exceptions;
372 } rd, rn, rz, ru;
373 };
374 struct test_f_l_data
375 {
376 const char *arg_str;
377 FLOAT arg;
378 struct
379 {
380 long int expected;
381 int exceptions;
382 } rd, rn, rz, ru;
383 };
384 struct test_f_L_data
385 {
386 const char *arg_str;
387 FLOAT arg;
388 struct
389 {
390 long long int expected;
391 int exceptions;
392 } rd, rn, rz, ru;
393 };
394 struct test_fFF_11_data
395 {
396 const char *arg_str;
397 FLOAT arg;
398 struct
399 {
400 int exceptions;
401 int extra1_test;
402 FLOAT extra1_expected;
403 int extra2_test;
404 FLOAT extra2_expected;
405 } rd, rn, rz, ru;
406 };
407 /* Used for both RUN_TEST_LOOP_Ff_b1 and RUN_TEST_LOOP_Ffp_b1. */
408 struct test_Ff_b1_data
409 {
410 const char *arg_str;
411 FLOAT arg;
412 struct
413 {
414 int expected;
415 int exceptions;
416 int extra_test;
417 FLOAT extra_expected;
418 } rd, rn, rz, ru;
419 };
420
421 /* Set the rounding mode, or restore the saved value. */
422 #define IF_ROUND_INIT_ /* Empty. */
423 #define IF_ROUND_INIT_FE_DOWNWARD \
424 int save_round_mode = fegetround (); \
425 if (ROUNDING_TESTS (FLOAT, FE_DOWNWARD) \
426 && !TEST_MATHVEC \
427 && fesetround (FE_DOWNWARD) == 0)
428 #define IF_ROUND_INIT_FE_TONEAREST \
429 int save_round_mode = fegetround (); \
430 if (ROUNDING_TESTS (FLOAT, FE_TONEAREST) \
431 && fesetround (FE_TONEAREST) == 0)
432 #define IF_ROUND_INIT_FE_TOWARDZERO \
433 int save_round_mode = fegetround (); \
434 if (ROUNDING_TESTS (FLOAT, FE_TOWARDZERO) \
435 && !TEST_MATHVEC \
436 && fesetround (FE_TOWARDZERO) == 0)
437 #define IF_ROUND_INIT_FE_UPWARD \
438 int save_round_mode = fegetround (); \
439 if (ROUNDING_TESTS (FLOAT, FE_UPWARD) \
440 && !TEST_MATHVEC \
441 && fesetround (FE_UPWARD) == 0)
442 #define ROUND_RESTORE_ /* Empty. */
443 #define ROUND_RESTORE_FE_DOWNWARD \
444 fesetround (save_round_mode)
445 #define ROUND_RESTORE_FE_TONEAREST \
446 fesetround (save_round_mode)
447 #define ROUND_RESTORE_FE_TOWARDZERO \
448 fesetround (save_round_mode)
449 #define ROUND_RESTORE_FE_UPWARD \
450 fesetround (save_round_mode)
451
452 /* Field name to use for a given rounding mode. */
453 #define RM_ rn
454 #define RM_FE_DOWNWARD rd
455 #define RM_FE_TONEAREST rn
456 #define RM_FE_TOWARDZERO rz
457 #define RM_FE_UPWARD ru
458
459 /* Common setup for an individual test. */
460 #define COMMON_TEST_SETUP(ARG_STR) \
461 char *test_name; \
462 if (asprintf (&test_name, "%s (%s)", this_func, (ARG_STR)) == -1) \
463 abort ()
464
465 /* Setup for a test with an extra output. */
466 #define EXTRA_OUTPUT_TEST_SETUP(ARG_STR, N) \
467 char *extra##N##_name; \
468 if (asprintf (&extra##N##_name, "%s (%s) extra output " #N, \
469 this_func, (ARG_STR)) == -1) \
470 abort ()
471
472 /* Common cleanup after an individual test. */
473 #define COMMON_TEST_CLEANUP \
474 free (test_name)
475
476 /* Cleanup for a test with an extra output. */
477 #define EXTRA_OUTPUT_TEST_CLEANUP(N) \
478 free (extra##N##_name)
479
480 /* Run an individual test, including any required setup and checking
481 of results, or loop over all tests in an array. */
482 #define RUN_TEST_1_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
483 EXCEPTIONS) \
484 do \
485 if (enable_test (EXCEPTIONS)) \
486 { \
487 COMMON_TEST_SETUP (ARG_STR); \
488 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
489 EXPECTED, EXCEPTIONS); \
490 COMMON_TEST_CLEANUP; \
491 } \
492 while (0)
493 #define RUN_TEST_LOOP_1_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
494 IF_ROUND_INIT_ ## ROUNDING_MODE \
495 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
496 RUN_TEST_1_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
497 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
498 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
499 ROUND_RESTORE_ ## ROUNDING_MODE
500 #define RUN_TEST_LOOP_f_f RUN_TEST_LOOP_1_f
501 #define RUN_TEST_LOOP_a_f RUN_TEST_LOOP_1_f
502 #define RUN_TEST_fp_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
503 EXCEPTIONS) \
504 do \
505 if (enable_test (EXCEPTIONS)) \
506 { \
507 COMMON_TEST_SETUP (ARG_STR); \
508 check_float (test_name, FUNC_TEST (FUNC_NAME) (&(ARG)), \
509 EXPECTED, EXCEPTIONS); \
510 COMMON_TEST_CLEANUP; \
511 } \
512 while (0)
513 #define RUN_TEST_LOOP_fp_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
514 IF_ROUND_INIT_ ## ROUNDING_MODE \
515 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
516 RUN_TEST_fp_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
517 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
518 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
519 ROUND_RESTORE_ ## ROUNDING_MODE
520 #define RUN_TEST_2_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
521 EXCEPTIONS) \
522 do \
523 if (enable_test (EXCEPTIONS)) \
524 { \
525 COMMON_TEST_SETUP (ARG_STR); \
526 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
527 EXPECTED, EXCEPTIONS); \
528 COMMON_TEST_CLEANUP; \
529 } \
530 while (0)
531 #define RUN_TEST_LOOP_2_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
532 IF_ROUND_INIT_ ## ROUNDING_MODE \
533 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
534 RUN_TEST_2_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
535 (ARRAY)[i].arg2, \
536 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
537 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
538 ROUND_RESTORE_ ## ROUNDING_MODE
539 #define RUN_TEST_ff_f RUN_TEST_2_f
540 #define RUN_TEST_LOOP_ff_f RUN_TEST_LOOP_2_f
541 #define RUN_TEST_LOOP_fj_f RUN_TEST_LOOP_2_f
542 #define RUN_TEST_LOOP_aa_f RUN_TEST_LOOP_2_f
543 #define RUN_TEST_fi_f RUN_TEST_2_f
544 #define RUN_TEST_LOOP_fi_f RUN_TEST_LOOP_2_f
545 #define RUN_TEST_fl_f RUN_TEST_2_f
546 #define RUN_TEST_LOOP_fl_f RUN_TEST_LOOP_2_f
547 #define RUN_TEST_if_f RUN_TEST_2_f
548 #define RUN_TEST_LOOP_if_f RUN_TEST_LOOP_2_f
549 #define RUN_TEST_3_f(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
550 EXPECTED, EXCEPTIONS) \
551 do \
552 if (enable_test (EXCEPTIONS)) \
553 { \
554 COMMON_TEST_SETUP (ARG_STR); \
555 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
556 EXPECTED, EXCEPTIONS); \
557 COMMON_TEST_CLEANUP; \
558 } \
559 while (0)
560 #define RUN_TEST_LOOP_3_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
561 IF_ROUND_INIT_ ## ROUNDING_MODE \
562 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
563 RUN_TEST_3_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
564 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
565 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
566 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
567 ROUND_RESTORE_ ## ROUNDING_MODE
568 #define RUN_TEST_LOOP_fff_f RUN_TEST_LOOP_3_f
569 #define RUN_TEST_LOOP_aaa_f RUN_TEST_LOOP_3_f
570 #define RUN_TEST_fiu_M(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
571 EXPECTED, EXCEPTIONS) \
572 do \
573 if (enable_test (EXCEPTIONS)) \
574 { \
575 COMMON_TEST_SETUP (ARG_STR); \
576 check_intmax_t (test_name, \
577 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
578 EXPECTED, EXCEPTIONS); \
579 COMMON_TEST_CLEANUP; \
580 } \
581 while (0)
582 #define RUN_TEST_LOOP_fiu_M(FUNC_NAME, ARRAY, ROUNDING_MODE) \
583 IF_ROUND_INIT_ ## ROUNDING_MODE \
584 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
585 RUN_TEST_fiu_M ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
586 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
587 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
588 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
589 ROUND_RESTORE_ ## ROUNDING_MODE
590 #define RUN_TEST_fiu_U(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
591 EXPECTED, EXCEPTIONS) \
592 do \
593 if (enable_test (EXCEPTIONS)) \
594 { \
595 COMMON_TEST_SETUP (ARG_STR); \
596 check_uintmax_t (test_name, \
597 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
598 EXPECTED, EXCEPTIONS); \
599 COMMON_TEST_CLEANUP; \
600 } \
601 while (0)
602 #define RUN_TEST_LOOP_fiu_U(FUNC_NAME, ARRAY, ROUNDING_MODE) \
603 IF_ROUND_INIT_ ## ROUNDING_MODE \
604 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
605 RUN_TEST_fiu_U ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
606 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
607 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
608 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
609 ROUND_RESTORE_ ## ROUNDING_MODE
610 #define RUN_TEST_c_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
611 EXCEPTIONS) \
612 do \
613 if (enable_test (EXCEPTIONS)) \
614 { \
615 COMMON_TEST_SETUP (ARG_STR); \
616 check_float (test_name, \
617 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1, ARG2)),\
618 EXPECTED, EXCEPTIONS); \
619 COMMON_TEST_CLEANUP; \
620 } \
621 while (0)
622 #define RUN_TEST_LOOP_c_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
623 IF_ROUND_INIT_ ## ROUNDING_MODE \
624 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
625 RUN_TEST_c_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
626 (ARRAY)[i].argc, \
627 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
628 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
629 ROUND_RESTORE_ ## ROUNDING_MODE
630 #define RUN_TEST_f_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
631 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
632 EXTRA_EXPECTED) \
633 do \
634 if (enable_test (EXCEPTIONS)) \
635 { \
636 COMMON_TEST_SETUP (ARG_STR); \
637 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
638 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
639 EXCEPTIONS); \
640 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
641 if (EXTRA_TEST) \
642 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
643 EXTRA_OUTPUT_TEST_CLEANUP (1); \
644 COMMON_TEST_CLEANUP; \
645 } \
646 while (0)
647 #define RUN_TEST_LOOP_f_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
648 IF_ROUND_INIT_ ## ROUNDING_MODE \
649 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
650 RUN_TEST_f_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
651 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
652 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
653 EXTRA_VAR, \
654 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
655 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
656 ROUND_RESTORE_ ## ROUNDING_MODE
657 #define RUN_TEST_fF_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
658 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
659 EXTRA_EXPECTED) \
660 do \
661 if (enable_test (EXCEPTIONS)) \
662 { \
663 COMMON_TEST_SETUP (ARG_STR); \
664 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
665 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
666 EXPECTED, EXCEPTIONS); \
667 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
668 if (EXTRA_TEST) \
669 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
670 EXTRA_OUTPUT_TEST_CLEANUP (1); \
671 COMMON_TEST_CLEANUP; \
672 } \
673 while (0)
674 #define RUN_TEST_LOOP_fF_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
675 IF_ROUND_INIT_ ## ROUNDING_MODE \
676 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
677 RUN_TEST_fF_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
678 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
679 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
680 EXTRA_VAR, \
681 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
682 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
683 ROUND_RESTORE_ ## ROUNDING_MODE
684 #define RUN_TEST_fI_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
685 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
686 EXTRA_EXPECTED) \
687 do \
688 if (enable_test (EXCEPTIONS)) \
689 { \
690 COMMON_TEST_SETUP (ARG_STR); \
691 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
692 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
693 EXPECTED, EXCEPTIONS); \
694 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
695 if (EXTRA_TEST) \
696 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
697 EXTRA_OUTPUT_TEST_CLEANUP (1); \
698 COMMON_TEST_CLEANUP; \
699 } \
700 while (0)
701 #define RUN_TEST_LOOP_fI_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
702 IF_ROUND_INIT_ ## ROUNDING_MODE \
703 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
704 RUN_TEST_fI_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
705 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
706 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
707 EXTRA_VAR, \
708 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
709 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
710 ROUND_RESTORE_ ## ROUNDING_MODE
711 #define RUN_TEST_ffI_f1_mod8(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
712 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
713 EXTRA_EXPECTED) \
714 do \
715 if (enable_test (EXCEPTIONS)) \
716 { \
717 COMMON_TEST_SETUP (ARG_STR); \
718 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
719 check_float (test_name, \
720 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, &(EXTRA_VAR)), \
721 EXPECTED, EXCEPTIONS); \
722 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
723 if (EXTRA_TEST) \
724 check_int (extra1_name, (EXTRA_VAR) % 8, EXTRA_EXPECTED, 0); \
725 EXTRA_OUTPUT_TEST_CLEANUP (1); \
726 COMMON_TEST_CLEANUP; \
727 } \
728 while (0)
729 #define RUN_TEST_LOOP_ffI_f1_mod8(FUNC_NAME, ARRAY, ROUNDING_MODE, \
730 EXTRA_VAR) \
731 IF_ROUND_INIT_ ## ROUNDING_MODE \
732 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
733 RUN_TEST_ffI_f1_mod8 ((ARRAY)[i].arg_str, FUNC_NAME, \
734 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
735 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
736 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
737 EXTRA_VAR, \
738 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
739 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
740 ROUND_RESTORE_ ## ROUNDING_MODE
741 #define RUN_TEST_Ff_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
742 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
743 EXTRA_EXPECTED) \
744 do \
745 if (enable_test (EXCEPTIONS)) \
746 { \
747 COMMON_TEST_SETUP (ARG_STR); \
748 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
749 /* Clear any exceptions from comparison involving sNaN \
750 EXTRA_EXPECTED. */ \
751 feclearexcept (FE_ALL_EXCEPT); \
752 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
753 (ARG)), \
754 EXPECTED, EXCEPTIONS); \
755 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
756 if (EXTRA_TEST) \
757 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
758 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
759 EXTRA_OUTPUT_TEST_CLEANUP (1); \
760 COMMON_TEST_CLEANUP; \
761 } \
762 while (0)
763 #define RUN_TEST_LOOP_Ff_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
764 EXTRA_VAR) \
765 IF_ROUND_INIT_ ## ROUNDING_MODE \
766 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
767 RUN_TEST_Ff_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
768 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
769 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
770 EXTRA_VAR, \
771 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
772 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
773 ROUND_RESTORE_ ## ROUNDING_MODE
774 #define RUN_TEST_Ffp_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
775 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
776 EXTRA_EXPECTED) \
777 do \
778 if (enable_test (EXCEPTIONS)) \
779 { \
780 COMMON_TEST_SETUP (ARG_STR); \
781 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
782 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
783 &(ARG)), \
784 EXPECTED, EXCEPTIONS); \
785 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
786 if (EXTRA_TEST) \
787 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
788 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
789 EXTRA_OUTPUT_TEST_CLEANUP (1); \
790 COMMON_TEST_CLEANUP; \
791 } \
792 while (0)
793 #define RUN_TEST_LOOP_Ffp_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
794 EXTRA_VAR) \
795 IF_ROUND_INIT_ ## ROUNDING_MODE \
796 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
797 RUN_TEST_Ffp_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
798 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
799 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
800 EXTRA_VAR, \
801 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
802 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
803 ROUND_RESTORE_ ## ROUNDING_MODE
804 #define RUN_TEST_c_c(ARG_STR, FUNC_NAME, ARGR, ARGC, EXPR, EXPC, \
805 EXCEPTIONS) \
806 do \
807 if (enable_test (EXCEPTIONS)) \
808 { \
809 COMMON_TEST_SETUP (ARG_STR); \
810 check_complex (test_name, \
811 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARGR, ARGC)), \
812 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
813 COMMON_TEST_CLEANUP; \
814 } \
815 while (0)
816 #define RUN_TEST_LOOP_c_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
817 IF_ROUND_INIT_ ## ROUNDING_MODE \
818 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
819 RUN_TEST_c_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
820 (ARRAY)[i].argc, \
821 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
822 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
823 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
824 ROUND_RESTORE_ ## ROUNDING_MODE
825 #define RUN_TEST_cc_c(ARG_STR, FUNC_NAME, ARG1R, ARG1C, ARG2R, ARG2C, \
826 EXPR, EXPC, EXCEPTIONS) \
827 do \
828 if (enable_test (EXCEPTIONS)) \
829 { \
830 COMMON_TEST_SETUP (ARG_STR); \
831 check_complex (test_name, \
832 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1R, ARG1C), \
833 BUILD_COMPLEX (ARG2R, ARG2C)), \
834 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
835 COMMON_TEST_CLEANUP; \
836 } \
837 while (0)
838 #define RUN_TEST_LOOP_cc_c(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_cc_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1r, \
842 (ARRAY)[i].arg1c, (ARRAY)[i].arg2r, \
843 (ARRAY)[i].arg2c, \
844 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
845 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
846 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
847 ROUND_RESTORE_ ## ROUNDING_MODE
848 #define RUN_TEST_f_i(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
849 do \
850 if (enable_test (EXCEPTIONS)) \
851 { \
852 COMMON_TEST_SETUP (ARG_STR); \
853 check_int (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
854 EXCEPTIONS); \
855 COMMON_TEST_CLEANUP; \
856 } \
857 while (0)
858 #define RUN_TEST_LOOP_f_i(FUNC_NAME, ARRAY, ROUNDING_MODE) \
859 IF_ROUND_INIT_ ## ROUNDING_MODE \
860 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
861 RUN_TEST_f_i ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
862 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
863 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
864 ROUND_RESTORE_ ## ROUNDING_MODE
865 #define RUN_TEST_f_i_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
866 EXCEPTIONS) \
867 do \
868 if (enable_test (EXCEPTIONS)) \
869 { \
870 COMMON_TEST_SETUP (ARG_STR); \
871 check_int (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
872 COMMON_TEST_CLEANUP; \
873 } \
874 while (0)
875 #define RUN_TEST_LOOP_f_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
876 IF_ROUND_INIT_ ## ROUNDING_MODE \
877 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
878 RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
879 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
880 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
881 ROUND_RESTORE_ ## ROUNDING_MODE
882 #define RUN_TEST_LOOP_j_b_tg_u(FUNC_NAME, ARRAY, ROUNDING_MODE) \
883 IF_ROUND_INIT_ ## ROUNDING_MODE \
884 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
885 RUN_TEST_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, \
886 (FLOAT)(ARRAY)[i].arg.value, \
887 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
888 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
889 ROUND_RESTORE_ ## ROUNDING_MODE
890 #define RUN_TEST_LOOP_j_i_tg_u(FUNC_NAME, ARRAY, ROUNDING_MODE) \
891 IF_ROUND_INIT_ ## ROUNDING_MODE \
892 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
893 RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, \
894 (FLOAT)(ARRAY)[i].arg.value, \
895 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
896 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
897 ROUND_RESTORE_ ## ROUNDING_MODE
898 #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
899 EXCEPTIONS) \
900 do \
901 if (enable_test (EXCEPTIONS)) \
902 { \
903 COMMON_TEST_SETUP (ARG_STR); \
904 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
905 EXPECTED, EXCEPTIONS); \
906 COMMON_TEST_CLEANUP; \
907 } \
908 while (0)
909 #define RUN_TEST_LOOP_ff_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
910 IF_ROUND_INIT_ ## ROUNDING_MODE \
911 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
912 RUN_TEST_ff_b ((ARRAY)[i].arg_str, FUNC_NAME, \
913 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
914 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
915 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
916 ROUND_RESTORE_ ## ROUNDING_MODE
917 #define RUN_TEST_fpfp_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
918 EXCEPTIONS) \
919 do \
920 if (enable_test (EXCEPTIONS)) \
921 { \
922 COMMON_TEST_SETUP (ARG_STR); \
923 check_bool (test_name, \
924 FUNC_TEST (FUNC_NAME) (&(ARG1), &(ARG2)), \
925 EXPECTED, EXCEPTIONS); \
926 COMMON_TEST_CLEANUP; \
927 } \
928 while (0)
929 #define RUN_TEST_LOOP_fpfp_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
930 IF_ROUND_INIT_ ## ROUNDING_MODE \
931 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
932 RUN_TEST_fpfp_b ((ARRAY)[i].arg_str, FUNC_NAME, \
933 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
934 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
935 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
936 ROUND_RESTORE_ ## ROUNDING_MODE
937 #define RUN_TEST_ff_i_tg(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
938 EXCEPTIONS) \
939 do \
940 if (enable_test (EXCEPTIONS)) \
941 { \
942 COMMON_TEST_SETUP (ARG_STR); \
943 check_int (test_name, FUNC_NAME (ARG1, ARG2), EXPECTED, \
944 EXCEPTIONS); \
945 COMMON_TEST_CLEANUP; \
946 } \
947 while (0)
948 #define RUN_TEST_LOOP_ff_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
949 IF_ROUND_INIT_ ## ROUNDING_MODE \
950 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
951 RUN_TEST_ff_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, \
952 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
953 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
954 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
955 ROUND_RESTORE_ ## ROUNDING_MODE
956 #define RUN_TEST_f_b(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
957 do \
958 if (enable_test (EXCEPTIONS)) \
959 { \
960 COMMON_TEST_SETUP (ARG_STR); \
961 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
962 EXCEPTIONS); \
963 COMMON_TEST_CLEANUP; \
964 } \
965 while (0)
966 #define RUN_TEST_LOOP_f_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
967 IF_ROUND_INIT_ ## ROUNDING_MODE \
968 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
969 RUN_TEST_f_b ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
970 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
971 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
972 ROUND_RESTORE_ ## ROUNDING_MODE
973 #define RUN_TEST_f_b_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
974 EXCEPTIONS) \
975 do \
976 if (enable_test (EXCEPTIONS)) \
977 { \
978 COMMON_TEST_SETUP (ARG_STR); \
979 check_bool (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
980 COMMON_TEST_CLEANUP; \
981 } \
982 while (0)
983 #define RUN_TEST_LOOP_f_b_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
984 IF_ROUND_INIT_ ## ROUNDING_MODE \
985 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
986 RUN_TEST_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
987 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
988 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
989 ROUND_RESTORE_ ## ROUNDING_MODE
990 #define RUN_TEST_f_l(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
991 do \
992 if (enable_test (EXCEPTIONS)) \
993 { \
994 COMMON_TEST_SETUP (ARG_STR); \
995 check_long (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
996 EXCEPTIONS); \
997 COMMON_TEST_CLEANUP; \
998 } \
999 while (0)
1000 #define RUN_TEST_LOOP_f_l(FUNC_NAME, ARRAY, ROUNDING_MODE) \
1001 IF_ROUND_INIT_ ## ROUNDING_MODE \
1002 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
1003 RUN_TEST_f_l ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
1004 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
1005 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
1006 ROUND_RESTORE_ ## ROUNDING_MODE
1007 #define RUN_TEST_f_L(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
1008 do \
1009 if (enable_test (EXCEPTIONS)) \
1010 { \
1011 COMMON_TEST_SETUP (ARG_STR); \
1012 check_longlong (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
1013 EXPECTED, EXCEPTIONS); \
1014 COMMON_TEST_CLEANUP; \
1015 } \
1016 while (0)
1017 #define RUN_TEST_LOOP_f_L(FUNC_NAME, ARRAY, ROUNDING_MODE) \
1018 IF_ROUND_INIT_ ## ROUNDING_MODE \
1019 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
1020 RUN_TEST_f_L ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
1021 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
1022 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
1023 ROUND_RESTORE_ ## ROUNDING_MODE
1024 #define RUN_TEST_fFF_11(ARG_STR, FUNC_NAME, ARG, EXCEPTIONS, \
1025 EXTRA1_VAR, EXTRA1_TEST, \
1026 EXTRA1_EXPECTED, EXTRA2_VAR, \
1027 EXTRA2_TEST, EXTRA2_EXPECTED) \
1028 do \
1029 if (enable_test (EXCEPTIONS)) \
1030 { \
1031 COMMON_TEST_SETUP (ARG_STR); \
1032 FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA1_VAR), &(EXTRA2_VAR)); \
1033 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
1034 if (EXTRA1_TEST) \
1035 check_float (extra1_name, EXTRA1_VAR, EXTRA1_EXPECTED, \
1036 EXCEPTIONS); \
1037 EXTRA_OUTPUT_TEST_CLEANUP (1); \
1038 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 2); \
1039 if (EXTRA2_TEST) \
1040 check_float (extra2_name, EXTRA2_VAR, EXTRA2_EXPECTED, 0); \
1041 EXTRA_OUTPUT_TEST_CLEANUP (2); \
1042 COMMON_TEST_CLEANUP; \
1043 } \
1044 while (0)
1045 #define RUN_TEST_LOOP_fFF_11(FUNC_NAME, ARRAY, ROUNDING_MODE, \
1046 EXTRA1_VAR, EXTRA2_VAR) \
1047 IF_ROUND_INIT_ ## ROUNDING_MODE \
1048 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
1049 RUN_TEST_fFF_11 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
1050 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
1051 EXTRA1_VAR, \
1052 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_test, \
1053 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_expected, \
1054 EXTRA2_VAR, \
1055 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_test, \
1056 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \
1057 ROUND_RESTORE_ ## ROUNDING_MODE
1058
1059 #if TEST_MATHVEC
1060 # define TEST_SUFF VEC_SUFF
1061 # define TEST_SUFF_STR
1062 #elif TEST_NARROW
1063 # define TEST_SUFF
1064 # define TEST_SUFF_STR "_" ARG_TYPE_STR
1065 #else
1066 # define TEST_SUFF
1067 # define TEST_SUFF_STR
1068 #endif
1069
1070 #define STR_CONCAT(a, b, c) __STRING (a##b##c)
1071 #define STR_CON3(a, b, c) STR_CONCAT (a, b, c)
1072
1073 #if TEST_NARROW
1074 # define TEST_COND_any_ibm128 (TEST_COND_ibm128 || TEST_COND_arg_ibm128)
1075 #else
1076 # define TEST_COND_any_ibm128 TEST_COND_ibm128
1077 #endif
1078
1079 /* Start and end the tests for a given function. */
1080 #define START(FUN, SUFF, EXACT) \
1081 CHECK_ARCH_EXT; \
1082 const char *this_func \
1083 = STR_CON3 (FUN, SUFF, TEST_SUFF) TEST_SUFF_STR; \
1084 init_max_error (this_func, EXACT, TEST_COND_any_ibm128)
1085 #define END \
1086 print_max_error (this_func)
1087 #define END_COMPLEX \
1088 print_complex_max_error (this_func)
1089
1090 /* Run tests for a given function in all rounding modes. */
1091 #define ALL_RM_TEST(FUNC, EXACT, ARRAY, LOOP_MACRO, END_MACRO, ...) \
1092 do \
1093 { \
1094 do \
1095 { \
1096 START (FUNC,, EXACT); \
1097 LOOP_MACRO (FUNC, ARRAY, , ## __VA_ARGS__); \
1098 END_MACRO; \
1099 } \
1100 while (0); \
1101 do \
1102 { \
1103 START (FUNC, _downward, EXACT); \
1104 LOOP_MACRO (FUNC, ARRAY, FE_DOWNWARD, ## __VA_ARGS__); \
1105 END_MACRO; \
1106 } \
1107 while (0); \
1108 do \
1109 { \
1110 START (FUNC, _towardzero, EXACT); \
1111 LOOP_MACRO (FUNC, ARRAY, FE_TOWARDZERO, ## __VA_ARGS__); \
1112 END_MACRO; \
1113 } \
1114 while (0); \
1115 do \
1116 { \
1117 START (FUNC, _upward, EXACT); \
1118 LOOP_MACRO (FUNC, ARRAY, FE_UPWARD, ## __VA_ARGS__); \
1119 END_MACRO; \
1120 } \
1121 while (0); \
1122 } \
1123 while (0);
1124
1125 /* Short description of program. */
1126 const char doc[] = "Math test suite: " TEST_MSG ;
1127
1128 static void do_test (void);
1129
1130 int
main(int argc,char ** argv)1131 main (int argc, char **argv)
1132 {
1133 libm_test_init (argc, argv);
1134 INIT_ARCH_EXT;
1135 do_test ();
1136 return libm_test_finish ();
1137 }
1138