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 #define STR(x) STRX (x)
32 #define STR_FLOAT STR (FLOAT)
33 #define STR_ARG_FLOAT STR (ARG_FLOAT)
34 #define STR_VEC_LEN STR (VEC_LEN)
36 /* Informal description of the functions being tested. */
38 # define TEST_MSG "testing " STR_FLOAT " (vector length " STR_VEC_LEN ")\n"
40 # define TEST_MSG "testing " STR_FLOAT " (inline functions)\n"
42 # define TEST_MSG "testing " STR_FLOAT " (finite-math-only)\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 \
71 const char qtype_str
[] = "i" TYPE_STR
;
73 const char qtype_str
[] = TYPE_STR
;
76 /* Various constants derived from pi. We must supply them precalculated for
77 accuracy. They are written as a series of postfix operations to keep
78 them concise yet somewhat readable. */
81 #define lit_pi_3_m_4_d LIT (2.356194490192344928846982537459627163)
82 /* pi * 3 / (4 * ln(10)) */
83 #define lit_pi_3_m_4_ln10_m_d LIT (1.023282265381381010614337719073516828)
84 /* pi / (2 * ln(10)) */
85 #define lit_pi_2_ln10_m_d LIT (0.682188176920920673742891812715677885)
86 /* pi / (4 * ln(10)) */
87 #define lit_pi_4_ln10_m_d LIT (0.341094088460460336871445906357838943)
89 #define lit_pi_ln10_d LIT (1.364376353841841347485783625431355770)
91 #define lit_pi_2_d LITM (M_PI_2)
93 #define lit_pi_4_d LITM (M_PI_4)
95 #define lit_pi LITM (M_PI)
97 /* Other useful constants. */
100 #define lit_e LITM (M_E)
102 #define plus_zero LIT (0.0)
103 #define minus_zero LIT (-0.0)
104 #define plus_infty FUNC (__builtin_inf) ()
105 #define minus_infty -(FUNC (__builtin_inf) ())
106 #define qnan_value_pl(S) FUNC (__builtin_nan) (S)
107 #define qnan_value qnan_value_pl ("")
108 #define snan_value_pl(S) FUNC (__builtin_nans) (S)
109 #define snan_value snan_value_pl ("")
110 #define max_value TYPE_MAX
111 #define min_value TYPE_MIN
112 #define min_subnorm_value TYPE_TRUE_MIN
114 #define arg_plus_zero ARG_LIT (0.0)
115 #define arg_minus_zero ARG_LIT (-0.0)
116 #define arg_plus_infty ARG_FUNC (__builtin_inf) ()
117 #define arg_minus_infty -(ARG_FUNC (__builtin_inf) ())
118 #define arg_qnan_value_pl(S) ARG_FUNC (__builtin_nan) (S)
119 #define arg_qnan_value arg_qnan_value_pl ("")
120 #define arg_snan_value_pl(S) ARG_FUNC (__builtin_nans) (S)
121 #define arg_snan_value arg_snan_value_pl ("")
122 #define arg_max_value ARG_TYPE_MAX
123 #define arg_min_value ARG_TYPE_MIN
124 #define arg_min_subnorm_value ARG_TYPE_TRUE_MIN
126 /* For nexttoward tests. */
127 #define snan_value_ld __builtin_nansl ("")
129 /* Structures for each kind of test. */
130 /* Used for both RUN_TEST_LOOP_f_f and RUN_TEST_LOOP_fp_f. */
141 struct test_ff_f_data
151 /* Strictly speaking, a j type argument is one gen-libm-test.pl will not
152 attempt to muck with. For now, it is only used to prevent it from
153 mucking up an explicitly long double argument. */
154 struct test_fj_f_data
166 struct test_aa_f_data
169 ARG_FLOAT arg1
, arg2
;
177 struct test_fi_f_data
188 struct test_fl_f_data
199 struct test_if_f_data
210 struct test_fff_f_data
213 FLOAT arg1
, arg2
, arg3
;
220 struct test_fiu_M_data
232 struct test_fiu_U_data
254 /* Used for both RUN_TEST_LOOP_f_f1 and RUN_TEST_LOOP_fI_f1. */
255 struct test_f_f1_data
267 struct test_fF_f1_data
276 FLOAT extra_expected
;
279 struct test_ffI_f1_data
301 struct test_cc_c_data
304 FLOAT arg1r
, arg1c
, arg2r
, arg2c
;
311 /* Used for all of RUN_TEST_LOOP_f_i, RUN_TEST_LOOP_f_i_tg,
312 RUN_TEST_LOOP_f_b and RUN_TEST_LOOP_f_b_tg. */
323 /* Used for both RUN_TEST_LOOP_ff_b and RUN_TEST_LOOP_ff_i_tg. */
324 struct test_ff_i_data
350 long long int expected
;
354 struct test_fFF_11_data
362 FLOAT extra1_expected
;
364 FLOAT extra2_expected
;
367 /* Used for both RUN_TEST_LOOP_Ff_b1 and RUN_TEST_LOOP_Ffp_b1. */
368 struct test_Ff_b1_data
377 FLOAT extra_expected
;
381 /* Set the rounding mode, or restore the saved value. */
382 #define IF_ROUND_INIT_ /* Empty. */
383 #define IF_ROUND_INIT_FE_DOWNWARD \
384 int save_round_mode = fegetround (); \
385 if (ROUNDING_TESTS (FLOAT, FE_DOWNWARD) \
386 && fesetround (FE_DOWNWARD) == 0)
387 #define IF_ROUND_INIT_FE_TONEAREST \
388 int save_round_mode = fegetround (); \
389 if (ROUNDING_TESTS (FLOAT, FE_TONEAREST) \
390 && fesetround (FE_TONEAREST) == 0)
391 #define IF_ROUND_INIT_FE_TOWARDZERO \
392 int save_round_mode = fegetround (); \
393 if (ROUNDING_TESTS (FLOAT, FE_TOWARDZERO) \
394 && fesetround (FE_TOWARDZERO) == 0)
395 #define IF_ROUND_INIT_FE_UPWARD \
396 int save_round_mode = fegetround (); \
397 if (ROUNDING_TESTS (FLOAT, FE_UPWARD) \
398 && fesetround (FE_UPWARD) == 0)
399 #define ROUND_RESTORE_ /* Empty. */
400 #define ROUND_RESTORE_FE_DOWNWARD \
401 fesetround (save_round_mode)
402 #define ROUND_RESTORE_FE_TONEAREST \
403 fesetround (save_round_mode)
404 #define ROUND_RESTORE_FE_TOWARDZERO \
405 fesetround (save_round_mode)
406 #define ROUND_RESTORE_FE_UPWARD \
407 fesetround (save_round_mode)
409 /* Field name to use for a given rounding mode. */
411 #define RM_FE_DOWNWARD rd
412 #define RM_FE_TONEAREST rn
413 #define RM_FE_TOWARDZERO rz
414 #define RM_FE_UPWARD ru
416 /* Common setup for an individual test. */
417 #define COMMON_TEST_SETUP(ARG_STR) \
419 if (asprintf (&test_name, "%s (%s)", this_func, (ARG_STR)) == -1) \
422 /* Setup for a test with an extra output. */
423 #define EXTRA_OUTPUT_TEST_SETUP(ARG_STR, N) \
424 char *extra##N##_name; \
425 if (asprintf (&extra##N##_name, "%s (%s) extra output " #N, \
426 this_func, (ARG_STR)) == -1) \
429 /* Common cleanup after an individual test. */
430 #define COMMON_TEST_CLEANUP \
433 /* Cleanup for a test with an extra output. */
434 #define EXTRA_OUTPUT_TEST_CLEANUP(N) \
435 free (extra##N##_name)
437 /* Run an individual test, including any required setup and checking
438 of results, or loop over all tests in an array. */
439 #define RUN_TEST_f_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
442 if (enable_test (EXCEPTIONS)) \
444 COMMON_TEST_SETUP (ARG_STR); \
445 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
446 EXPECTED, EXCEPTIONS); \
447 COMMON_TEST_CLEANUP; \
450 #define RUN_TEST_LOOP_f_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
451 IF_ROUND_INIT_ ## ROUNDING_MODE \
452 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
453 RUN_TEST_f_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
454 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
455 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
456 ROUND_RESTORE_ ## ROUNDING_MODE
457 #define RUN_TEST_fp_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
460 if (enable_test (EXCEPTIONS)) \
462 COMMON_TEST_SETUP (ARG_STR); \
463 check_float (test_name, FUNC_TEST (FUNC_NAME) (&(ARG)), \
464 EXPECTED, EXCEPTIONS); \
465 COMMON_TEST_CLEANUP; \
468 #define RUN_TEST_LOOP_fp_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
469 IF_ROUND_INIT_ ## ROUNDING_MODE \
470 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
471 RUN_TEST_fp_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
472 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
473 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
474 ROUND_RESTORE_ ## ROUNDING_MODE
475 #define RUN_TEST_2_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
478 if (enable_test (EXCEPTIONS)) \
480 COMMON_TEST_SETUP (ARG_STR); \
481 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
482 EXPECTED, EXCEPTIONS); \
483 COMMON_TEST_CLEANUP; \
486 #define RUN_TEST_LOOP_2_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
487 IF_ROUND_INIT_ ## ROUNDING_MODE \
488 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
489 RUN_TEST_2_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
491 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
492 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
493 ROUND_RESTORE_ ## ROUNDING_MODE
494 #define RUN_TEST_ff_f RUN_TEST_2_f
495 #define RUN_TEST_LOOP_ff_f RUN_TEST_LOOP_2_f
496 #define RUN_TEST_LOOP_fj_f RUN_TEST_LOOP_2_f
497 #define RUN_TEST_LOOP_aa_f RUN_TEST_LOOP_2_f
498 #define RUN_TEST_fi_f RUN_TEST_2_f
499 #define RUN_TEST_LOOP_fi_f RUN_TEST_LOOP_2_f
500 #define RUN_TEST_fl_f RUN_TEST_2_f
501 #define RUN_TEST_LOOP_fl_f RUN_TEST_LOOP_2_f
502 #define RUN_TEST_if_f RUN_TEST_2_f
503 #define RUN_TEST_LOOP_if_f RUN_TEST_LOOP_2_f
504 #define RUN_TEST_fff_f(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
505 EXPECTED, EXCEPTIONS) \
507 if (enable_test (EXCEPTIONS)) \
509 COMMON_TEST_SETUP (ARG_STR); \
510 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
511 EXPECTED, EXCEPTIONS); \
512 COMMON_TEST_CLEANUP; \
515 #define RUN_TEST_LOOP_fff_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
516 IF_ROUND_INIT_ ## ROUNDING_MODE \
517 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
518 RUN_TEST_fff_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
519 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
520 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
521 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
522 ROUND_RESTORE_ ## ROUNDING_MODE
523 #define RUN_TEST_fiu_M(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
524 EXPECTED, EXCEPTIONS) \
526 if (enable_test (EXCEPTIONS)) \
528 COMMON_TEST_SETUP (ARG_STR); \
529 check_intmax_t (test_name, \
530 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
531 EXPECTED, EXCEPTIONS); \
532 COMMON_TEST_CLEANUP; \
535 #define RUN_TEST_LOOP_fiu_M(FUNC_NAME, ARRAY, ROUNDING_MODE) \
536 IF_ROUND_INIT_ ## ROUNDING_MODE \
537 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
538 RUN_TEST_fiu_M ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
539 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
540 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
541 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
542 ROUND_RESTORE_ ## ROUNDING_MODE
543 #define RUN_TEST_fiu_U(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
544 EXPECTED, EXCEPTIONS) \
546 if (enable_test (EXCEPTIONS)) \
548 COMMON_TEST_SETUP (ARG_STR); \
549 check_uintmax_t (test_name, \
550 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
551 EXPECTED, EXCEPTIONS); \
552 COMMON_TEST_CLEANUP; \
555 #define RUN_TEST_LOOP_fiu_U(FUNC_NAME, ARRAY, ROUNDING_MODE) \
556 IF_ROUND_INIT_ ## ROUNDING_MODE \
557 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
558 RUN_TEST_fiu_U ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
559 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
560 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
561 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
562 ROUND_RESTORE_ ## ROUNDING_MODE
563 #define RUN_TEST_c_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
566 if (enable_test (EXCEPTIONS)) \
568 COMMON_TEST_SETUP (ARG_STR); \
569 check_float (test_name, \
570 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1, ARG2)),\
571 EXPECTED, EXCEPTIONS); \
572 COMMON_TEST_CLEANUP; \
575 #define RUN_TEST_LOOP_c_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
576 IF_ROUND_INIT_ ## ROUNDING_MODE \
577 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
578 RUN_TEST_c_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
580 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
581 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
582 ROUND_RESTORE_ ## ROUNDING_MODE
583 #define RUN_TEST_f_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
584 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
587 if (enable_test (EXCEPTIONS)) \
589 COMMON_TEST_SETUP (ARG_STR); \
590 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
591 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
593 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
595 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
596 EXTRA_OUTPUT_TEST_CLEANUP (1); \
597 COMMON_TEST_CLEANUP; \
600 #define RUN_TEST_LOOP_f_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
601 IF_ROUND_INIT_ ## ROUNDING_MODE \
602 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
603 RUN_TEST_f_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
604 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
605 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
607 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
608 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
609 ROUND_RESTORE_ ## ROUNDING_MODE
610 #define RUN_TEST_fF_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
611 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
614 if (enable_test (EXCEPTIONS)) \
616 COMMON_TEST_SETUP (ARG_STR); \
617 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
618 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
619 EXPECTED, EXCEPTIONS); \
620 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
622 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
623 EXTRA_OUTPUT_TEST_CLEANUP (1); \
624 COMMON_TEST_CLEANUP; \
627 #define RUN_TEST_LOOP_fF_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
628 IF_ROUND_INIT_ ## ROUNDING_MODE \
629 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
630 RUN_TEST_fF_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
631 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
632 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
634 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
635 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
636 ROUND_RESTORE_ ## ROUNDING_MODE
637 #define RUN_TEST_fI_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
638 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
641 if (enable_test (EXCEPTIONS)) \
643 COMMON_TEST_SETUP (ARG_STR); \
644 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
645 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
646 EXPECTED, EXCEPTIONS); \
647 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
649 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
650 EXTRA_OUTPUT_TEST_CLEANUP (1); \
651 COMMON_TEST_CLEANUP; \
654 #define RUN_TEST_LOOP_fI_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
655 IF_ROUND_INIT_ ## ROUNDING_MODE \
656 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
657 RUN_TEST_fI_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
658 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
659 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
661 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
662 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
663 ROUND_RESTORE_ ## ROUNDING_MODE
664 #define RUN_TEST_ffI_f1_mod8(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
665 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
668 if (enable_test (EXCEPTIONS)) \
670 COMMON_TEST_SETUP (ARG_STR); \
671 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
672 check_float (test_name, \
673 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, &(EXTRA_VAR)), \
674 EXPECTED, EXCEPTIONS); \
675 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
677 check_int (extra1_name, (EXTRA_VAR) % 8, EXTRA_EXPECTED, 0); \
678 EXTRA_OUTPUT_TEST_CLEANUP (1); \
679 COMMON_TEST_CLEANUP; \
682 #define RUN_TEST_LOOP_ffI_f1_mod8(FUNC_NAME, ARRAY, ROUNDING_MODE, \
684 IF_ROUND_INIT_ ## ROUNDING_MODE \
685 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
686 RUN_TEST_ffI_f1_mod8 ((ARRAY)[i].arg_str, FUNC_NAME, \
687 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
688 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
689 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
691 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
692 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
693 ROUND_RESTORE_ ## ROUNDING_MODE
694 #define RUN_TEST_Ff_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
695 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
698 if (enable_test (EXCEPTIONS)) \
700 COMMON_TEST_SETUP (ARG_STR); \
701 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
702 /* Clear any exceptions from comparison involving sNaN \
704 feclearexcept (FE_ALL_EXCEPT); \
705 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
707 EXPECTED, EXCEPTIONS); \
708 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
710 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
711 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
712 EXTRA_OUTPUT_TEST_CLEANUP (1); \
713 COMMON_TEST_CLEANUP; \
716 #define RUN_TEST_LOOP_Ff_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
718 IF_ROUND_INIT_ ## ROUNDING_MODE \
719 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
720 RUN_TEST_Ff_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
721 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
722 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
724 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
725 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
726 ROUND_RESTORE_ ## ROUNDING_MODE
727 #define RUN_TEST_Ffp_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
728 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
731 if (enable_test (EXCEPTIONS)) \
733 COMMON_TEST_SETUP (ARG_STR); \
734 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
735 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
737 EXPECTED, EXCEPTIONS); \
738 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
740 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
741 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
742 EXTRA_OUTPUT_TEST_CLEANUP (1); \
743 COMMON_TEST_CLEANUP; \
746 #define RUN_TEST_LOOP_Ffp_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
748 IF_ROUND_INIT_ ## ROUNDING_MODE \
749 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
750 RUN_TEST_Ffp_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
751 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
752 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
754 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
755 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
756 ROUND_RESTORE_ ## ROUNDING_MODE
757 #define RUN_TEST_c_c(ARG_STR, FUNC_NAME, ARGR, ARGC, EXPR, EXPC, \
760 if (enable_test (EXCEPTIONS)) \
762 COMMON_TEST_SETUP (ARG_STR); \
763 check_complex (test_name, \
764 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARGR, ARGC)), \
765 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
766 COMMON_TEST_CLEANUP; \
769 #define RUN_TEST_LOOP_c_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
770 IF_ROUND_INIT_ ## ROUNDING_MODE \
771 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
772 RUN_TEST_c_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
774 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
775 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
776 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
777 ROUND_RESTORE_ ## ROUNDING_MODE
778 #define RUN_TEST_cc_c(ARG_STR, FUNC_NAME, ARG1R, ARG1C, ARG2R, ARG2C, \
779 EXPR, EXPC, EXCEPTIONS) \
781 if (enable_test (EXCEPTIONS)) \
783 COMMON_TEST_SETUP (ARG_STR); \
784 check_complex (test_name, \
785 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1R, ARG1C), \
786 BUILD_COMPLEX (ARG2R, ARG2C)), \
787 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
788 COMMON_TEST_CLEANUP; \
791 #define RUN_TEST_LOOP_cc_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
792 IF_ROUND_INIT_ ## ROUNDING_MODE \
793 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
794 RUN_TEST_cc_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1r, \
795 (ARRAY)[i].arg1c, (ARRAY)[i].arg2r, \
797 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
798 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
799 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
800 ROUND_RESTORE_ ## ROUNDING_MODE
801 #define RUN_TEST_f_i(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
803 if (enable_test (EXCEPTIONS)) \
805 COMMON_TEST_SETUP (ARG_STR); \
806 check_int (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
808 COMMON_TEST_CLEANUP; \
811 #define RUN_TEST_LOOP_f_i(FUNC_NAME, ARRAY, ROUNDING_MODE) \
812 IF_ROUND_INIT_ ## ROUNDING_MODE \
813 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
814 RUN_TEST_f_i ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
815 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
816 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
817 ROUND_RESTORE_ ## ROUNDING_MODE
818 #define RUN_TEST_f_i_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
821 if (enable_test (EXCEPTIONS)) \
823 COMMON_TEST_SETUP (ARG_STR); \
824 check_int (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
825 COMMON_TEST_CLEANUP; \
828 #define RUN_TEST_LOOP_f_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
829 IF_ROUND_INIT_ ## ROUNDING_MODE \
830 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
831 RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
832 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
833 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
834 ROUND_RESTORE_ ## ROUNDING_MODE
835 #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
838 if (enable_test (EXCEPTIONS)) \
840 COMMON_TEST_SETUP (ARG_STR); \
841 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
842 EXPECTED, EXCEPTIONS); \
843 COMMON_TEST_CLEANUP; \
846 #define RUN_TEST_LOOP_ff_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
847 IF_ROUND_INIT_ ## ROUNDING_MODE \
848 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
849 RUN_TEST_ff_b ((ARRAY)[i].arg_str, FUNC_NAME, \
850 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
851 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
852 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
853 ROUND_RESTORE_ ## ROUNDING_MODE
854 #define RUN_TEST_ff_i_tg(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
857 if (enable_test (EXCEPTIONS)) \
859 COMMON_TEST_SETUP (ARG_STR); \
860 check_int (test_name, FUNC_NAME (ARG1, ARG2), EXPECTED, \
862 COMMON_TEST_CLEANUP; \
865 #define RUN_TEST_LOOP_ff_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
866 IF_ROUND_INIT_ ## ROUNDING_MODE \
867 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
868 RUN_TEST_ff_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, \
869 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
870 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
871 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
872 ROUND_RESTORE_ ## ROUNDING_MODE
873 #define RUN_TEST_f_b(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
875 if (enable_test (EXCEPTIONS)) \
877 COMMON_TEST_SETUP (ARG_STR); \
878 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
880 COMMON_TEST_CLEANUP; \
883 #define RUN_TEST_LOOP_f_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
884 IF_ROUND_INIT_ ## ROUNDING_MODE \
885 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
886 RUN_TEST_f_b ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
887 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
888 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
889 ROUND_RESTORE_ ## ROUNDING_MODE
890 #define RUN_TEST_f_b_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
893 if (enable_test (EXCEPTIONS)) \
895 COMMON_TEST_SETUP (ARG_STR); \
896 check_bool (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
897 COMMON_TEST_CLEANUP; \
900 #define RUN_TEST_LOOP_f_b_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
901 IF_ROUND_INIT_ ## ROUNDING_MODE \
902 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
903 RUN_TEST_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
904 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
905 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
906 ROUND_RESTORE_ ## ROUNDING_MODE
907 #define RUN_TEST_f_l(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
909 if (enable_test (EXCEPTIONS)) \
911 COMMON_TEST_SETUP (ARG_STR); \
912 check_long (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
914 COMMON_TEST_CLEANUP; \
917 #define RUN_TEST_LOOP_f_l(FUNC_NAME, ARRAY, ROUNDING_MODE) \
918 IF_ROUND_INIT_ ## ROUNDING_MODE \
919 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
920 RUN_TEST_f_l ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
921 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
922 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
923 ROUND_RESTORE_ ## ROUNDING_MODE
924 #define RUN_TEST_f_L(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
926 if (enable_test (EXCEPTIONS)) \
928 COMMON_TEST_SETUP (ARG_STR); \
929 check_longlong (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
930 EXPECTED, EXCEPTIONS); \
931 COMMON_TEST_CLEANUP; \
934 #define RUN_TEST_LOOP_f_L(FUNC_NAME, ARRAY, ROUNDING_MODE) \
935 IF_ROUND_INIT_ ## ROUNDING_MODE \
936 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
937 RUN_TEST_f_L ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
938 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
939 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
940 ROUND_RESTORE_ ## ROUNDING_MODE
941 #define RUN_TEST_fFF_11(ARG_STR, FUNC_NAME, ARG, EXCEPTIONS, \
942 EXTRA1_VAR, EXTRA1_TEST, \
943 EXTRA1_EXPECTED, EXTRA2_VAR, \
944 EXTRA2_TEST, EXTRA2_EXPECTED) \
946 if (enable_test (EXCEPTIONS)) \
948 COMMON_TEST_SETUP (ARG_STR); \
949 FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA1_VAR), &(EXTRA2_VAR)); \
950 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
952 check_float (extra1_name, EXTRA1_VAR, EXTRA1_EXPECTED, \
954 EXTRA_OUTPUT_TEST_CLEANUP (1); \
955 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 2); \
957 check_float (extra2_name, EXTRA2_VAR, EXTRA2_EXPECTED, 0); \
958 EXTRA_OUTPUT_TEST_CLEANUP (2); \
959 COMMON_TEST_CLEANUP; \
962 #define RUN_TEST_LOOP_fFF_11(FUNC_NAME, ARRAY, ROUNDING_MODE, \
963 EXTRA1_VAR, EXTRA2_VAR) \
964 IF_ROUND_INIT_ ## ROUNDING_MODE \
965 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
966 RUN_TEST_fFF_11 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
967 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
969 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_test, \
970 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_expected, \
972 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_test, \
973 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \
974 ROUND_RESTORE_ ## ROUNDING_MODE
977 # define TEST_SUFF VEC_SUFF
978 # define TEST_SUFF_STR
981 # define TEST_SUFF_STR "_" ARG_TYPE_STR
984 # define TEST_SUFF_STR
987 #define STR_CONCAT(a, b, c) __STRING (a##b##c)
988 #define STR_CON3(a, b, c) STR_CONCAT (a, b, c)
991 # define TEST_COND_any_ibm128 (TEST_COND_ibm128 || TEST_COND_arg_ibm128)
993 # define TEST_COND_any_ibm128 TEST_COND_ibm128
996 /* Start and end the tests for a given function. */
997 #define START(FUN, SUFF, EXACT) \
999 const char *this_func \
1000 = STR_CON3 (FUN, SUFF, TEST_SUFF) TEST_SUFF_STR; \
1001 init_max_error (this_func, EXACT, TEST_COND_any_ibm128)
1003 print_max_error (this_func)
1004 #define END_COMPLEX \
1005 print_complex_max_error (this_func)
1007 /* Run tests for a given function in all rounding modes. */
1008 #define ALL_RM_TEST(FUNC, EXACT, ARRAY, LOOP_MACRO, END_MACRO, ...) \
1013 START (FUNC,, EXACT); \
1014 LOOP_MACRO (FUNC, ARRAY, , ## __VA_ARGS__); \
1020 START (FUNC, _downward, EXACT); \
1021 LOOP_MACRO (FUNC, ARRAY, FE_DOWNWARD, ## __VA_ARGS__); \
1027 START (FUNC, _towardzero, EXACT); \
1028 LOOP_MACRO (FUNC, ARRAY, FE_TOWARDZERO, ## __VA_ARGS__); \
1034 START (FUNC, _upward, EXACT); \
1035 LOOP_MACRO (FUNC, ARRAY, FE_UPWARD, ## __VA_ARGS__); \
1042 /* Short description of program. */
1043 const char doc
[] = "Math test suite: " TEST_MSG
;
1045 static void do_test (void);
1048 main (int argc
, char **argv
)
1050 libm_test_init (argc
, argv
);
1053 return libm_test_finish ();