📄 libm-test.inc
字号:
if (print_screen (1, 0)) printf ("Pass: %s: Exception \"%s\" set\n", test_name, flag_name); } else { ok = 0; if (print_screen (0, 0)) printf ("Failure: %s: Exception \"%s\" not set\n", test_name, flag_name); } } else { if (fetestexcept (fe_flag)) { ok = 0; if (print_screen (0, 0)) printf ("Failure: %s: Exception \"%s\" set\n", test_name, flag_name); } else { if (print_screen (1, 0)) printf ("%s: Exception \"%s\" not set\n", test_name, flag_name); } } if (!ok) ++noErrors;#endif}/* Test whether exceptions given by EXCEPTION are raised. Ignore thereby allowed but not required exceptions.*/static voidtest_exceptions (const char *test_name, int exception){ ++noExcTests;#ifdef FE_DIVBYZERO if ((exception & DIVIDE_BY_ZERO_EXCEPTION_OK) == 0) test_single_exception (test_name, exception, DIVIDE_BY_ZERO_EXCEPTION, FE_DIVBYZERO, "Divide by zero");#endif#ifdef FE_INVALID if ((exception & INVALID_EXCEPTION_OK) == 0) test_single_exception (test_name, exception, INVALID_EXCEPTION, FE_INVALID, "Invalid operation");#endif feclearexcept (FE_ALL_EXCEPT);}static voidcheck_float_internal (const char *test_name, FLOAT computed, FLOAT expected, FLOAT max_ulp, int xfail, int exceptions, FLOAT *curr_max_error){ int ok = 0; int print_diff = 0; FLOAT diff = 0; FLOAT ulp = 0; test_exceptions (test_name, exceptions); if (isnan (computed) && isnan (expected)) ok = 1; else if (isinf (computed) && isinf (expected)) { /* Test for sign of infinities. */ if ((exceptions & IGNORE_ZERO_INF_SIGN) == 0 && signbit (computed) != signbit (expected)) { ok = 0; printf ("infinity has wrong sign.\n"); } else ok = 1; } /* Don't calc ulp for NaNs or infinities. */ else if (isinf (computed) || isnan (computed) || isinf (expected) || isnan (expected)) ok = 0; else { diff = FUNC(fabs) (computed - expected); /* ilogb (0) isn't allowed. */ if (expected == 0.0) ulp = diff / FUNC(ldexp) (1.0, - MANT_DIG); else ulp = diff / FUNC(ldexp) (1.0, FUNC(ilogb) (expected) - MANT_DIG); set_max_error (ulp, curr_max_error); print_diff = 1; if ((exceptions & IGNORE_ZERO_INF_SIGN) == 0 && computed == 0.0 && expected == 0.0 && signbit(computed) != signbit (expected)) ok = 0; else if (ulp == 0.0 || (ulp <= max_ulp && !ignore_max_ulp)) ok = 1; else { ok = 0; print_ulps (test_name, ulp); } } if (print_screen (ok, xfail)) { if (!ok) printf ("Failure: "); printf ("Test: %s\n", test_name); printf ("Result:\n"); printf (" is: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n", computed, computed); printf (" should be: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n", expected, expected); if (print_diff) { printf (" difference: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n", diff, diff); printf (" ulp : % .4" PRINTF_NEXPR "\n", ulp); printf (" max.ulp : % .4" PRINTF_NEXPR "\n", max_ulp); } } update_stats (ok, xfail); fpstack_test (test_name);}static voidcheck_float (const char *test_name, FLOAT computed, FLOAT expected, FLOAT max_ulp, int xfail, int exceptions){ check_float_internal (test_name, computed, expected, max_ulp, xfail, exceptions, &max_error);}static voidcheck_complex (const char *test_name, __complex__ FLOAT computed, __complex__ FLOAT expected, __complex__ FLOAT max_ulp, __complex__ int xfail, int exception){ FLOAT part_comp, part_exp, part_max_ulp; int part_xfail; char str[200]; sprintf (str, "Real part of: %s", test_name); part_comp = __real__ computed; part_exp = __real__ expected; part_max_ulp = __real__ max_ulp; part_xfail = __real__ xfail; check_float_internal (str, part_comp, part_exp, part_max_ulp, part_xfail, exception, &real_max_error); sprintf (str, "Imaginary part of: %s", test_name); part_comp = __imag__ computed; part_exp = __imag__ expected; part_max_ulp = __imag__ max_ulp; part_xfail = __imag__ xfail; /* Don't check again for exceptions, just pass through the zero/inf sign test. */ check_float_internal (str, part_comp, part_exp, part_max_ulp, part_xfail, exception & IGNORE_ZERO_INF_SIGN, &imag_max_error);}/* Check that computed and expected values are equal (int values). */static voidcheck_int (const char *test_name, int computed, int expected, int max_ulp, int xfail, int exceptions){ int diff = computed - expected; int ok = 0; test_exceptions (test_name, exceptions); noTests++; if (abs (diff) <= max_ulp) ok = 1; if (!ok) print_ulps (test_name, diff); if (print_screen (ok, xfail)) { if (!ok) printf ("Failure: "); printf ("Test: %s\n", test_name); printf ("Result:\n"); printf (" is: %d\n", computed); printf (" should be: %d\n", expected); } update_stats (ok, xfail); fpstack_test (test_name);}/* Check that computed and expected values are equal (long int values). */static voidcheck_long (const char *test_name, long int computed, long int expected, long int max_ulp, int xfail, int exceptions){ long int diff = computed - expected; int ok = 0; test_exceptions (test_name, exceptions); noTests++; if (labs (diff) <= max_ulp) ok = 1; if (!ok) print_ulps (test_name, diff); if (print_screen (ok, xfail)) { if (!ok) printf ("Failure: "); printf ("Test: %s\n", test_name); printf ("Result:\n"); printf (" is: %ld\n", computed); printf (" should be: %ld\n", expected); } update_stats (ok, xfail); fpstack_test (test_name);}/* Check that computed value is true/false. */static voidcheck_bool (const char *test_name, int computed, int expected, long int max_ulp, int xfail, int exceptions){ int ok = 0; test_exceptions (test_name, exceptions); noTests++; if ((computed == 0) == (expected == 0)) ok = 1; if (print_screen (ok, xfail)) { if (!ok) printf ("Failure: "); printf ("Test: %s\n", test_name); printf ("Result:\n"); printf (" is: %d\n", computed); printf (" should be: %d\n", expected); } update_stats (ok, xfail); fpstack_test (test_name);}/* check that computed and expected values are equal (long int values) */static voidcheck_longlong (const char *test_name, long long int computed, long long int expected, long long int max_ulp, int xfail, int exceptions){ long long int diff = computed - expected; int ok = 0; test_exceptions (test_name, exceptions); noTests++; if (llabs (diff) <= max_ulp) ok = 1; if (!ok) print_ulps (test_name, diff); if (print_screen (ok, xfail)) { if (!ok) printf ("Failure:"); printf ("Test: %s\n", test_name); printf ("Result:\n"); printf (" is: %lld\n", computed); printf (" should be: %lld\n", expected); } update_stats (ok, xfail); fpstack_test (test_name);}/* This is to prevent messages from the SVID libm emulation. */intmatherr (struct exception *x __attribute__ ((unused))){ return 1;}/**************************************************************************** Tests for single functions of libm. Please keep them alphabetically sorted!****************************************************************************/static voidacos_test (void){ errno = 0; FUNC(acos) (0); if (errno == ENOSYS) /* Function not implemented. */ return; START (acos); TEST_f_f (acos, plus_infty, nan_value, INVALID_EXCEPTION); TEST_f_f (acos, minus_infty, nan_value, INVALID_EXCEPTION); TEST_f_f (acos, nan_value, nan_value); /* |x| > 1: */ TEST_f_f (acos, 1.1L, nan_value, INVALID_EXCEPTION); TEST_f_f (acos, -1.1L, nan_value, INVALID_EXCEPTION); TEST_f_f (acos, 0, M_PI_2l); TEST_f_f (acos, minus_zero, M_PI_2l); TEST_f_f (acos, 1, 0); TEST_f_f (acos, -1, M_PIl); TEST_f_f (acos, 0.5, M_PI_6l*2.0); TEST_f_f (acos, -0.5, M_PI_6l*4.0); TEST_f_f (acos, 0.7L, 0.79539883018414355549096833892476432L); END (acos);}static voidacosh_test (void){ errno = 0; FUNC(acosh) (7); if (errno == ENOSYS) /* Function not implemented. */ return; START (acosh); TEST_f_f (acosh, plus_infty, plus_infty); TEST_f_f (acosh, minus_infty, nan_value, INVALID_EXCEPTION); /* x < 1: */ TEST_f_f (acosh, -1.1L, nan_value, INVALID_EXCEPTION); TEST_f_f (acosh, 1, 0); TEST_f_f (acosh, 7, 2.633915793849633417250092694615937L); END (acosh);}static voidasin_test (void){ errno = 0; FUNC(asin) (0); if (errno == ENOSYS) /* Function not implemented. */ return; START (asin); TEST_f_f (asin, plus_infty, nan_value, INVALID_EXCEPTION); TEST_f_f (asin, minus_infty, nan_value, INVALID_EXCEPTION); TEST_f_f (asin, nan_value, nan_value); /* asin x == NaN plus invalid exception for |x| > 1. */ TEST_f_f (asin, 1.1L, nan_value, INVALID_EXCEPTION); TEST_f_f (asin, -1.1L, nan_value, INVALID_EXCEPTION); TEST_f_f (asin, 0, 0); TEST_f_f (asin, minus_zero, minus_zero); TEST_f_f (asin, 0.5, M_PI_6l); TEST_f_f (asin, -0.5, -M_PI_6l); TEST_f_f (asin, 1.0, M_PI_2l); TEST_f_f (asin, -1.0, -M_PI_2l); TEST_f_f (asin, 0.7L, 0.77539749661075306374035335271498708L); END (asin);}static voidasinh_test (void){ errno = 0; FUNC(asinh) (0.7L); if (errno == ENOSYS) /* Function not implemented. */ return; START (asinh);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -