1 /* Support code for testing libm functions (driver).
2 Copyright (C) 1997-2023 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 <https://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_mathvec
= TEST_MATHVEC
;
29 const int snan_tests_arg
= SNAN_TESTS (ARG_FLOAT
);
31 const int snan_tests_arg
= SNAN_TESTS (FLOAT
);
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)
40 /* Informal description of the functions being tested. */
42 # define TEST_MSG "testing " STR_FLOAT " (vector length " STR_VEC_LEN ")\n"
44 # define TEST_MSG "testing " STR_FLOAT " (argument " STR_ARG_FLOAT ")\n"
46 # define TEST_MSG "testing " STR_FLOAT " (without inline functions)\n"
48 const char test_msg
[] = TEST_MSG
;
50 /* Allow platforms without all rounding modes to test properly,
51 assuming they provide an __FE_UNDEFINED in <bits/fenv.h> which
52 causes fesetround() to return failure. */
54 # define FE_TONEAREST __FE_UNDEFINED
57 # define FE_TOWARDZERO __FE_UNDEFINED
60 # define FE_UPWARD __FE_UNDEFINED
63 # define FE_DOWNWARD __FE_UNDEFINED
66 #define TEST_NAN_PAYLOAD_CANONICALIZE (SNAN_TESTS_PRESERVE_PAYLOAD \
70 const char qtype_str
[] = TYPE_STR
;
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. */
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)
85 #define lit_pi_ln10_d LIT (1.364376353841841347485783625431355770)
87 #define lit_pi_2_d LITM (M_PI_2)
89 #define lit_pi_4_d LITM (M_PI_4)
91 #define lit_pi LITM (M_PI)
93 /* Other useful constants. */
96 #define lit_e LITM (M_E)
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
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
122 /* For nexttoward tests. */
123 #define snan_value_ld __builtin_nansl ("")
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 }}
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
182 struct test_aa_f_data
185 ARG_FLOAT arg1
, arg2
;
192 struct test_aaa_f_data
195 ARG_FLOAT arg1
, arg2
, arg3
;
203 struct test_fi_f_data
214 struct test_fl_f_data
225 struct test_if_f_data
236 struct test_fff_f_data
239 FLOAT arg1
, arg2
, arg3
;
246 struct test_fiu_M_data
258 struct test_fiu_U_data
280 /* Used for both RUN_TEST_LOOP_f_f1 and RUN_TEST_LOOP_fI_f1. */
281 struct test_f_f1_data
293 struct test_fF_f1_data
302 FLOAT extra_expected
;
305 struct test_ffI_f1_data
327 struct test_cc_c_data
330 FLOAT arg1r
, arg1c
, arg2r
, arg2c
;
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. */
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
354 ieee_long_double_shape_type arg
;
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
390 long long int expected
;
394 struct test_fFF_11_data
402 FLOAT extra1_expected
;
404 FLOAT extra2_expected
;
407 /* Used for both RUN_TEST_LOOP_Ff_b1 and RUN_TEST_LOOP_Ffp_b1. */
408 struct test_Ff_b1_data
417 FLOAT extra_expected
;
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) \
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) \
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) \
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)
452 /* Field name to use for a given rounding mode. */
454 #define RM_FE_DOWNWARD rd
455 #define RM_FE_TONEAREST rn
456 #define RM_FE_TOWARDZERO rz
457 #define RM_FE_UPWARD ru
459 /* Common setup for an individual test. */
460 #define COMMON_TEST_SETUP(ARG_STR) \
462 if (asprintf (&test_name, "%s (%s)", this_func, (ARG_STR)) == -1) \
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) \
472 /* Common cleanup after an individual test. */
473 #define COMMON_TEST_CLEANUP \
476 /* Cleanup for a test with an extra output. */
477 #define EXTRA_OUTPUT_TEST_CLEANUP(N) \
478 free (extra##N##_name)
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, \
485 if (enable_test (EXCEPTIONS)) \
487 COMMON_TEST_SETUP (ARG_STR); \
488 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
489 EXPECTED, EXCEPTIONS); \
490 COMMON_TEST_CLEANUP; \
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, \
505 if (enable_test (EXCEPTIONS)) \
507 COMMON_TEST_SETUP (ARG_STR); \
508 check_float (test_name, FUNC_TEST (FUNC_NAME) (&(ARG)), \
509 EXPECTED, EXCEPTIONS); \
510 COMMON_TEST_CLEANUP; \
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, \
523 if (enable_test (EXCEPTIONS)) \
525 COMMON_TEST_SETUP (ARG_STR); \
526 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
527 EXPECTED, EXCEPTIONS); \
528 COMMON_TEST_CLEANUP; \
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, \
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) \
552 if (enable_test (EXCEPTIONS)) \
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; \
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) \
573 if (enable_test (EXCEPTIONS)) \
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; \
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) \
593 if (enable_test (EXCEPTIONS)) \
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; \
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, \
613 if (enable_test (EXCEPTIONS)) \
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; \
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, \
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, \
634 if (enable_test (EXCEPTIONS)) \
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, \
640 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
642 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
643 EXTRA_OUTPUT_TEST_CLEANUP (1); \
644 COMMON_TEST_CLEANUP; \
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, \
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, \
661 if (enable_test (EXCEPTIONS)) \
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); \
669 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
670 EXTRA_OUTPUT_TEST_CLEANUP (1); \
671 COMMON_TEST_CLEANUP; \
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, \
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, \
688 if (enable_test (EXCEPTIONS)) \
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); \
696 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
697 EXTRA_OUTPUT_TEST_CLEANUP (1); \
698 COMMON_TEST_CLEANUP; \
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, \
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, \
715 if (enable_test (EXCEPTIONS)) \
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); \
724 check_int (extra1_name, (EXTRA_VAR) % 8, EXTRA_EXPECTED, 0); \
725 EXTRA_OUTPUT_TEST_CLEANUP (1); \
726 COMMON_TEST_CLEANUP; \
729 #define RUN_TEST_LOOP_ffI_f1_mod8(FUNC_NAME, ARRAY, ROUNDING_MODE, \
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, \
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, \
745 if (enable_test (EXCEPTIONS)) \
747 COMMON_TEST_SETUP (ARG_STR); \
748 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
749 /* Clear any exceptions from comparison involving sNaN \
751 feclearexcept (FE_ALL_EXCEPT); \
752 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
754 EXPECTED, EXCEPTIONS); \
755 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
757 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
758 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
759 EXTRA_OUTPUT_TEST_CLEANUP (1); \
760 COMMON_TEST_CLEANUP; \
763 #define RUN_TEST_LOOP_Ff_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
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, \
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, \
778 if (enable_test (EXCEPTIONS)) \
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), \
784 EXPECTED, EXCEPTIONS); \
785 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
787 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
788 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
789 EXTRA_OUTPUT_TEST_CLEANUP (1); \
790 COMMON_TEST_CLEANUP; \
793 #define RUN_TEST_LOOP_Ffp_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
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, \
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, \
807 if (enable_test (EXCEPTIONS)) \
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; \
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, \
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) \
828 if (enable_test (EXCEPTIONS)) \
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; \
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, \
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) \
850 if (enable_test (EXCEPTIONS)) \
852 COMMON_TEST_SETUP (ARG_STR); \
853 check_int (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
855 COMMON_TEST_CLEANUP; \
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, \
868 if (enable_test (EXCEPTIONS)) \
870 COMMON_TEST_SETUP (ARG_STR); \
871 check_int (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
872 COMMON_TEST_CLEANUP; \
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, \
901 if (enable_test (EXCEPTIONS)) \
903 COMMON_TEST_SETUP (ARG_STR); \
904 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
905 EXPECTED, EXCEPTIONS); \
906 COMMON_TEST_CLEANUP; \
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, \
920 if (enable_test (EXCEPTIONS)) \
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; \
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, \
940 if (enable_test (EXCEPTIONS)) \
942 COMMON_TEST_SETUP (ARG_STR); \
943 check_int (test_name, FUNC_NAME (ARG1, ARG2), EXPECTED, \
945 COMMON_TEST_CLEANUP; \
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) \
958 if (enable_test (EXCEPTIONS)) \
960 COMMON_TEST_SETUP (ARG_STR); \
961 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
963 COMMON_TEST_CLEANUP; \
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, \
976 if (enable_test (EXCEPTIONS)) \
978 COMMON_TEST_SETUP (ARG_STR); \
979 check_bool (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
980 COMMON_TEST_CLEANUP; \
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) \
992 if (enable_test (EXCEPTIONS)) \
994 COMMON_TEST_SETUP (ARG_STR); \
995 check_long (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
997 COMMON_TEST_CLEANUP; \
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) \
1009 if (enable_test (EXCEPTIONS)) \
1011 COMMON_TEST_SETUP (ARG_STR); \
1012 check_longlong (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
1013 EXPECTED, EXCEPTIONS); \
1014 COMMON_TEST_CLEANUP; \
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) \
1029 if (enable_test (EXCEPTIONS)) \
1031 COMMON_TEST_SETUP (ARG_STR); \
1032 FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA1_VAR), &(EXTRA2_VAR)); \
1033 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
1035 check_float (extra1_name, EXTRA1_VAR, EXTRA1_EXPECTED, \
1037 EXTRA_OUTPUT_TEST_CLEANUP (1); \
1038 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 2); \
1040 check_float (extra2_name, EXTRA2_VAR, EXTRA2_EXPECTED, 0); \
1041 EXTRA_OUTPUT_TEST_CLEANUP (2); \
1042 COMMON_TEST_CLEANUP; \
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, \
1052 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_test, \
1053 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_expected, \
1055 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_test, \
1056 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \
1057 ROUND_RESTORE_ ## ROUNDING_MODE
1060 # define TEST_SUFF VEC_SUFF
1061 # define TEST_SUFF_STR
1064 # define TEST_SUFF_STR "_" ARG_TYPE_STR
1067 # define TEST_SUFF_STR
1070 #define STR_CONCAT(a, b, c) __STRING (a##b##c)
1071 #define STR_CON3(a, b, c) STR_CONCAT (a, b, c)
1074 # define TEST_COND_any_ibm128 (TEST_COND_ibm128 || TEST_COND_arg_ibm128)
1076 # define TEST_COND_any_ibm128 TEST_COND_ibm128
1079 /* Start and end the tests for a given function. */
1080 #define START(FUN, SUFF, EXACT) \
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)
1086 print_max_error (this_func)
1087 #define END_COMPLEX \
1088 print_complex_max_error (this_func)
1090 /* Run tests for a given function in all rounding modes. */
1091 #define ALL_RM_TEST(FUNC, EXACT, ARRAY, LOOP_MACRO, END_MACRO, ...) \
1096 START (FUNC,, EXACT); \
1097 LOOP_MACRO (FUNC, ARRAY, , ## __VA_ARGS__); \
1103 START (FUNC, _downward, EXACT); \
1104 LOOP_MACRO (FUNC, ARRAY, FE_DOWNWARD, ## __VA_ARGS__); \
1110 START (FUNC, _towardzero, EXACT); \
1111 LOOP_MACRO (FUNC, ARRAY, FE_TOWARDZERO, ## __VA_ARGS__); \
1117 START (FUNC, _upward, EXACT); \
1118 LOOP_MACRO (FUNC, ARRAY, FE_UPWARD, ## __VA_ARGS__); \
1125 /* Short description of program. */
1126 const char doc
[] = "Math test suite: " TEST_MSG
;
1128 static void do_test (void);
1131 main (int argc
, char **argv
)
1133 libm_test_init (argc
, argv
);
1136 return libm_test_finish ();