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
;
31 const int snan_tests_arg
= SNAN_TESTS (ARG_FLOAT
);
33 const int snan_tests_arg
= SNAN_TESTS (FLOAT
);
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. */
44 # define TEST_MSG "testing " STR_FLOAT " (vector length " STR_VEC_LEN ")\n"
46 # define TEST_MSG "testing " STR_FLOAT " (inline functions)\n"
48 # define TEST_MSG "testing " STR_FLOAT " (finite-math-only)\n"
50 # define TEST_MSG "testing " STR_FLOAT " (argument " STR_ARG_FLOAT ")\n"
52 # define TEST_MSG "testing " STR_FLOAT " (without inline functions)\n"
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. */
60 # define FE_TONEAREST __FE_UNDEFINED
63 # define FE_TOWARDZERO __FE_UNDEFINED
66 # define FE_UPWARD __FE_UNDEFINED
69 # define FE_DOWNWARD __FE_UNDEFINED
72 #define TEST_NAN_PAYLOAD_CANONICALIZE (SNAN_TESTS_PRESERVE_PAYLOAD \
77 const char qtype_str
[] = "i" TYPE_STR
;
79 const char qtype_str
[] = TYPE_STR
;
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. */
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)
95 #define lit_pi_ln10_d LIT (1.364376353841841347485783625431355770)
97 #define lit_pi_2_d LITM (M_PI_2)
99 #define lit_pi_4_d LITM (M_PI_4)
101 #define lit_pi LITM (M_PI)
103 /* Other useful constants. */
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. */
147 struct test_ff_f_data
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
172 struct test_aa_f_data
175 ARG_FLOAT arg1
, arg2
;
183 struct test_fi_f_data
194 struct test_fl_f_data
205 struct test_if_f_data
216 struct test_fff_f_data
219 FLOAT arg1
, arg2
, arg3
;
226 struct test_fiu_M_data
238 struct test_fiu_U_data
260 /* Used for both RUN_TEST_LOOP_f_f1 and RUN_TEST_LOOP_fI_f1. */
261 struct test_f_f1_data
273 struct test_fF_f1_data
282 FLOAT extra_expected
;
285 struct test_ffI_f1_data
307 struct test_cc_c_data
310 FLOAT arg1r
, arg1c
, arg2r
, arg2c
;
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. */
329 /* Used for both RUN_TEST_LOOP_ff_b and RUN_TEST_LOOP_ff_i_tg. */
330 struct test_ff_i_data
356 long long int expected
;
360 struct test_fFF_11_data
368 FLOAT extra1_expected
;
370 FLOAT extra2_expected
;
373 /* Used for both RUN_TEST_LOOP_Ff_b1 and RUN_TEST_LOOP_Ffp_b1. */
374 struct test_Ff_b1_data
383 FLOAT extra_expected
;
387 /* Set the rounding mode, or restore the saved value. */
388 #define IF_ROUND_INIT_ /* Empty. */
389 #define IF_ROUND_INIT_FE_DOWNWARD \
390 int save_round_mode = fegetround (); \
391 if (ROUNDING_TESTS (FLOAT, FE_DOWNWARD) \
393 && fesetround (FE_DOWNWARD) == 0)
394 #define IF_ROUND_INIT_FE_TONEAREST \
395 int save_round_mode = fegetround (); \
396 if (ROUNDING_TESTS (FLOAT, FE_TONEAREST) \
397 && fesetround (FE_TONEAREST) == 0)
398 #define IF_ROUND_INIT_FE_TOWARDZERO \
399 int save_round_mode = fegetround (); \
400 if (ROUNDING_TESTS (FLOAT, FE_TOWARDZERO) \
402 && fesetround (FE_TOWARDZERO) == 0)
403 #define IF_ROUND_INIT_FE_UPWARD \
404 int save_round_mode = fegetround (); \
405 if (ROUNDING_TESTS (FLOAT, FE_UPWARD) \
407 && fesetround (FE_UPWARD) == 0)
408 #define ROUND_RESTORE_ /* Empty. */
409 #define ROUND_RESTORE_FE_DOWNWARD \
410 fesetround (save_round_mode)
411 #define ROUND_RESTORE_FE_TONEAREST \
412 fesetround (save_round_mode)
413 #define ROUND_RESTORE_FE_TOWARDZERO \
414 fesetround (save_round_mode)
415 #define ROUND_RESTORE_FE_UPWARD \
416 fesetround (save_round_mode)
418 /* Field name to use for a given rounding mode. */
420 #define RM_FE_DOWNWARD rd
421 #define RM_FE_TONEAREST rn
422 #define RM_FE_TOWARDZERO rz
423 #define RM_FE_UPWARD ru
425 /* Common setup for an individual test. */
426 #define COMMON_TEST_SETUP(ARG_STR) \
428 if (asprintf (&test_name, "%s (%s)", this_func, (ARG_STR)) == -1) \
431 /* Setup for a test with an extra output. */
432 #define EXTRA_OUTPUT_TEST_SETUP(ARG_STR, N) \
433 char *extra##N##_name; \
434 if (asprintf (&extra##N##_name, "%s (%s) extra output " #N, \
435 this_func, (ARG_STR)) == -1) \
438 /* Common cleanup after an individual test. */
439 #define COMMON_TEST_CLEANUP \
442 /* Cleanup for a test with an extra output. */
443 #define EXTRA_OUTPUT_TEST_CLEANUP(N) \
444 free (extra##N##_name)
446 /* Run an individual test, including any required setup and checking
447 of results, or loop over all tests in an array. */
448 #define RUN_TEST_f_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
451 if (enable_test (EXCEPTIONS)) \
453 COMMON_TEST_SETUP (ARG_STR); \
454 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
455 EXPECTED, EXCEPTIONS); \
456 COMMON_TEST_CLEANUP; \
459 #define RUN_TEST_LOOP_f_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
460 IF_ROUND_INIT_ ## ROUNDING_MODE \
461 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
462 RUN_TEST_f_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
463 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
464 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
465 ROUND_RESTORE_ ## ROUNDING_MODE
466 #define RUN_TEST_fp_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
469 if (enable_test (EXCEPTIONS)) \
471 COMMON_TEST_SETUP (ARG_STR); \
472 check_float (test_name, FUNC_TEST (FUNC_NAME) (&(ARG)), \
473 EXPECTED, EXCEPTIONS); \
474 COMMON_TEST_CLEANUP; \
477 #define RUN_TEST_LOOP_fp_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
478 IF_ROUND_INIT_ ## ROUNDING_MODE \
479 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
480 RUN_TEST_fp_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
481 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
482 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
483 ROUND_RESTORE_ ## ROUNDING_MODE
484 #define RUN_TEST_2_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
487 if (enable_test (EXCEPTIONS)) \
489 COMMON_TEST_SETUP (ARG_STR); \
490 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
491 EXPECTED, EXCEPTIONS); \
492 COMMON_TEST_CLEANUP; \
495 #define RUN_TEST_LOOP_2_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
496 IF_ROUND_INIT_ ## ROUNDING_MODE \
497 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
498 RUN_TEST_2_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
500 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
501 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
502 ROUND_RESTORE_ ## ROUNDING_MODE
503 #define RUN_TEST_ff_f RUN_TEST_2_f
504 #define RUN_TEST_LOOP_ff_f RUN_TEST_LOOP_2_f
505 #define RUN_TEST_LOOP_fj_f RUN_TEST_LOOP_2_f
506 #define RUN_TEST_LOOP_aa_f RUN_TEST_LOOP_2_f
507 #define RUN_TEST_fi_f RUN_TEST_2_f
508 #define RUN_TEST_LOOP_fi_f RUN_TEST_LOOP_2_f
509 #define RUN_TEST_fl_f RUN_TEST_2_f
510 #define RUN_TEST_LOOP_fl_f RUN_TEST_LOOP_2_f
511 #define RUN_TEST_if_f RUN_TEST_2_f
512 #define RUN_TEST_LOOP_if_f RUN_TEST_LOOP_2_f
513 #define RUN_TEST_fff_f(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
514 EXPECTED, EXCEPTIONS) \
516 if (enable_test (EXCEPTIONS)) \
518 COMMON_TEST_SETUP (ARG_STR); \
519 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
520 EXPECTED, EXCEPTIONS); \
521 COMMON_TEST_CLEANUP; \
524 #define RUN_TEST_LOOP_fff_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
525 IF_ROUND_INIT_ ## ROUNDING_MODE \
526 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
527 RUN_TEST_fff_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
528 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
529 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
530 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
531 ROUND_RESTORE_ ## ROUNDING_MODE
532 #define RUN_TEST_fiu_M(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
533 EXPECTED, EXCEPTIONS) \
535 if (enable_test (EXCEPTIONS)) \
537 COMMON_TEST_SETUP (ARG_STR); \
538 check_intmax_t (test_name, \
539 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
540 EXPECTED, EXCEPTIONS); \
541 COMMON_TEST_CLEANUP; \
544 #define RUN_TEST_LOOP_fiu_M(FUNC_NAME, ARRAY, ROUNDING_MODE) \
545 IF_ROUND_INIT_ ## ROUNDING_MODE \
546 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
547 RUN_TEST_fiu_M ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
548 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
549 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
550 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
551 ROUND_RESTORE_ ## ROUNDING_MODE
552 #define RUN_TEST_fiu_U(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
553 EXPECTED, EXCEPTIONS) \
555 if (enable_test (EXCEPTIONS)) \
557 COMMON_TEST_SETUP (ARG_STR); \
558 check_uintmax_t (test_name, \
559 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
560 EXPECTED, EXCEPTIONS); \
561 COMMON_TEST_CLEANUP; \
564 #define RUN_TEST_LOOP_fiu_U(FUNC_NAME, ARRAY, ROUNDING_MODE) \
565 IF_ROUND_INIT_ ## ROUNDING_MODE \
566 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
567 RUN_TEST_fiu_U ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
568 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
569 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
570 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
571 ROUND_RESTORE_ ## ROUNDING_MODE
572 #define RUN_TEST_c_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
575 if (enable_test (EXCEPTIONS)) \
577 COMMON_TEST_SETUP (ARG_STR); \
578 check_float (test_name, \
579 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1, ARG2)),\
580 EXPECTED, EXCEPTIONS); \
581 COMMON_TEST_CLEANUP; \
584 #define RUN_TEST_LOOP_c_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
585 IF_ROUND_INIT_ ## ROUNDING_MODE \
586 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
587 RUN_TEST_c_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
589 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
590 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
591 ROUND_RESTORE_ ## ROUNDING_MODE
592 #define RUN_TEST_f_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
593 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
596 if (enable_test (EXCEPTIONS)) \
598 COMMON_TEST_SETUP (ARG_STR); \
599 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
600 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
602 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
604 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
605 EXTRA_OUTPUT_TEST_CLEANUP (1); \
606 COMMON_TEST_CLEANUP; \
609 #define RUN_TEST_LOOP_f_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
610 IF_ROUND_INIT_ ## ROUNDING_MODE \
611 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
612 RUN_TEST_f_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
613 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
614 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
616 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
617 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
618 ROUND_RESTORE_ ## ROUNDING_MODE
619 #define RUN_TEST_fF_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
620 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
623 if (enable_test (EXCEPTIONS)) \
625 COMMON_TEST_SETUP (ARG_STR); \
626 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
627 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
628 EXPECTED, EXCEPTIONS); \
629 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
631 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
632 EXTRA_OUTPUT_TEST_CLEANUP (1); \
633 COMMON_TEST_CLEANUP; \
636 #define RUN_TEST_LOOP_fF_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
637 IF_ROUND_INIT_ ## ROUNDING_MODE \
638 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
639 RUN_TEST_fF_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
640 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
641 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
643 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
644 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
645 ROUND_RESTORE_ ## ROUNDING_MODE
646 #define RUN_TEST_fI_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
647 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
650 if (enable_test (EXCEPTIONS)) \
652 COMMON_TEST_SETUP (ARG_STR); \
653 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
654 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
655 EXPECTED, EXCEPTIONS); \
656 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
658 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
659 EXTRA_OUTPUT_TEST_CLEANUP (1); \
660 COMMON_TEST_CLEANUP; \
663 #define RUN_TEST_LOOP_fI_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
664 IF_ROUND_INIT_ ## ROUNDING_MODE \
665 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
666 RUN_TEST_fI_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
667 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
668 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
670 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
671 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
672 ROUND_RESTORE_ ## ROUNDING_MODE
673 #define RUN_TEST_ffI_f1_mod8(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
674 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
677 if (enable_test (EXCEPTIONS)) \
679 COMMON_TEST_SETUP (ARG_STR); \
680 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
681 check_float (test_name, \
682 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, &(EXTRA_VAR)), \
683 EXPECTED, EXCEPTIONS); \
684 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
686 check_int (extra1_name, (EXTRA_VAR) % 8, EXTRA_EXPECTED, 0); \
687 EXTRA_OUTPUT_TEST_CLEANUP (1); \
688 COMMON_TEST_CLEANUP; \
691 #define RUN_TEST_LOOP_ffI_f1_mod8(FUNC_NAME, ARRAY, ROUNDING_MODE, \
693 IF_ROUND_INIT_ ## ROUNDING_MODE \
694 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
695 RUN_TEST_ffI_f1_mod8 ((ARRAY)[i].arg_str, FUNC_NAME, \
696 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
697 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
698 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
700 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
701 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
702 ROUND_RESTORE_ ## ROUNDING_MODE
703 #define RUN_TEST_Ff_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
704 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
707 if (enable_test (EXCEPTIONS)) \
709 COMMON_TEST_SETUP (ARG_STR); \
710 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
711 /* Clear any exceptions from comparison involving sNaN \
713 feclearexcept (FE_ALL_EXCEPT); \
714 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
716 EXPECTED, EXCEPTIONS); \
717 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
719 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
720 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
721 EXTRA_OUTPUT_TEST_CLEANUP (1); \
722 COMMON_TEST_CLEANUP; \
725 #define RUN_TEST_LOOP_Ff_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
727 IF_ROUND_INIT_ ## ROUNDING_MODE \
728 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
729 RUN_TEST_Ff_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
730 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
731 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
733 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
734 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
735 ROUND_RESTORE_ ## ROUNDING_MODE
736 #define RUN_TEST_Ffp_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
737 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
740 if (enable_test (EXCEPTIONS)) \
742 COMMON_TEST_SETUP (ARG_STR); \
743 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
744 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
746 EXPECTED, EXCEPTIONS); \
747 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
749 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
750 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
751 EXTRA_OUTPUT_TEST_CLEANUP (1); \
752 COMMON_TEST_CLEANUP; \
755 #define RUN_TEST_LOOP_Ffp_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
757 IF_ROUND_INIT_ ## ROUNDING_MODE \
758 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
759 RUN_TEST_Ffp_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
760 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
761 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
763 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
764 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
765 ROUND_RESTORE_ ## ROUNDING_MODE
766 #define RUN_TEST_c_c(ARG_STR, FUNC_NAME, ARGR, ARGC, EXPR, EXPC, \
769 if (enable_test (EXCEPTIONS)) \
771 COMMON_TEST_SETUP (ARG_STR); \
772 check_complex (test_name, \
773 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARGR, ARGC)), \
774 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
775 COMMON_TEST_CLEANUP; \
778 #define RUN_TEST_LOOP_c_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
779 IF_ROUND_INIT_ ## ROUNDING_MODE \
780 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
781 RUN_TEST_c_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
783 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
784 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
785 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
786 ROUND_RESTORE_ ## ROUNDING_MODE
787 #define RUN_TEST_cc_c(ARG_STR, FUNC_NAME, ARG1R, ARG1C, ARG2R, ARG2C, \
788 EXPR, EXPC, EXCEPTIONS) \
790 if (enable_test (EXCEPTIONS)) \
792 COMMON_TEST_SETUP (ARG_STR); \
793 check_complex (test_name, \
794 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1R, ARG1C), \
795 BUILD_COMPLEX (ARG2R, ARG2C)), \
796 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
797 COMMON_TEST_CLEANUP; \
800 #define RUN_TEST_LOOP_cc_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
801 IF_ROUND_INIT_ ## ROUNDING_MODE \
802 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
803 RUN_TEST_cc_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1r, \
804 (ARRAY)[i].arg1c, (ARRAY)[i].arg2r, \
806 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
807 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
808 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
809 ROUND_RESTORE_ ## ROUNDING_MODE
810 #define RUN_TEST_f_i(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
812 if (enable_test (EXCEPTIONS)) \
814 COMMON_TEST_SETUP (ARG_STR); \
815 check_int (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
817 COMMON_TEST_CLEANUP; \
820 #define RUN_TEST_LOOP_f_i(FUNC_NAME, ARRAY, ROUNDING_MODE) \
821 IF_ROUND_INIT_ ## ROUNDING_MODE \
822 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
823 RUN_TEST_f_i ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
824 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
825 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
826 ROUND_RESTORE_ ## ROUNDING_MODE
827 #define RUN_TEST_f_i_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
830 if (enable_test (EXCEPTIONS)) \
832 COMMON_TEST_SETUP (ARG_STR); \
833 check_int (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
834 COMMON_TEST_CLEANUP; \
837 #define RUN_TEST_LOOP_f_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
838 IF_ROUND_INIT_ ## ROUNDING_MODE \
839 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
840 RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
841 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
842 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
843 ROUND_RESTORE_ ## ROUNDING_MODE
844 #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
847 if (enable_test (EXCEPTIONS)) \
849 COMMON_TEST_SETUP (ARG_STR); \
850 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
851 EXPECTED, EXCEPTIONS); \
852 COMMON_TEST_CLEANUP; \
855 #define RUN_TEST_LOOP_ff_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
856 IF_ROUND_INIT_ ## ROUNDING_MODE \
857 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
858 RUN_TEST_ff_b ((ARRAY)[i].arg_str, FUNC_NAME, \
859 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
860 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
861 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
862 ROUND_RESTORE_ ## ROUNDING_MODE
863 #define RUN_TEST_ff_i_tg(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
866 if (enable_test (EXCEPTIONS)) \
868 COMMON_TEST_SETUP (ARG_STR); \
869 check_int (test_name, FUNC_NAME (ARG1, ARG2), EXPECTED, \
871 COMMON_TEST_CLEANUP; \
874 #define RUN_TEST_LOOP_ff_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
875 IF_ROUND_INIT_ ## ROUNDING_MODE \
876 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
877 RUN_TEST_ff_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, \
878 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
879 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
880 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
881 ROUND_RESTORE_ ## ROUNDING_MODE
882 #define RUN_TEST_f_b(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
884 if (enable_test (EXCEPTIONS)) \
886 COMMON_TEST_SETUP (ARG_STR); \
887 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
889 COMMON_TEST_CLEANUP; \
892 #define RUN_TEST_LOOP_f_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
893 IF_ROUND_INIT_ ## ROUNDING_MODE \
894 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
895 RUN_TEST_f_b ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
896 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
897 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
898 ROUND_RESTORE_ ## ROUNDING_MODE
899 #define RUN_TEST_f_b_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
902 if (enable_test (EXCEPTIONS)) \
904 COMMON_TEST_SETUP (ARG_STR); \
905 check_bool (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
906 COMMON_TEST_CLEANUP; \
909 #define RUN_TEST_LOOP_f_b_tg(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_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
913 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
914 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
915 ROUND_RESTORE_ ## ROUNDING_MODE
916 #define RUN_TEST_f_l(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
918 if (enable_test (EXCEPTIONS)) \
920 COMMON_TEST_SETUP (ARG_STR); \
921 check_long (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
923 COMMON_TEST_CLEANUP; \
926 #define RUN_TEST_LOOP_f_l(FUNC_NAME, ARRAY, ROUNDING_MODE) \
927 IF_ROUND_INIT_ ## ROUNDING_MODE \
928 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
929 RUN_TEST_f_l ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
930 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
931 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
932 ROUND_RESTORE_ ## ROUNDING_MODE
933 #define RUN_TEST_f_L(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
935 if (enable_test (EXCEPTIONS)) \
937 COMMON_TEST_SETUP (ARG_STR); \
938 check_longlong (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
939 EXPECTED, EXCEPTIONS); \
940 COMMON_TEST_CLEANUP; \
943 #define RUN_TEST_LOOP_f_L(FUNC_NAME, ARRAY, ROUNDING_MODE) \
944 IF_ROUND_INIT_ ## ROUNDING_MODE \
945 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
946 RUN_TEST_f_L ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
947 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
948 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
949 ROUND_RESTORE_ ## ROUNDING_MODE
950 #define RUN_TEST_fFF_11(ARG_STR, FUNC_NAME, ARG, EXCEPTIONS, \
951 EXTRA1_VAR, EXTRA1_TEST, \
952 EXTRA1_EXPECTED, EXTRA2_VAR, \
953 EXTRA2_TEST, EXTRA2_EXPECTED) \
955 if (enable_test (EXCEPTIONS)) \
957 COMMON_TEST_SETUP (ARG_STR); \
958 FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA1_VAR), &(EXTRA2_VAR)); \
959 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
961 check_float (extra1_name, EXTRA1_VAR, EXTRA1_EXPECTED, \
963 EXTRA_OUTPUT_TEST_CLEANUP (1); \
964 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 2); \
966 check_float (extra2_name, EXTRA2_VAR, EXTRA2_EXPECTED, 0); \
967 EXTRA_OUTPUT_TEST_CLEANUP (2); \
968 COMMON_TEST_CLEANUP; \
971 #define RUN_TEST_LOOP_fFF_11(FUNC_NAME, ARRAY, ROUNDING_MODE, \
972 EXTRA1_VAR, EXTRA2_VAR) \
973 IF_ROUND_INIT_ ## ROUNDING_MODE \
974 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
975 RUN_TEST_fFF_11 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
976 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
978 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_test, \
979 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_expected, \
981 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_test, \
982 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \
983 ROUND_RESTORE_ ## ROUNDING_MODE
986 # define TEST_SUFF VEC_SUFF
987 # define TEST_SUFF_STR
990 # define TEST_SUFF_STR "_" ARG_TYPE_STR
993 # define TEST_SUFF_STR
996 #define STR_CONCAT(a, b, c) __STRING (a##b##c)
997 #define STR_CON3(a, b, c) STR_CONCAT (a, b, c)
1000 # define TEST_COND_any_ibm128 (TEST_COND_ibm128 || TEST_COND_arg_ibm128)
1002 # define TEST_COND_any_ibm128 TEST_COND_ibm128
1005 /* Start and end the tests for a given function. */
1006 #define START(FUN, SUFF, EXACT) \
1008 const char *this_func \
1009 = STR_CON3 (FUN, SUFF, TEST_SUFF) TEST_SUFF_STR; \
1010 init_max_error (this_func, EXACT, TEST_COND_any_ibm128)
1012 print_max_error (this_func)
1013 #define END_COMPLEX \
1014 print_complex_max_error (this_func)
1016 /* Run tests for a given function in all rounding modes. */
1017 #define ALL_RM_TEST(FUNC, EXACT, ARRAY, LOOP_MACRO, END_MACRO, ...) \
1022 START (FUNC,, EXACT); \
1023 LOOP_MACRO (FUNC, ARRAY, , ## __VA_ARGS__); \
1029 START (FUNC, _downward, EXACT); \
1030 LOOP_MACRO (FUNC, ARRAY, FE_DOWNWARD, ## __VA_ARGS__); \
1036 START (FUNC, _towardzero, EXACT); \
1037 LOOP_MACRO (FUNC, ARRAY, FE_TOWARDZERO, ## __VA_ARGS__); \
1043 START (FUNC, _upward, EXACT); \
1044 LOOP_MACRO (FUNC, ARRAY, FE_UPWARD, ## __VA_ARGS__); \
1051 /* Short description of program. */
1052 const char doc
[] = "Math test suite: " TEST_MSG
;
1054 static void do_test (void);
1057 main (int argc
, char **argv
)
1059 libm_test_init (argc
, argv
);
1062 return libm_test_finish ();