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.pl 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) \
392 && fesetround (FE_DOWNWARD) == 0)
393 #define IF_ROUND_INIT_FE_TONEAREST \
394 int save_round_mode = fegetround (); \
395 if (ROUNDING_TESTS (FLOAT, FE_TONEAREST) \
396 && fesetround (FE_TONEAREST) == 0)
397 #define IF_ROUND_INIT_FE_TOWARDZERO \
398 int save_round_mode = fegetround (); \
399 if (ROUNDING_TESTS (FLOAT, FE_TOWARDZERO) \
400 && fesetround (FE_TOWARDZERO) == 0)
401 #define IF_ROUND_INIT_FE_UPWARD \
402 int save_round_mode = fegetround (); \
403 if (ROUNDING_TESTS (FLOAT, FE_UPWARD) \
404 && fesetround (FE_UPWARD) == 0)
405 #define ROUND_RESTORE_ /* Empty. */
406 #define ROUND_RESTORE_FE_DOWNWARD \
407 fesetround (save_round_mode)
408 #define ROUND_RESTORE_FE_TONEAREST \
409 fesetround (save_round_mode)
410 #define ROUND_RESTORE_FE_TOWARDZERO \
411 fesetround (save_round_mode)
412 #define ROUND_RESTORE_FE_UPWARD \
413 fesetround (save_round_mode)
415 /* Field name to use for a given rounding mode. */
417 #define RM_FE_DOWNWARD rd
418 #define RM_FE_TONEAREST rn
419 #define RM_FE_TOWARDZERO rz
420 #define RM_FE_UPWARD ru
422 /* Common setup for an individual test. */
423 #define COMMON_TEST_SETUP(ARG_STR) \
425 if (asprintf (&test_name, "%s (%s)", this_func, (ARG_STR)) == -1) \
428 /* Setup for a test with an extra output. */
429 #define EXTRA_OUTPUT_TEST_SETUP(ARG_STR, N) \
430 char *extra##N##_name; \
431 if (asprintf (&extra##N##_name, "%s (%s) extra output " #N, \
432 this_func, (ARG_STR)) == -1) \
435 /* Common cleanup after an individual test. */
436 #define COMMON_TEST_CLEANUP \
439 /* Cleanup for a test with an extra output. */
440 #define EXTRA_OUTPUT_TEST_CLEANUP(N) \
441 free (extra##N##_name)
443 /* Run an individual test, including any required setup and checking
444 of results, or loop over all tests in an array. */
445 #define RUN_TEST_f_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
448 if (enable_test (EXCEPTIONS)) \
450 COMMON_TEST_SETUP (ARG_STR); \
451 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
452 EXPECTED, EXCEPTIONS); \
453 COMMON_TEST_CLEANUP; \
456 #define RUN_TEST_LOOP_f_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
457 IF_ROUND_INIT_ ## ROUNDING_MODE \
458 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
459 RUN_TEST_f_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
460 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
461 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
462 ROUND_RESTORE_ ## ROUNDING_MODE
463 #define RUN_TEST_fp_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
466 if (enable_test (EXCEPTIONS)) \
468 COMMON_TEST_SETUP (ARG_STR); \
469 check_float (test_name, FUNC_TEST (FUNC_NAME) (&(ARG)), \
470 EXPECTED, EXCEPTIONS); \
471 COMMON_TEST_CLEANUP; \
474 #define RUN_TEST_LOOP_fp_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
475 IF_ROUND_INIT_ ## ROUNDING_MODE \
476 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
477 RUN_TEST_fp_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
478 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
479 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
480 ROUND_RESTORE_ ## ROUNDING_MODE
481 #define RUN_TEST_2_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
484 if (enable_test (EXCEPTIONS)) \
486 COMMON_TEST_SETUP (ARG_STR); \
487 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
488 EXPECTED, EXCEPTIONS); \
489 COMMON_TEST_CLEANUP; \
492 #define RUN_TEST_LOOP_2_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
493 IF_ROUND_INIT_ ## ROUNDING_MODE \
494 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
495 RUN_TEST_2_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
497 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
498 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
499 ROUND_RESTORE_ ## ROUNDING_MODE
500 #define RUN_TEST_ff_f RUN_TEST_2_f
501 #define RUN_TEST_LOOP_ff_f RUN_TEST_LOOP_2_f
502 #define RUN_TEST_LOOP_fj_f RUN_TEST_LOOP_2_f
503 #define RUN_TEST_LOOP_aa_f RUN_TEST_LOOP_2_f
504 #define RUN_TEST_fi_f RUN_TEST_2_f
505 #define RUN_TEST_LOOP_fi_f RUN_TEST_LOOP_2_f
506 #define RUN_TEST_fl_f RUN_TEST_2_f
507 #define RUN_TEST_LOOP_fl_f RUN_TEST_LOOP_2_f
508 #define RUN_TEST_if_f RUN_TEST_2_f
509 #define RUN_TEST_LOOP_if_f RUN_TEST_LOOP_2_f
510 #define RUN_TEST_fff_f(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
511 EXPECTED, EXCEPTIONS) \
513 if (enable_test (EXCEPTIONS)) \
515 COMMON_TEST_SETUP (ARG_STR); \
516 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
517 EXPECTED, EXCEPTIONS); \
518 COMMON_TEST_CLEANUP; \
521 #define RUN_TEST_LOOP_fff_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
522 IF_ROUND_INIT_ ## ROUNDING_MODE \
523 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
524 RUN_TEST_fff_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
525 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
526 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
527 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
528 ROUND_RESTORE_ ## ROUNDING_MODE
529 #define RUN_TEST_fiu_M(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
530 EXPECTED, EXCEPTIONS) \
532 if (enable_test (EXCEPTIONS)) \
534 COMMON_TEST_SETUP (ARG_STR); \
535 check_intmax_t (test_name, \
536 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
537 EXPECTED, EXCEPTIONS); \
538 COMMON_TEST_CLEANUP; \
541 #define RUN_TEST_LOOP_fiu_M(FUNC_NAME, ARRAY, ROUNDING_MODE) \
542 IF_ROUND_INIT_ ## ROUNDING_MODE \
543 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
544 RUN_TEST_fiu_M ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
545 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
546 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
547 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
548 ROUND_RESTORE_ ## ROUNDING_MODE
549 #define RUN_TEST_fiu_U(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
550 EXPECTED, EXCEPTIONS) \
552 if (enable_test (EXCEPTIONS)) \
554 COMMON_TEST_SETUP (ARG_STR); \
555 check_uintmax_t (test_name, \
556 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
557 EXPECTED, EXCEPTIONS); \
558 COMMON_TEST_CLEANUP; \
561 #define RUN_TEST_LOOP_fiu_U(FUNC_NAME, ARRAY, ROUNDING_MODE) \
562 IF_ROUND_INIT_ ## ROUNDING_MODE \
563 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
564 RUN_TEST_fiu_U ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
565 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
566 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
567 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
568 ROUND_RESTORE_ ## ROUNDING_MODE
569 #define RUN_TEST_c_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
572 if (enable_test (EXCEPTIONS)) \
574 COMMON_TEST_SETUP (ARG_STR); \
575 check_float (test_name, \
576 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1, ARG2)),\
577 EXPECTED, EXCEPTIONS); \
578 COMMON_TEST_CLEANUP; \
581 #define RUN_TEST_LOOP_c_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
582 IF_ROUND_INIT_ ## ROUNDING_MODE \
583 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
584 RUN_TEST_c_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
586 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
587 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
588 ROUND_RESTORE_ ## ROUNDING_MODE
589 #define RUN_TEST_f_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
590 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
593 if (enable_test (EXCEPTIONS)) \
595 COMMON_TEST_SETUP (ARG_STR); \
596 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
597 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
599 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
601 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
602 EXTRA_OUTPUT_TEST_CLEANUP (1); \
603 COMMON_TEST_CLEANUP; \
606 #define RUN_TEST_LOOP_f_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
607 IF_ROUND_INIT_ ## ROUNDING_MODE \
608 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
609 RUN_TEST_f_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
610 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
611 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
613 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
614 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
615 ROUND_RESTORE_ ## ROUNDING_MODE
616 #define RUN_TEST_fF_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
617 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
620 if (enable_test (EXCEPTIONS)) \
622 COMMON_TEST_SETUP (ARG_STR); \
623 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
624 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
625 EXPECTED, EXCEPTIONS); \
626 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
628 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
629 EXTRA_OUTPUT_TEST_CLEANUP (1); \
630 COMMON_TEST_CLEANUP; \
633 #define RUN_TEST_LOOP_fF_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
634 IF_ROUND_INIT_ ## ROUNDING_MODE \
635 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
636 RUN_TEST_fF_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
637 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
638 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
640 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
641 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
642 ROUND_RESTORE_ ## ROUNDING_MODE
643 #define RUN_TEST_fI_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
644 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
647 if (enable_test (EXCEPTIONS)) \
649 COMMON_TEST_SETUP (ARG_STR); \
650 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
651 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
652 EXPECTED, EXCEPTIONS); \
653 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
655 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
656 EXTRA_OUTPUT_TEST_CLEANUP (1); \
657 COMMON_TEST_CLEANUP; \
660 #define RUN_TEST_LOOP_fI_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
661 IF_ROUND_INIT_ ## ROUNDING_MODE \
662 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
663 RUN_TEST_fI_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
664 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
665 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
667 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
668 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
669 ROUND_RESTORE_ ## ROUNDING_MODE
670 #define RUN_TEST_ffI_f1_mod8(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
671 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
674 if (enable_test (EXCEPTIONS)) \
676 COMMON_TEST_SETUP (ARG_STR); \
677 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
678 check_float (test_name, \
679 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, &(EXTRA_VAR)), \
680 EXPECTED, EXCEPTIONS); \
681 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
683 check_int (extra1_name, (EXTRA_VAR) % 8, EXTRA_EXPECTED, 0); \
684 EXTRA_OUTPUT_TEST_CLEANUP (1); \
685 COMMON_TEST_CLEANUP; \
688 #define RUN_TEST_LOOP_ffI_f1_mod8(FUNC_NAME, ARRAY, ROUNDING_MODE, \
690 IF_ROUND_INIT_ ## ROUNDING_MODE \
691 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
692 RUN_TEST_ffI_f1_mod8 ((ARRAY)[i].arg_str, FUNC_NAME, \
693 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
694 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
695 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
697 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
698 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
699 ROUND_RESTORE_ ## ROUNDING_MODE
700 #define RUN_TEST_Ff_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
701 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
704 if (enable_test (EXCEPTIONS)) \
706 COMMON_TEST_SETUP (ARG_STR); \
707 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
708 /* Clear any exceptions from comparison involving sNaN \
710 feclearexcept (FE_ALL_EXCEPT); \
711 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
713 EXPECTED, EXCEPTIONS); \
714 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
716 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
717 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
718 EXTRA_OUTPUT_TEST_CLEANUP (1); \
719 COMMON_TEST_CLEANUP; \
722 #define RUN_TEST_LOOP_Ff_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
724 IF_ROUND_INIT_ ## ROUNDING_MODE \
725 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
726 RUN_TEST_Ff_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
727 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
728 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
730 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
731 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
732 ROUND_RESTORE_ ## ROUNDING_MODE
733 #define RUN_TEST_Ffp_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
734 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
737 if (enable_test (EXCEPTIONS)) \
739 COMMON_TEST_SETUP (ARG_STR); \
740 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
741 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
743 EXPECTED, EXCEPTIONS); \
744 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
746 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
747 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
748 EXTRA_OUTPUT_TEST_CLEANUP (1); \
749 COMMON_TEST_CLEANUP; \
752 #define RUN_TEST_LOOP_Ffp_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
754 IF_ROUND_INIT_ ## ROUNDING_MODE \
755 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
756 RUN_TEST_Ffp_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
757 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
758 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
760 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
761 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
762 ROUND_RESTORE_ ## ROUNDING_MODE
763 #define RUN_TEST_c_c(ARG_STR, FUNC_NAME, ARGR, ARGC, EXPR, EXPC, \
766 if (enable_test (EXCEPTIONS)) \
768 COMMON_TEST_SETUP (ARG_STR); \
769 check_complex (test_name, \
770 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARGR, ARGC)), \
771 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
772 COMMON_TEST_CLEANUP; \
775 #define RUN_TEST_LOOP_c_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
776 IF_ROUND_INIT_ ## ROUNDING_MODE \
777 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
778 RUN_TEST_c_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
780 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
781 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
782 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
783 ROUND_RESTORE_ ## ROUNDING_MODE
784 #define RUN_TEST_cc_c(ARG_STR, FUNC_NAME, ARG1R, ARG1C, ARG2R, ARG2C, \
785 EXPR, EXPC, EXCEPTIONS) \
787 if (enable_test (EXCEPTIONS)) \
789 COMMON_TEST_SETUP (ARG_STR); \
790 check_complex (test_name, \
791 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1R, ARG1C), \
792 BUILD_COMPLEX (ARG2R, ARG2C)), \
793 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
794 COMMON_TEST_CLEANUP; \
797 #define RUN_TEST_LOOP_cc_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
798 IF_ROUND_INIT_ ## ROUNDING_MODE \
799 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
800 RUN_TEST_cc_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1r, \
801 (ARRAY)[i].arg1c, (ARRAY)[i].arg2r, \
803 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
804 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
805 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
806 ROUND_RESTORE_ ## ROUNDING_MODE
807 #define RUN_TEST_f_i(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
809 if (enable_test (EXCEPTIONS)) \
811 COMMON_TEST_SETUP (ARG_STR); \
812 check_int (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
814 COMMON_TEST_CLEANUP; \
817 #define RUN_TEST_LOOP_f_i(FUNC_NAME, ARRAY, ROUNDING_MODE) \
818 IF_ROUND_INIT_ ## ROUNDING_MODE \
819 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
820 RUN_TEST_f_i ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
821 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
822 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
823 ROUND_RESTORE_ ## ROUNDING_MODE
824 #define RUN_TEST_f_i_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
827 if (enable_test (EXCEPTIONS)) \
829 COMMON_TEST_SETUP (ARG_STR); \
830 check_int (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
831 COMMON_TEST_CLEANUP; \
834 #define RUN_TEST_LOOP_f_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
835 IF_ROUND_INIT_ ## ROUNDING_MODE \
836 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
837 RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
838 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
839 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
840 ROUND_RESTORE_ ## ROUNDING_MODE
841 #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
844 if (enable_test (EXCEPTIONS)) \
846 COMMON_TEST_SETUP (ARG_STR); \
847 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
848 EXPECTED, EXCEPTIONS); \
849 COMMON_TEST_CLEANUP; \
852 #define RUN_TEST_LOOP_ff_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
853 IF_ROUND_INIT_ ## ROUNDING_MODE \
854 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
855 RUN_TEST_ff_b ((ARRAY)[i].arg_str, FUNC_NAME, \
856 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
857 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
858 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
859 ROUND_RESTORE_ ## ROUNDING_MODE
860 #define RUN_TEST_ff_i_tg(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
863 if (enable_test (EXCEPTIONS)) \
865 COMMON_TEST_SETUP (ARG_STR); \
866 check_int (test_name, FUNC_NAME (ARG1, ARG2), EXPECTED, \
868 COMMON_TEST_CLEANUP; \
871 #define RUN_TEST_LOOP_ff_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
872 IF_ROUND_INIT_ ## ROUNDING_MODE \
873 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
874 RUN_TEST_ff_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, \
875 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
876 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
877 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
878 ROUND_RESTORE_ ## ROUNDING_MODE
879 #define RUN_TEST_f_b(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
881 if (enable_test (EXCEPTIONS)) \
883 COMMON_TEST_SETUP (ARG_STR); \
884 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
886 COMMON_TEST_CLEANUP; \
889 #define RUN_TEST_LOOP_f_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
890 IF_ROUND_INIT_ ## ROUNDING_MODE \
891 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
892 RUN_TEST_f_b ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
893 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
894 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
895 ROUND_RESTORE_ ## ROUNDING_MODE
896 #define RUN_TEST_f_b_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
899 if (enable_test (EXCEPTIONS)) \
901 COMMON_TEST_SETUP (ARG_STR); \
902 check_bool (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
903 COMMON_TEST_CLEANUP; \
906 #define RUN_TEST_LOOP_f_b_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
907 IF_ROUND_INIT_ ## ROUNDING_MODE \
908 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
909 RUN_TEST_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
910 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
911 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
912 ROUND_RESTORE_ ## ROUNDING_MODE
913 #define RUN_TEST_f_l(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
915 if (enable_test (EXCEPTIONS)) \
917 COMMON_TEST_SETUP (ARG_STR); \
918 check_long (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
920 COMMON_TEST_CLEANUP; \
923 #define RUN_TEST_LOOP_f_l(FUNC_NAME, ARRAY, ROUNDING_MODE) \
924 IF_ROUND_INIT_ ## ROUNDING_MODE \
925 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
926 RUN_TEST_f_l ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
927 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
928 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
929 ROUND_RESTORE_ ## ROUNDING_MODE
930 #define RUN_TEST_f_L(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
932 if (enable_test (EXCEPTIONS)) \
934 COMMON_TEST_SETUP (ARG_STR); \
935 check_longlong (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
936 EXPECTED, EXCEPTIONS); \
937 COMMON_TEST_CLEANUP; \
940 #define RUN_TEST_LOOP_f_L(FUNC_NAME, ARRAY, ROUNDING_MODE) \
941 IF_ROUND_INIT_ ## ROUNDING_MODE \
942 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
943 RUN_TEST_f_L ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
944 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
945 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
946 ROUND_RESTORE_ ## ROUNDING_MODE
947 #define RUN_TEST_fFF_11(ARG_STR, FUNC_NAME, ARG, EXCEPTIONS, \
948 EXTRA1_VAR, EXTRA1_TEST, \
949 EXTRA1_EXPECTED, EXTRA2_VAR, \
950 EXTRA2_TEST, EXTRA2_EXPECTED) \
952 if (enable_test (EXCEPTIONS)) \
954 COMMON_TEST_SETUP (ARG_STR); \
955 FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA1_VAR), &(EXTRA2_VAR)); \
956 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
958 check_float (extra1_name, EXTRA1_VAR, EXTRA1_EXPECTED, \
960 EXTRA_OUTPUT_TEST_CLEANUP (1); \
961 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 2); \
963 check_float (extra2_name, EXTRA2_VAR, EXTRA2_EXPECTED, 0); \
964 EXTRA_OUTPUT_TEST_CLEANUP (2); \
965 COMMON_TEST_CLEANUP; \
968 #define RUN_TEST_LOOP_fFF_11(FUNC_NAME, ARRAY, ROUNDING_MODE, \
969 EXTRA1_VAR, EXTRA2_VAR) \
970 IF_ROUND_INIT_ ## ROUNDING_MODE \
971 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
972 RUN_TEST_fFF_11 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
973 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
975 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_test, \
976 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_expected, \
978 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_test, \
979 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \
980 ROUND_RESTORE_ ## ROUNDING_MODE
983 # define TEST_SUFF VEC_SUFF
984 # define TEST_SUFF_STR
987 # define TEST_SUFF_STR "_" ARG_TYPE_STR
990 # define TEST_SUFF_STR
993 #define STR_CONCAT(a, b, c) __STRING (a##b##c)
994 #define STR_CON3(a, b, c) STR_CONCAT (a, b, c)
997 # define TEST_COND_any_ibm128 (TEST_COND_ibm128 || TEST_COND_arg_ibm128)
999 # define TEST_COND_any_ibm128 TEST_COND_ibm128
1002 /* Start and end the tests for a given function. */
1003 #define START(FUN, SUFF, EXACT) \
1005 const char *this_func \
1006 = STR_CON3 (FUN, SUFF, TEST_SUFF) TEST_SUFF_STR; \
1007 init_max_error (this_func, EXACT, TEST_COND_any_ibm128)
1009 print_max_error (this_func)
1010 #define END_COMPLEX \
1011 print_complex_max_error (this_func)
1013 /* Run tests for a given function in all rounding modes. */
1014 #define ALL_RM_TEST(FUNC, EXACT, ARRAY, LOOP_MACRO, END_MACRO, ...) \
1019 START (FUNC,, EXACT); \
1020 LOOP_MACRO (FUNC, ARRAY, , ## __VA_ARGS__); \
1026 START (FUNC, _downward, EXACT); \
1027 LOOP_MACRO (FUNC, ARRAY, FE_DOWNWARD, ## __VA_ARGS__); \
1033 START (FUNC, _towardzero, EXACT); \
1034 LOOP_MACRO (FUNC, ARRAY, FE_TOWARDZERO, ## __VA_ARGS__); \
1040 START (FUNC, _upward, EXACT); \
1041 LOOP_MACRO (FUNC, ARRAY, FE_UPWARD, ## __VA_ARGS__); \
1048 /* Short description of program. */
1049 const char doc
[] = "Math test suite: " TEST_MSG
;
1051 static void do_test (void);
1054 main (int argc
, char **argv
)
1056 libm_test_init (argc
, argv
);
1059 return libm_test_finish ();