1 1.7 riastrad /* $NetBSD: t_libm.h,v 1.7 2018/11/07 03:59:36 riastradh Exp $ */ 2 1.1 dsl 3 1.1 dsl /* 4 1.1 dsl * Check result of fn(arg) is correct within the bounds. 5 1.1 dsl * Should be ok to do the checks using 'double' for 'float' functions. 6 1.5 dsl * On i386 float and double values are returned on the x87 stack and might 7 1.5 dsl * be out of range for the function - so save and print as 'long double'. 8 1.5 dsl * (otherwise you can get 'inf != inf' reported!) 9 1.1 dsl */ 10 1.6 joerg #define T_LIBM_CHECK(subtest, fn, arg, expect_, epsilon_) do { \ 11 1.6 joerg long double epsilon = epsilon_; \ 12 1.6 joerg long double expect = expect_; \ 13 1.5 dsl long double r = fn(arg); \ 14 1.7 riastrad long double e = fabsl((r - expect)/expect); \ 15 1.7 riastrad if (!(r == expect || e <= epsilon)) \ 16 1.1 dsl atf_tc_fail_nonfatal( \ 17 1.6 joerg "subtest %u: " #fn "(%g) is %Lg (%.14La) " \ 18 1.6 joerg "not %Lg (%.13La), error %Lg (%.6La) > %Lg", \ 19 1.4 dsl subtest, arg, r, r, expect, expect, e, e, epsilon); \ 20 1.1 dsl } while (0) 21 1.1 dsl 22 1.1 dsl /* Check that the result of fn(arg) is NaN */ 23 1.1 dsl #ifndef __vax__ 24 1.1 dsl #define T_LIBM_CHECK_NAN(subtest, fn, arg) do { \ 25 1.1 dsl double r = fn(arg); \ 26 1.1 dsl if (!isnan(r)) \ 27 1.1 dsl atf_tc_fail_nonfatal("subtest %u: " #fn "(%g) is %g not NaN", \ 28 1.1 dsl subtest, arg, r); \ 29 1.1 dsl } while (0) 30 1.1 dsl #else 31 1.1 dsl /* vax doesn't support NaN */ 32 1.1 dsl #define T_LIBM_CHECK_NAN(subtest, fn, arg) (void)(arg) 33 1.1 dsl #endif 34 1.1 dsl 35 1.1 dsl /* Check that the result of fn(arg) is +0.0 */ 36 1.1 dsl #define T_LIBM_CHECK_PLUS_ZERO(subtest, fn, arg) do { \ 37 1.1 dsl double r = fn(arg); \ 38 1.1 dsl if (fabs(r) > 0.0 || signbit(r) != 0) \ 39 1.1 dsl atf_tc_fail_nonfatal("subtest %u: " #fn "(%g) is %g not +0.0", \ 40 1.1 dsl subtest, arg, r); \ 41 1.1 dsl } while (0) 42 1.1 dsl 43 1.1 dsl /* Check that the result of fn(arg) is -0.0 */ 44 1.1 dsl #define T_LIBM_CHECK_MINUS_ZERO(subtest, fn, arg) do { \ 45 1.1 dsl double r = fn(arg); \ 46 1.1 dsl if (fabs(r) > 0.0 || signbit(r) == 0) \ 47 1.1 dsl atf_tc_fail_nonfatal("subtest %u: " #fn "(%g) is %g not -0.0", \ 48 1.1 dsl subtest, arg, r); \ 49 1.1 dsl } while (0) 50 1.1 dsl 51 1.1 dsl /* Some useful constants (for test vectors) */ 52 1.3 martin #ifndef __vax__ /* no NAN nor +/- INF on vax */ 53 1.2 dsl #define T_LIBM_NAN (0.0 / 0.0) 54 1.2 dsl #define T_LIBM_PLUS_INF (+1.0 / 0.0) 55 1.2 dsl #define T_LIBM_MINUS_INF (-1.0 / 0.0) 56 1.3 martin #endif 57 1.1 dsl 58 1.1 dsl /* One line definition of a simple test */ 59 1.2 dsl #define ATF_LIBM_TEST(name, description) \ 60 1.1 dsl ATF_TC(name); \ 61 1.1 dsl ATF_TC_HEAD(name, tc) { atf_tc_set_md_var(tc, "descr", description); } \ 62 1.1 dsl ATF_TC_BODY(name, tc) 63