1 /* Support code for testing libm functions (driver).
2 Copyright (C) 1997-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include "libm-test-support.h"
21 #include <math-tests-arch.h>
23 /* Flags set by the including file. */
24 const int flag_test_errno
= TEST_ERRNO
;
25 const int flag_test_exceptions
= TEST_EXCEPTIONS
;
26 const int flag_test_finite
= TEST_FINITE
;
27 const int flag_test_inline
= TEST_INLINE
;
28 const int flag_test_mathvec
= TEST_MATHVEC
;
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 RUN_TEST_LOOP_ff_b, RUN_TEST_LOOP_fpfp_b and
330 RUN_TEST_LOOP_ff_i_tg. */
331 struct test_ff_i_data
357 long long int expected
;
361 struct test_fFF_11_data
369 FLOAT extra1_expected
;
371 FLOAT extra2_expected
;
374 /* Used for both RUN_TEST_LOOP_Ff_b1 and RUN_TEST_LOOP_Ffp_b1. */
375 struct test_Ff_b1_data
384 FLOAT extra_expected
;
388 /* Set the rounding mode, or restore the saved value. */
389 #define IF_ROUND_INIT_ /* Empty. */
390 #define IF_ROUND_INIT_FE_DOWNWARD \
391 int save_round_mode = fegetround (); \
392 if (ROUNDING_TESTS (FLOAT, FE_DOWNWARD) \
394 && fesetround (FE_DOWNWARD) == 0)
395 #define IF_ROUND_INIT_FE_TONEAREST \
396 int save_round_mode = fegetround (); \
397 if (ROUNDING_TESTS (FLOAT, FE_TONEAREST) \
398 && fesetround (FE_TONEAREST) == 0)
399 #define IF_ROUND_INIT_FE_TOWARDZERO \
400 int save_round_mode = fegetround (); \
401 if (ROUNDING_TESTS (FLOAT, FE_TOWARDZERO) \
403 && fesetround (FE_TOWARDZERO) == 0)
404 #define IF_ROUND_INIT_FE_UPWARD \
405 int save_round_mode = fegetround (); \
406 if (ROUNDING_TESTS (FLOAT, FE_UPWARD) \
408 && fesetround (FE_UPWARD) == 0)
409 #define ROUND_RESTORE_ /* Empty. */
410 #define ROUND_RESTORE_FE_DOWNWARD \
411 fesetround (save_round_mode)
412 #define ROUND_RESTORE_FE_TONEAREST \
413 fesetround (save_round_mode)
414 #define ROUND_RESTORE_FE_TOWARDZERO \
415 fesetround (save_round_mode)
416 #define ROUND_RESTORE_FE_UPWARD \
417 fesetround (save_round_mode)
419 /* Field name to use for a given rounding mode. */
421 #define RM_FE_DOWNWARD rd
422 #define RM_FE_TONEAREST rn
423 #define RM_FE_TOWARDZERO rz
424 #define RM_FE_UPWARD ru
426 /* Common setup for an individual test. */
427 #define COMMON_TEST_SETUP(ARG_STR) \
429 if (asprintf (&test_name, "%s (%s)", this_func, (ARG_STR)) == -1) \
432 /* Setup for a test with an extra output. */
433 #define EXTRA_OUTPUT_TEST_SETUP(ARG_STR, N) \
434 char *extra##N##_name; \
435 if (asprintf (&extra##N##_name, "%s (%s) extra output " #N, \
436 this_func, (ARG_STR)) == -1) \
439 /* Common cleanup after an individual test. */
440 #define COMMON_TEST_CLEANUP \
443 /* Cleanup for a test with an extra output. */
444 #define EXTRA_OUTPUT_TEST_CLEANUP(N) \
445 free (extra##N##_name)
447 /* Run an individual test, including any required setup and checking
448 of results, or loop over all tests in an array. */
449 #define RUN_TEST_f_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
452 if (enable_test (EXCEPTIONS)) \
454 COMMON_TEST_SETUP (ARG_STR); \
455 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
456 EXPECTED, EXCEPTIONS); \
457 COMMON_TEST_CLEANUP; \
460 #define RUN_TEST_LOOP_f_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
461 IF_ROUND_INIT_ ## ROUNDING_MODE \
462 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
463 RUN_TEST_f_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
464 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
465 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
466 ROUND_RESTORE_ ## ROUNDING_MODE
467 #define RUN_TEST_fp_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
470 if (enable_test (EXCEPTIONS)) \
472 COMMON_TEST_SETUP (ARG_STR); \
473 check_float (test_name, FUNC_TEST (FUNC_NAME) (&(ARG)), \
474 EXPECTED, EXCEPTIONS); \
475 COMMON_TEST_CLEANUP; \
478 #define RUN_TEST_LOOP_fp_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
479 IF_ROUND_INIT_ ## ROUNDING_MODE \
480 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
481 RUN_TEST_fp_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
482 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
483 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
484 ROUND_RESTORE_ ## ROUNDING_MODE
485 #define RUN_TEST_2_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
488 if (enable_test (EXCEPTIONS)) \
490 COMMON_TEST_SETUP (ARG_STR); \
491 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
492 EXPECTED, EXCEPTIONS); \
493 COMMON_TEST_CLEANUP; \
496 #define RUN_TEST_LOOP_2_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
497 IF_ROUND_INIT_ ## ROUNDING_MODE \
498 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
499 RUN_TEST_2_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
501 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
502 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
503 ROUND_RESTORE_ ## ROUNDING_MODE
504 #define RUN_TEST_ff_f RUN_TEST_2_f
505 #define RUN_TEST_LOOP_ff_f RUN_TEST_LOOP_2_f
506 #define RUN_TEST_LOOP_fj_f RUN_TEST_LOOP_2_f
507 #define RUN_TEST_LOOP_aa_f RUN_TEST_LOOP_2_f
508 #define RUN_TEST_fi_f RUN_TEST_2_f
509 #define RUN_TEST_LOOP_fi_f RUN_TEST_LOOP_2_f
510 #define RUN_TEST_fl_f RUN_TEST_2_f
511 #define RUN_TEST_LOOP_fl_f RUN_TEST_LOOP_2_f
512 #define RUN_TEST_if_f RUN_TEST_2_f
513 #define RUN_TEST_LOOP_if_f RUN_TEST_LOOP_2_f
514 #define RUN_TEST_fff_f(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
515 EXPECTED, EXCEPTIONS) \
517 if (enable_test (EXCEPTIONS)) \
519 COMMON_TEST_SETUP (ARG_STR); \
520 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
521 EXPECTED, EXCEPTIONS); \
522 COMMON_TEST_CLEANUP; \
525 #define RUN_TEST_LOOP_fff_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
526 IF_ROUND_INIT_ ## ROUNDING_MODE \
527 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
528 RUN_TEST_fff_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
529 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
530 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
531 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
532 ROUND_RESTORE_ ## ROUNDING_MODE
533 #define RUN_TEST_fiu_M(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
534 EXPECTED, EXCEPTIONS) \
536 if (enable_test (EXCEPTIONS)) \
538 COMMON_TEST_SETUP (ARG_STR); \
539 check_intmax_t (test_name, \
540 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
541 EXPECTED, EXCEPTIONS); \
542 COMMON_TEST_CLEANUP; \
545 #define RUN_TEST_LOOP_fiu_M(FUNC_NAME, ARRAY, ROUNDING_MODE) \
546 IF_ROUND_INIT_ ## ROUNDING_MODE \
547 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
548 RUN_TEST_fiu_M ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
549 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
550 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
551 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
552 ROUND_RESTORE_ ## ROUNDING_MODE
553 #define RUN_TEST_fiu_U(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
554 EXPECTED, EXCEPTIONS) \
556 if (enable_test (EXCEPTIONS)) \
558 COMMON_TEST_SETUP (ARG_STR); \
559 check_uintmax_t (test_name, \
560 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
561 EXPECTED, EXCEPTIONS); \
562 COMMON_TEST_CLEANUP; \
565 #define RUN_TEST_LOOP_fiu_U(FUNC_NAME, ARRAY, ROUNDING_MODE) \
566 IF_ROUND_INIT_ ## ROUNDING_MODE \
567 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
568 RUN_TEST_fiu_U ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
569 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
570 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
571 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
572 ROUND_RESTORE_ ## ROUNDING_MODE
573 #define RUN_TEST_c_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
576 if (enable_test (EXCEPTIONS)) \
578 COMMON_TEST_SETUP (ARG_STR); \
579 check_float (test_name, \
580 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1, ARG2)),\
581 EXPECTED, EXCEPTIONS); \
582 COMMON_TEST_CLEANUP; \
585 #define RUN_TEST_LOOP_c_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
586 IF_ROUND_INIT_ ## ROUNDING_MODE \
587 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
588 RUN_TEST_c_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
590 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
591 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
592 ROUND_RESTORE_ ## ROUNDING_MODE
593 #define RUN_TEST_f_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
594 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
597 if (enable_test (EXCEPTIONS)) \
599 COMMON_TEST_SETUP (ARG_STR); \
600 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
601 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
603 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
605 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
606 EXTRA_OUTPUT_TEST_CLEANUP (1); \
607 COMMON_TEST_CLEANUP; \
610 #define RUN_TEST_LOOP_f_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
611 IF_ROUND_INIT_ ## ROUNDING_MODE \
612 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
613 RUN_TEST_f_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
614 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
615 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
617 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
618 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
619 ROUND_RESTORE_ ## ROUNDING_MODE
620 #define RUN_TEST_fF_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
621 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
624 if (enable_test (EXCEPTIONS)) \
626 COMMON_TEST_SETUP (ARG_STR); \
627 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
628 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
629 EXPECTED, EXCEPTIONS); \
630 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
632 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
633 EXTRA_OUTPUT_TEST_CLEANUP (1); \
634 COMMON_TEST_CLEANUP; \
637 #define RUN_TEST_LOOP_fF_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
638 IF_ROUND_INIT_ ## ROUNDING_MODE \
639 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
640 RUN_TEST_fF_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
641 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
642 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
644 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
645 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
646 ROUND_RESTORE_ ## ROUNDING_MODE
647 #define RUN_TEST_fI_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
648 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
651 if (enable_test (EXCEPTIONS)) \
653 COMMON_TEST_SETUP (ARG_STR); \
654 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
655 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
656 EXPECTED, EXCEPTIONS); \
657 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
659 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
660 EXTRA_OUTPUT_TEST_CLEANUP (1); \
661 COMMON_TEST_CLEANUP; \
664 #define RUN_TEST_LOOP_fI_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
665 IF_ROUND_INIT_ ## ROUNDING_MODE \
666 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
667 RUN_TEST_fI_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
668 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
669 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
671 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
672 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
673 ROUND_RESTORE_ ## ROUNDING_MODE
674 #define RUN_TEST_ffI_f1_mod8(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
675 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
678 if (enable_test (EXCEPTIONS)) \
680 COMMON_TEST_SETUP (ARG_STR); \
681 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
682 check_float (test_name, \
683 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, &(EXTRA_VAR)), \
684 EXPECTED, EXCEPTIONS); \
685 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
687 check_int (extra1_name, (EXTRA_VAR) % 8, EXTRA_EXPECTED, 0); \
688 EXTRA_OUTPUT_TEST_CLEANUP (1); \
689 COMMON_TEST_CLEANUP; \
692 #define RUN_TEST_LOOP_ffI_f1_mod8(FUNC_NAME, ARRAY, ROUNDING_MODE, \
694 IF_ROUND_INIT_ ## ROUNDING_MODE \
695 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
696 RUN_TEST_ffI_f1_mod8 ((ARRAY)[i].arg_str, FUNC_NAME, \
697 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
698 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
699 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
701 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
702 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
703 ROUND_RESTORE_ ## ROUNDING_MODE
704 #define RUN_TEST_Ff_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
705 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
708 if (enable_test (EXCEPTIONS)) \
710 COMMON_TEST_SETUP (ARG_STR); \
711 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
712 /* Clear any exceptions from comparison involving sNaN \
714 feclearexcept (FE_ALL_EXCEPT); \
715 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
717 EXPECTED, EXCEPTIONS); \
718 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
720 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
721 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
722 EXTRA_OUTPUT_TEST_CLEANUP (1); \
723 COMMON_TEST_CLEANUP; \
726 #define RUN_TEST_LOOP_Ff_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
728 IF_ROUND_INIT_ ## ROUNDING_MODE \
729 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
730 RUN_TEST_Ff_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
731 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
732 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
734 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
735 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
736 ROUND_RESTORE_ ## ROUNDING_MODE
737 #define RUN_TEST_Ffp_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
738 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
741 if (enable_test (EXCEPTIONS)) \
743 COMMON_TEST_SETUP (ARG_STR); \
744 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
745 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
747 EXPECTED, EXCEPTIONS); \
748 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
750 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
751 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
752 EXTRA_OUTPUT_TEST_CLEANUP (1); \
753 COMMON_TEST_CLEANUP; \
756 #define RUN_TEST_LOOP_Ffp_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
758 IF_ROUND_INIT_ ## ROUNDING_MODE \
759 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
760 RUN_TEST_Ffp_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
761 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
762 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
764 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
765 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
766 ROUND_RESTORE_ ## ROUNDING_MODE
767 #define RUN_TEST_c_c(ARG_STR, FUNC_NAME, ARGR, ARGC, EXPR, EXPC, \
770 if (enable_test (EXCEPTIONS)) \
772 COMMON_TEST_SETUP (ARG_STR); \
773 check_complex (test_name, \
774 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARGR, ARGC)), \
775 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
776 COMMON_TEST_CLEANUP; \
779 #define RUN_TEST_LOOP_c_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
780 IF_ROUND_INIT_ ## ROUNDING_MODE \
781 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
782 RUN_TEST_c_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
784 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
785 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
786 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
787 ROUND_RESTORE_ ## ROUNDING_MODE
788 #define RUN_TEST_cc_c(ARG_STR, FUNC_NAME, ARG1R, ARG1C, ARG2R, ARG2C, \
789 EXPR, EXPC, EXCEPTIONS) \
791 if (enable_test (EXCEPTIONS)) \
793 COMMON_TEST_SETUP (ARG_STR); \
794 check_complex (test_name, \
795 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1R, ARG1C), \
796 BUILD_COMPLEX (ARG2R, ARG2C)), \
797 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
798 COMMON_TEST_CLEANUP; \
801 #define RUN_TEST_LOOP_cc_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
802 IF_ROUND_INIT_ ## ROUNDING_MODE \
803 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
804 RUN_TEST_cc_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1r, \
805 (ARRAY)[i].arg1c, (ARRAY)[i].arg2r, \
807 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
808 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
809 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
810 ROUND_RESTORE_ ## ROUNDING_MODE
811 #define RUN_TEST_f_i(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
813 if (enable_test (EXCEPTIONS)) \
815 COMMON_TEST_SETUP (ARG_STR); \
816 check_int (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
818 COMMON_TEST_CLEANUP; \
821 #define RUN_TEST_LOOP_f_i(FUNC_NAME, ARRAY, ROUNDING_MODE) \
822 IF_ROUND_INIT_ ## ROUNDING_MODE \
823 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
824 RUN_TEST_f_i ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
825 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
826 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
827 ROUND_RESTORE_ ## ROUNDING_MODE
828 #define RUN_TEST_f_i_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
831 if (enable_test (EXCEPTIONS)) \
833 COMMON_TEST_SETUP (ARG_STR); \
834 check_int (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
835 COMMON_TEST_CLEANUP; \
838 #define RUN_TEST_LOOP_f_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
839 IF_ROUND_INIT_ ## ROUNDING_MODE \
840 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
841 RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
842 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
843 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
844 ROUND_RESTORE_ ## ROUNDING_MODE
845 #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
848 if (enable_test (EXCEPTIONS)) \
850 COMMON_TEST_SETUP (ARG_STR); \
851 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
852 EXPECTED, EXCEPTIONS); \
853 COMMON_TEST_CLEANUP; \
856 #define RUN_TEST_LOOP_ff_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
857 IF_ROUND_INIT_ ## ROUNDING_MODE \
858 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
859 RUN_TEST_ff_b ((ARRAY)[i].arg_str, FUNC_NAME, \
860 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
861 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
862 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
863 ROUND_RESTORE_ ## ROUNDING_MODE
864 #define RUN_TEST_fpfp_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
867 if (enable_test (EXCEPTIONS)) \
869 COMMON_TEST_SETUP (ARG_STR); \
870 check_bool (test_name, \
871 FUNC_TEST (FUNC_NAME) (&(ARG1), &(ARG2)), \
872 EXPECTED, EXCEPTIONS); \
873 COMMON_TEST_CLEANUP; \
876 #define RUN_TEST_LOOP_fpfp_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
877 IF_ROUND_INIT_ ## ROUNDING_MODE \
878 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
879 RUN_TEST_fpfp_b ((ARRAY)[i].arg_str, FUNC_NAME, \
880 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
881 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
882 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
883 ROUND_RESTORE_ ## ROUNDING_MODE
884 #define RUN_TEST_ff_i_tg(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
887 if (enable_test (EXCEPTIONS)) \
889 COMMON_TEST_SETUP (ARG_STR); \
890 check_int (test_name, FUNC_NAME (ARG1, ARG2), EXPECTED, \
892 COMMON_TEST_CLEANUP; \
895 #define RUN_TEST_LOOP_ff_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
896 IF_ROUND_INIT_ ## ROUNDING_MODE \
897 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
898 RUN_TEST_ff_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, \
899 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
900 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
901 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
902 ROUND_RESTORE_ ## ROUNDING_MODE
903 #define RUN_TEST_f_b(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
905 if (enable_test (EXCEPTIONS)) \
907 COMMON_TEST_SETUP (ARG_STR); \
908 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
910 COMMON_TEST_CLEANUP; \
913 #define RUN_TEST_LOOP_f_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
914 IF_ROUND_INIT_ ## ROUNDING_MODE \
915 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
916 RUN_TEST_f_b ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
917 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
918 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
919 ROUND_RESTORE_ ## ROUNDING_MODE
920 #define RUN_TEST_f_b_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
923 if (enable_test (EXCEPTIONS)) \
925 COMMON_TEST_SETUP (ARG_STR); \
926 check_bool (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
927 COMMON_TEST_CLEANUP; \
930 #define RUN_TEST_LOOP_f_b_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
931 IF_ROUND_INIT_ ## ROUNDING_MODE \
932 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
933 RUN_TEST_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
934 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
935 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
936 ROUND_RESTORE_ ## ROUNDING_MODE
937 #define RUN_TEST_f_l(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
939 if (enable_test (EXCEPTIONS)) \
941 COMMON_TEST_SETUP (ARG_STR); \
942 check_long (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
944 COMMON_TEST_CLEANUP; \
947 #define RUN_TEST_LOOP_f_l(FUNC_NAME, ARRAY, ROUNDING_MODE) \
948 IF_ROUND_INIT_ ## ROUNDING_MODE \
949 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
950 RUN_TEST_f_l ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
951 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
952 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
953 ROUND_RESTORE_ ## ROUNDING_MODE
954 #define RUN_TEST_f_L(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
956 if (enable_test (EXCEPTIONS)) \
958 COMMON_TEST_SETUP (ARG_STR); \
959 check_longlong (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
960 EXPECTED, EXCEPTIONS); \
961 COMMON_TEST_CLEANUP; \
964 #define RUN_TEST_LOOP_f_L(FUNC_NAME, ARRAY, ROUNDING_MODE) \
965 IF_ROUND_INIT_ ## ROUNDING_MODE \
966 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
967 RUN_TEST_f_L ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
968 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
969 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
970 ROUND_RESTORE_ ## ROUNDING_MODE
971 #define RUN_TEST_fFF_11(ARG_STR, FUNC_NAME, ARG, EXCEPTIONS, \
972 EXTRA1_VAR, EXTRA1_TEST, \
973 EXTRA1_EXPECTED, EXTRA2_VAR, \
974 EXTRA2_TEST, EXTRA2_EXPECTED) \
976 if (enable_test (EXCEPTIONS)) \
978 COMMON_TEST_SETUP (ARG_STR); \
979 FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA1_VAR), &(EXTRA2_VAR)); \
980 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
982 check_float (extra1_name, EXTRA1_VAR, EXTRA1_EXPECTED, \
984 EXTRA_OUTPUT_TEST_CLEANUP (1); \
985 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 2); \
987 check_float (extra2_name, EXTRA2_VAR, EXTRA2_EXPECTED, 0); \
988 EXTRA_OUTPUT_TEST_CLEANUP (2); \
989 COMMON_TEST_CLEANUP; \
992 #define RUN_TEST_LOOP_fFF_11(FUNC_NAME, ARRAY, ROUNDING_MODE, \
993 EXTRA1_VAR, EXTRA2_VAR) \
994 IF_ROUND_INIT_ ## ROUNDING_MODE \
995 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
996 RUN_TEST_fFF_11 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
997 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
999 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_test, \
1000 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_expected, \
1002 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_test, \
1003 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \
1004 ROUND_RESTORE_ ## ROUNDING_MODE
1007 # define TEST_SUFF VEC_SUFF
1008 # define TEST_SUFF_STR
1011 # define TEST_SUFF_STR "_" ARG_TYPE_STR
1014 # define TEST_SUFF_STR
1017 #define STR_CONCAT(a, b, c) __STRING (a##b##c)
1018 #define STR_CON3(a, b, c) STR_CONCAT (a, b, c)
1021 # define TEST_COND_any_ibm128 (TEST_COND_ibm128 || TEST_COND_arg_ibm128)
1023 # define TEST_COND_any_ibm128 TEST_COND_ibm128
1026 /* Start and end the tests for a given function. */
1027 #define START(FUN, SUFF, EXACT) \
1029 const char *this_func \
1030 = STR_CON3 (FUN, SUFF, TEST_SUFF) TEST_SUFF_STR; \
1031 init_max_error (this_func, EXACT, TEST_COND_any_ibm128)
1033 print_max_error (this_func)
1034 #define END_COMPLEX \
1035 print_complex_max_error (this_func)
1037 /* Run tests for a given function in all rounding modes. */
1038 #define ALL_RM_TEST(FUNC, EXACT, ARRAY, LOOP_MACRO, END_MACRO, ...) \
1043 START (FUNC,, EXACT); \
1044 LOOP_MACRO (FUNC, ARRAY, , ## __VA_ARGS__); \
1050 START (FUNC, _downward, EXACT); \
1051 LOOP_MACRO (FUNC, ARRAY, FE_DOWNWARD, ## __VA_ARGS__); \
1057 START (FUNC, _towardzero, EXACT); \
1058 LOOP_MACRO (FUNC, ARRAY, FE_TOWARDZERO, ## __VA_ARGS__); \
1064 START (FUNC, _upward, EXACT); \
1065 LOOP_MACRO (FUNC, ARRAY, FE_UPWARD, ## __VA_ARGS__); \
1072 /* Short description of program. */
1073 const char doc
[] = "Math test suite: " TEST_MSG
;
1075 static void do_test (void);
1078 main (int argc
, char **argv
)
1080 libm_test_init (argc
, argv
);
1083 return libm_test_finish ();