1 /* Support code for testing libm functions (driver).
2 Copyright (C) 1997-2017 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_VEC_LEN STR (VEC_LEN)
35 /* Informal description of the functions being tested. */
37 # define TEST_MSG "testing " STR_FLOAT " (vector length " STR_VEC_LEN ")\n"
39 # define TEST_MSG "testing " STR_FLOAT " (inline functions)\n"
41 # define TEST_MSG "testing " STR_FLOAT " (finite-math-only)\n"
43 # define TEST_MSG "testing " STR_FLOAT " (without inline functions)\n"
45 const char test_msg
[] = TEST_MSG
;
47 /* Allow platforms without all rounding modes to test properly,
48 assuming they provide an __FE_UNDEFINED in <bits/fenv.h> which
49 causes fesetround() to return failure. */
51 # define FE_TONEAREST __FE_UNDEFINED
54 # define FE_TOWARDZERO __FE_UNDEFINED
57 # define FE_UPWARD __FE_UNDEFINED
60 # define FE_DOWNWARD __FE_UNDEFINED
63 #define TEST_NAN_PAYLOAD_CANONICALIZE (SNAN_TESTS_PRESERVE_PAYLOAD \
68 const char qtype_str
[] = "i" TYPE_STR
;
70 const char qtype_str
[] = TYPE_STR
;
73 /* Various constants derived from pi. We must supply them precalculated for
74 accuracy. They are written as a series of postfix operations to keep
75 them concise yet somewhat readable. */
78 #define lit_pi_3_m_4_d LIT (2.356194490192344928846982537459627163)
79 /* pi * 3 / (4 * ln(10)) */
80 #define lit_pi_3_m_4_ln10_m_d LIT (1.023282265381381010614337719073516828)
81 /* pi / (2 * ln(10)) */
82 #define lit_pi_2_ln10_m_d LIT (0.682188176920920673742891812715677885)
83 /* pi / (4 * ln(10)) */
84 #define lit_pi_4_ln10_m_d LIT (0.341094088460460336871445906357838943)
86 #define lit_pi_ln10_d LIT (1.364376353841841347485783625431355770)
88 #define lit_pi_2_d LITM (M_PI_2)
90 #define lit_pi_4_d LITM (M_PI_4)
92 #define lit_pi LITM (M_PI)
94 /* Other useful constants. */
97 #define lit_e LITM (M_E)
99 #define plus_zero LIT (0.0)
100 #define minus_zero LIT (-0.0)
101 #define plus_infty FUNC (__builtin_inf) ()
102 #define minus_infty -(FUNC (__builtin_inf) ())
103 #define qnan_value_pl(S) FUNC (__builtin_nan) (S)
104 #define qnan_value qnan_value_pl ("")
105 #define snan_value_pl(S) FUNC (__builtin_nans) (S)
106 #define snan_value snan_value_pl ("")
107 #define max_value TYPE_MAX
108 #define min_value TYPE_MIN
109 #define min_subnorm_value TYPE_TRUE_MIN
111 /* For nexttoward tests. */
112 #define snan_value_ld __builtin_nansl ("")
114 /* Structures for each kind of test. */
115 /* Used for both RUN_TEST_LOOP_f_f and RUN_TEST_LOOP_fp_f. */
126 struct test_ff_f_data
136 /* Strictly speaking, a j type argument is one gen-libm-test.pl will not
137 attempt to muck with. For now, it is only used to prevent it from
138 mucking up an explicitly long double argument. */
139 struct test_fj_f_data
150 struct test_fi_f_data
161 struct test_fl_f_data
172 struct test_if_f_data
183 struct test_fff_f_data
186 FLOAT arg1
, arg2
, arg3
;
193 struct test_fiu_M_data
205 struct test_fiu_U_data
227 /* Used for both RUN_TEST_LOOP_f_f1 and RUN_TEST_LOOP_fI_f1. */
228 struct test_f_f1_data
240 struct test_fF_f1_data
249 FLOAT extra_expected
;
252 struct test_ffI_f1_data
274 struct test_cc_c_data
277 FLOAT arg1r
, arg1c
, arg2r
, arg2c
;
284 /* Used for all of RUN_TEST_LOOP_f_i, RUN_TEST_LOOP_f_i_tg,
285 RUN_TEST_LOOP_f_b and RUN_TEST_LOOP_f_b_tg. */
296 /* Used for both RUN_TEST_LOOP_ff_b and RUN_TEST_LOOP_ff_i_tg. */
297 struct test_ff_i_data
323 long long int expected
;
327 struct test_fFF_11_data
335 FLOAT extra1_expected
;
337 FLOAT extra2_expected
;
340 /* Used for both RUN_TEST_LOOP_Ff_b1 and RUN_TEST_LOOP_Ffp_b1. */
341 struct test_Ff_b1_data
350 FLOAT extra_expected
;
354 /* Set the rounding mode, or restore the saved value. */
355 #define IF_ROUND_INIT_ /* Empty. */
356 #define IF_ROUND_INIT_FE_DOWNWARD \
357 int save_round_mode = fegetround (); \
358 if (ROUNDING_TESTS (FLOAT, FE_DOWNWARD) \
359 && fesetround (FE_DOWNWARD) == 0)
360 #define IF_ROUND_INIT_FE_TONEAREST \
361 int save_round_mode = fegetround (); \
362 if (ROUNDING_TESTS (FLOAT, FE_TONEAREST) \
363 && fesetround (FE_TONEAREST) == 0)
364 #define IF_ROUND_INIT_FE_TOWARDZERO \
365 int save_round_mode = fegetround (); \
366 if (ROUNDING_TESTS (FLOAT, FE_TOWARDZERO) \
367 && fesetround (FE_TOWARDZERO) == 0)
368 #define IF_ROUND_INIT_FE_UPWARD \
369 int save_round_mode = fegetround (); \
370 if (ROUNDING_TESTS (FLOAT, FE_UPWARD) \
371 && fesetround (FE_UPWARD) == 0)
372 #define ROUND_RESTORE_ /* Empty. */
373 #define ROUND_RESTORE_FE_DOWNWARD \
374 fesetround (save_round_mode)
375 #define ROUND_RESTORE_FE_TONEAREST \
376 fesetround (save_round_mode)
377 #define ROUND_RESTORE_FE_TOWARDZERO \
378 fesetround (save_round_mode)
379 #define ROUND_RESTORE_FE_UPWARD \
380 fesetround (save_round_mode)
382 /* Field name to use for a given rounding mode. */
384 #define RM_FE_DOWNWARD rd
385 #define RM_FE_TONEAREST rn
386 #define RM_FE_TOWARDZERO rz
387 #define RM_FE_UPWARD ru
389 /* Common setup for an individual test. */
390 #define COMMON_TEST_SETUP(ARG_STR) \
392 if (asprintf (&test_name, "%s (%s)", this_func, (ARG_STR)) == -1) \
395 /* Setup for a test with an extra output. */
396 #define EXTRA_OUTPUT_TEST_SETUP(ARG_STR, N) \
397 char *extra##N##_name; \
398 if (asprintf (&extra##N##_name, "%s (%s) extra output " #N, \
399 this_func, (ARG_STR)) == -1) \
402 /* Common cleanup after an individual test. */
403 #define COMMON_TEST_CLEANUP \
406 /* Cleanup for a test with an extra output. */
407 #define EXTRA_OUTPUT_TEST_CLEANUP(N) \
408 free (extra##N##_name)
410 /* Run an individual test, including any required setup and checking
411 of results, or loop over all tests in an array. */
412 #define RUN_TEST_f_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
415 if (enable_test (EXCEPTIONS)) \
417 COMMON_TEST_SETUP (ARG_STR); \
418 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
419 EXPECTED, EXCEPTIONS); \
420 COMMON_TEST_CLEANUP; \
423 #define RUN_TEST_LOOP_f_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
424 IF_ROUND_INIT_ ## ROUNDING_MODE \
425 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
426 RUN_TEST_f_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
427 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
428 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
429 ROUND_RESTORE_ ## ROUNDING_MODE
430 #define RUN_TEST_fp_f(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
433 if (enable_test (EXCEPTIONS)) \
435 COMMON_TEST_SETUP (ARG_STR); \
436 check_float (test_name, FUNC_TEST (FUNC_NAME) (&(ARG)), \
437 EXPECTED, EXCEPTIONS); \
438 COMMON_TEST_CLEANUP; \
441 #define RUN_TEST_LOOP_fp_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
442 IF_ROUND_INIT_ ## ROUNDING_MODE \
443 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
444 RUN_TEST_fp_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
445 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
446 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
447 ROUND_RESTORE_ ## ROUNDING_MODE
448 #define RUN_TEST_2_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
451 if (enable_test (EXCEPTIONS)) \
453 COMMON_TEST_SETUP (ARG_STR); \
454 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
455 EXPECTED, EXCEPTIONS); \
456 COMMON_TEST_CLEANUP; \
459 #define RUN_TEST_LOOP_2_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
460 IF_ROUND_INIT_ ## ROUNDING_MODE \
461 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
462 RUN_TEST_2_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
464 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
465 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
466 ROUND_RESTORE_ ## ROUNDING_MODE
467 #define RUN_TEST_ff_f RUN_TEST_2_f
468 #define RUN_TEST_LOOP_ff_f RUN_TEST_LOOP_2_f
469 #define RUN_TEST_LOOP_fj_f RUN_TEST_LOOP_2_f
470 #define RUN_TEST_fi_f RUN_TEST_2_f
471 #define RUN_TEST_LOOP_fi_f RUN_TEST_LOOP_2_f
472 #define RUN_TEST_fl_f RUN_TEST_2_f
473 #define RUN_TEST_LOOP_fl_f RUN_TEST_LOOP_2_f
474 #define RUN_TEST_if_f RUN_TEST_2_f
475 #define RUN_TEST_LOOP_if_f RUN_TEST_LOOP_2_f
476 #define RUN_TEST_fff_f(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
477 EXPECTED, EXCEPTIONS) \
479 if (enable_test (EXCEPTIONS)) \
481 COMMON_TEST_SETUP (ARG_STR); \
482 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
483 EXPECTED, EXCEPTIONS); \
484 COMMON_TEST_CLEANUP; \
487 #define RUN_TEST_LOOP_fff_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
488 IF_ROUND_INIT_ ## ROUNDING_MODE \
489 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
490 RUN_TEST_fff_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
491 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
492 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
493 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
494 ROUND_RESTORE_ ## ROUNDING_MODE
495 #define RUN_TEST_fiu_M(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
496 EXPECTED, EXCEPTIONS) \
498 if (enable_test (EXCEPTIONS)) \
500 COMMON_TEST_SETUP (ARG_STR); \
501 check_intmax_t (test_name, \
502 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
503 EXPECTED, EXCEPTIONS); \
504 COMMON_TEST_CLEANUP; \
507 #define RUN_TEST_LOOP_fiu_M(FUNC_NAME, ARRAY, ROUNDING_MODE) \
508 IF_ROUND_INIT_ ## ROUNDING_MODE \
509 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
510 RUN_TEST_fiu_M ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
511 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
512 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
513 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
514 ROUND_RESTORE_ ## ROUNDING_MODE
515 #define RUN_TEST_fiu_U(ARG_STR, FUNC_NAME, ARG1, ARG2, ARG3, \
516 EXPECTED, EXCEPTIONS) \
518 if (enable_test (EXCEPTIONS)) \
520 COMMON_TEST_SETUP (ARG_STR); \
521 check_uintmax_t (test_name, \
522 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, ARG3), \
523 EXPECTED, EXCEPTIONS); \
524 COMMON_TEST_CLEANUP; \
527 #define RUN_TEST_LOOP_fiu_U(FUNC_NAME, ARRAY, ROUNDING_MODE) \
528 IF_ROUND_INIT_ ## ROUNDING_MODE \
529 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
530 RUN_TEST_fiu_U ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1, \
531 (ARRAY)[i].arg2, (ARRAY)[i].arg3, \
532 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
533 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
534 ROUND_RESTORE_ ## ROUNDING_MODE
535 #define RUN_TEST_c_f(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
538 if (enable_test (EXCEPTIONS)) \
540 COMMON_TEST_SETUP (ARG_STR); \
541 check_float (test_name, \
542 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1, ARG2)),\
543 EXPECTED, EXCEPTIONS); \
544 COMMON_TEST_CLEANUP; \
547 #define RUN_TEST_LOOP_c_f(FUNC_NAME, ARRAY, ROUNDING_MODE) \
548 IF_ROUND_INIT_ ## ROUNDING_MODE \
549 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
550 RUN_TEST_c_f ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
552 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
553 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
554 ROUND_RESTORE_ ## ROUNDING_MODE
555 #define RUN_TEST_f_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
556 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
559 if (enable_test (EXCEPTIONS)) \
561 COMMON_TEST_SETUP (ARG_STR); \
562 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
563 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
565 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
567 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
568 EXTRA_OUTPUT_TEST_CLEANUP (1); \
569 COMMON_TEST_CLEANUP; \
572 #define RUN_TEST_LOOP_f_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
573 IF_ROUND_INIT_ ## ROUNDING_MODE \
574 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
575 RUN_TEST_f_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
576 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
577 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
579 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
580 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
581 ROUND_RESTORE_ ## ROUNDING_MODE
582 #define RUN_TEST_fF_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
583 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
586 if (enable_test (EXCEPTIONS)) \
588 COMMON_TEST_SETUP (ARG_STR); \
589 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
590 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
591 EXPECTED, EXCEPTIONS); \
592 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
594 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
595 EXTRA_OUTPUT_TEST_CLEANUP (1); \
596 COMMON_TEST_CLEANUP; \
599 #define RUN_TEST_LOOP_fF_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
600 IF_ROUND_INIT_ ## ROUNDING_MODE \
601 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
602 RUN_TEST_fF_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
603 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
604 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
606 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
607 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
608 ROUND_RESTORE_ ## ROUNDING_MODE
609 #define RUN_TEST_fI_f1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
610 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
613 if (enable_test (EXCEPTIONS)) \
615 COMMON_TEST_SETUP (ARG_STR); \
616 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
617 check_float (test_name, FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA_VAR)), \
618 EXPECTED, EXCEPTIONS); \
619 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
621 check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \
622 EXTRA_OUTPUT_TEST_CLEANUP (1); \
623 COMMON_TEST_CLEANUP; \
626 #define RUN_TEST_LOOP_fI_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, EXTRA_VAR) \
627 IF_ROUND_INIT_ ## ROUNDING_MODE \
628 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
629 RUN_TEST_fI_f1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
630 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
631 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
633 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
634 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
635 ROUND_RESTORE_ ## ROUNDING_MODE
636 #define RUN_TEST_ffI_f1_mod8(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
637 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
640 if (enable_test (EXCEPTIONS)) \
642 COMMON_TEST_SETUP (ARG_STR); \
643 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
644 check_float (test_name, \
645 FUNC_TEST (FUNC_NAME) (ARG1, ARG2, &(EXTRA_VAR)), \
646 EXPECTED, EXCEPTIONS); \
647 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
649 check_int (extra1_name, (EXTRA_VAR) % 8, EXTRA_EXPECTED, 0); \
650 EXTRA_OUTPUT_TEST_CLEANUP (1); \
651 COMMON_TEST_CLEANUP; \
654 #define RUN_TEST_LOOP_ffI_f1_mod8(FUNC_NAME, ARRAY, ROUNDING_MODE, \
656 IF_ROUND_INIT_ ## ROUNDING_MODE \
657 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
658 RUN_TEST_ffI_f1_mod8 ((ARRAY)[i].arg_str, FUNC_NAME, \
659 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
660 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
661 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
663 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
664 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
665 ROUND_RESTORE_ ## ROUNDING_MODE
666 #define RUN_TEST_Ff_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
667 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
670 if (enable_test (EXCEPTIONS)) \
672 COMMON_TEST_SETUP (ARG_STR); \
673 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
674 /* Clear any exceptions from comparison involving sNaN \
676 feclearexcept (FE_ALL_EXCEPT); \
677 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
679 EXPECTED, EXCEPTIONS); \
680 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
682 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
683 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
684 EXTRA_OUTPUT_TEST_CLEANUP (1); \
685 COMMON_TEST_CLEANUP; \
688 #define RUN_TEST_LOOP_Ff_b1(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_Ff_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
693 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
694 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
696 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
697 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
698 ROUND_RESTORE_ ## ROUNDING_MODE
699 #define RUN_TEST_Ffp_b1(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
700 EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \
703 if (enable_test (EXCEPTIONS)) \
705 COMMON_TEST_SETUP (ARG_STR); \
706 (EXTRA_VAR) = (EXTRA_EXPECTED) == 0 ? 1 : 0; \
707 check_bool (test_name, FUNC_TEST (FUNC_NAME) (&(EXTRA_VAR), \
709 EXPECTED, EXCEPTIONS); \
710 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
712 check_float (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, \
713 (EXCEPTIONS) & TEST_NAN_PAYLOAD); \
714 EXTRA_OUTPUT_TEST_CLEANUP (1); \
715 COMMON_TEST_CLEANUP; \
718 #define RUN_TEST_LOOP_Ffp_b1(FUNC_NAME, ARRAY, ROUNDING_MODE, \
720 IF_ROUND_INIT_ ## ROUNDING_MODE \
721 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
722 RUN_TEST_Ffp_b1 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
723 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
724 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
726 (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \
727 (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \
728 ROUND_RESTORE_ ## ROUNDING_MODE
729 #define RUN_TEST_c_c(ARG_STR, FUNC_NAME, ARGR, ARGC, EXPR, EXPC, \
732 if (enable_test (EXCEPTIONS)) \
734 COMMON_TEST_SETUP (ARG_STR); \
735 check_complex (test_name, \
736 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARGR, ARGC)), \
737 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
738 COMMON_TEST_CLEANUP; \
741 #define RUN_TEST_LOOP_c_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
742 IF_ROUND_INIT_ ## ROUNDING_MODE \
743 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
744 RUN_TEST_c_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].argr, \
746 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
747 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
748 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
749 ROUND_RESTORE_ ## ROUNDING_MODE
750 #define RUN_TEST_cc_c(ARG_STR, FUNC_NAME, ARG1R, ARG1C, ARG2R, ARG2C, \
751 EXPR, EXPC, EXCEPTIONS) \
753 if (enable_test (EXCEPTIONS)) \
755 COMMON_TEST_SETUP (ARG_STR); \
756 check_complex (test_name, \
757 FUNC_TEST (FUNC_NAME) (BUILD_COMPLEX (ARG1R, ARG1C), \
758 BUILD_COMPLEX (ARG2R, ARG2C)), \
759 BUILD_COMPLEX (EXPR, EXPC), EXCEPTIONS); \
760 COMMON_TEST_CLEANUP; \
763 #define RUN_TEST_LOOP_cc_c(FUNC_NAME, ARRAY, ROUNDING_MODE) \
764 IF_ROUND_INIT_ ## ROUNDING_MODE \
765 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
766 RUN_TEST_cc_c ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg1r, \
767 (ARRAY)[i].arg1c, (ARRAY)[i].arg2r, \
769 (ARRAY)[i].RM_##ROUNDING_MODE.expr, \
770 (ARRAY)[i].RM_##ROUNDING_MODE.expc, \
771 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
772 ROUND_RESTORE_ ## ROUNDING_MODE
773 #define RUN_TEST_f_i(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
775 if (enable_test (EXCEPTIONS)) \
777 COMMON_TEST_SETUP (ARG_STR); \
778 check_int (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
780 COMMON_TEST_CLEANUP; \
783 #define RUN_TEST_LOOP_f_i(FUNC_NAME, ARRAY, ROUNDING_MODE) \
784 IF_ROUND_INIT_ ## ROUNDING_MODE \
785 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
786 RUN_TEST_f_i ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
787 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
788 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
789 ROUND_RESTORE_ ## ROUNDING_MODE
790 #define RUN_TEST_f_i_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
793 if (enable_test (EXCEPTIONS)) \
795 COMMON_TEST_SETUP (ARG_STR); \
796 check_int (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
797 COMMON_TEST_CLEANUP; \
800 #define RUN_TEST_LOOP_f_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
801 IF_ROUND_INIT_ ## ROUNDING_MODE \
802 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
803 RUN_TEST_f_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
804 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
805 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
806 ROUND_RESTORE_ ## ROUNDING_MODE
807 #define RUN_TEST_ff_b(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
810 if (enable_test (EXCEPTIONS)) \
812 COMMON_TEST_SETUP (ARG_STR); \
813 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG1, ARG2), \
814 EXPECTED, EXCEPTIONS); \
815 COMMON_TEST_CLEANUP; \
818 #define RUN_TEST_LOOP_ff_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
819 IF_ROUND_INIT_ ## ROUNDING_MODE \
820 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
821 RUN_TEST_ff_b ((ARRAY)[i].arg_str, FUNC_NAME, \
822 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
823 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
824 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
825 ROUND_RESTORE_ ## ROUNDING_MODE
826 #define RUN_TEST_ff_i_tg(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \
829 if (enable_test (EXCEPTIONS)) \
831 COMMON_TEST_SETUP (ARG_STR); \
832 check_int (test_name, FUNC_NAME (ARG1, ARG2), EXPECTED, \
834 COMMON_TEST_CLEANUP; \
837 #define RUN_TEST_LOOP_ff_i_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
838 IF_ROUND_INIT_ ## ROUNDING_MODE \
839 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
840 RUN_TEST_ff_i_tg ((ARRAY)[i].arg_str, FUNC_NAME, \
841 (ARRAY)[i].arg1, (ARRAY)[i].arg2, \
842 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
843 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
844 ROUND_RESTORE_ ## ROUNDING_MODE
845 #define RUN_TEST_f_b(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
847 if (enable_test (EXCEPTIONS)) \
849 COMMON_TEST_SETUP (ARG_STR); \
850 check_bool (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
852 COMMON_TEST_CLEANUP; \
855 #define RUN_TEST_LOOP_f_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
856 IF_ROUND_INIT_ ## ROUNDING_MODE \
857 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
858 RUN_TEST_f_b ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
859 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
860 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
861 ROUND_RESTORE_ ## ROUNDING_MODE
862 #define RUN_TEST_f_b_tg(ARG_STR, FUNC_NAME, ARG, EXPECTED, \
865 if (enable_test (EXCEPTIONS)) \
867 COMMON_TEST_SETUP (ARG_STR); \
868 check_bool (test_name, FUNC_NAME (ARG), EXPECTED, EXCEPTIONS); \
869 COMMON_TEST_CLEANUP; \
872 #define RUN_TEST_LOOP_f_b_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
873 IF_ROUND_INIT_ ## ROUNDING_MODE \
874 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
875 RUN_TEST_f_b_tg ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
876 (ARRAY)[i].RM_##ROUNDING_MODE.expected, \
877 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions); \
878 ROUND_RESTORE_ ## ROUNDING_MODE
879 #define RUN_TEST_f_l(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
881 if (enable_test (EXCEPTIONS)) \
883 COMMON_TEST_SETUP (ARG_STR); \
884 check_long (test_name, FUNC_TEST (FUNC_NAME) (ARG), EXPECTED, \
886 COMMON_TEST_CLEANUP; \
889 #define RUN_TEST_LOOP_f_l(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_l ((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_L(ARG_STR, FUNC_NAME, ARG, EXPECTED, EXCEPTIONS) \
898 if (enable_test (EXCEPTIONS)) \
900 COMMON_TEST_SETUP (ARG_STR); \
901 check_longlong (test_name, FUNC_TEST (FUNC_NAME) (ARG), \
902 EXPECTED, EXCEPTIONS); \
903 COMMON_TEST_CLEANUP; \
906 #define RUN_TEST_LOOP_f_L(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_L ((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_fFF_11(ARG_STR, FUNC_NAME, ARG, EXCEPTIONS, \
914 EXTRA1_VAR, EXTRA1_TEST, \
915 EXTRA1_EXPECTED, EXTRA2_VAR, \
916 EXTRA2_TEST, EXTRA2_EXPECTED) \
918 if (enable_test (EXCEPTIONS)) \
920 COMMON_TEST_SETUP (ARG_STR); \
921 FUNC_TEST (FUNC_NAME) (ARG, &(EXTRA1_VAR), &(EXTRA2_VAR)); \
922 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \
924 check_float (extra1_name, EXTRA1_VAR, EXTRA1_EXPECTED, \
926 EXTRA_OUTPUT_TEST_CLEANUP (1); \
927 EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 2); \
929 check_float (extra2_name, EXTRA2_VAR, EXTRA2_EXPECTED, 0); \
930 EXTRA_OUTPUT_TEST_CLEANUP (2); \
931 COMMON_TEST_CLEANUP; \
934 #define RUN_TEST_LOOP_fFF_11(FUNC_NAME, ARRAY, ROUNDING_MODE, \
935 EXTRA1_VAR, EXTRA2_VAR) \
936 IF_ROUND_INIT_ ## ROUNDING_MODE \
937 for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
938 RUN_TEST_fFF_11 ((ARRAY)[i].arg_str, FUNC_NAME, (ARRAY)[i].arg, \
939 (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \
941 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_test, \
942 (ARRAY)[i].RM_##ROUNDING_MODE.extra1_expected, \
944 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_test, \
945 (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \
946 ROUND_RESTORE_ ## ROUNDING_MODE
952 #define STR_CONCAT(a, b, c) __STRING (a##b##c)
953 #define STR_CON3(a, b, c) STR_CONCAT (a, b, c)
955 /* Start and end the tests for a given function. */
956 #define START(FUN, SUFF, EXACT) \
958 const char *this_func = STR_CON3 (FUN, SUFF, VEC_SUFF); \
959 init_max_error (this_func, EXACT)
961 print_max_error (this_func)
962 #define END_COMPLEX \
963 print_complex_max_error (this_func)
965 /* Run tests for a given function in all rounding modes. */
966 #define ALL_RM_TEST(FUNC, EXACT, ARRAY, LOOP_MACRO, END_MACRO, ...) \
971 START (FUNC,, EXACT); \
972 LOOP_MACRO (FUNC, ARRAY, , ## __VA_ARGS__); \
978 START (FUNC, _downward, EXACT); \
979 LOOP_MACRO (FUNC, ARRAY, FE_DOWNWARD, ## __VA_ARGS__); \
985 START (FUNC, _towardzero, EXACT); \
986 LOOP_MACRO (FUNC, ARRAY, FE_TOWARDZERO, ## __VA_ARGS__); \
992 START (FUNC, _upward, EXACT); \
993 LOOP_MACRO (FUNC, ARRAY, FE_UPWARD, ## __VA_ARGS__); \
1000 /* Short description of program. */
1001 const char doc
[] = "Math test suite: " TEST_MSG
;
1003 static void do_test (void);
1006 main (int argc
, char **argv
)
1008 libm_test_init (argc
, argv
);
1011 return libm_test_finish ();