t_libm.h revision 1.2 1 /* $NetBSD: t_libm.h,v 1.2 2014/03/05 20:14:46 dsl Exp $ */
2
3 /*
4 * Check result of fn(arg) is correct within the bounds.
5 * Should be ok to do the checks using 'double' for 'float' functions.
6 */
7 #define T_LIBM_CHECK(subtest, fn, arg, expect, epsilon) do { \
8 double r = fn(arg); \
9 double e = fabs(r - expect); \
10 if (e > epsilon) \
11 atf_tc_fail_nonfatal( \
12 "subtest %u: " #fn "(%g) is %g not %g (error %g > %g)", \
13 subtest, arg, r, expect, e, epsilon); \
14 } while (0)
15
16 /* Check that the result of fn(arg) is NaN */
17 #ifndef __vax__
18 #define T_LIBM_CHECK_NAN(subtest, fn, arg) do { \
19 double r = fn(arg); \
20 if (!isnan(r)) \
21 atf_tc_fail_nonfatal("subtest %u: " #fn "(%g) is %g not NaN", \
22 subtest, arg, r); \
23 } while (0)
24 #else
25 /* vax doesn't support NaN */
26 #define T_LIBM_CHECK_NAN(subtest, fn, arg) (void)(arg)
27 #endif
28
29 /* Check that the result of fn(arg) is +0.0 */
30 #define T_LIBM_CHECK_PLUS_ZERO(subtest, fn, arg) do { \
31 double r = fn(arg); \
32 if (fabs(r) > 0.0 || signbit(r) != 0) \
33 atf_tc_fail_nonfatal("subtest %u: " #fn "(%g) is %g not +0.0", \
34 subtest, arg, r); \
35 } while (0)
36
37 /* Check that the result of fn(arg) is -0.0 */
38 #define T_LIBM_CHECK_MINUS_ZERO(subtest, fn, arg) do { \
39 double r = fn(arg); \
40 if (fabs(r) > 0.0 || signbit(r) == 0) \
41 atf_tc_fail_nonfatal("subtest %u: " #fn "(%g) is %g not -0.0", \
42 subtest, arg, r); \
43 } while (0)
44
45 /* Some useful constants (for test vectors) */
46 #define T_LIBM_NAN (0.0 / 0.0)
47 #define T_LIBM_PLUS_INF (+1.0 / 0.0)
48 #define T_LIBM_MINUS_INF (-1.0 / 0.0)
49
50 /* One line definition of a simple test */
51 #define ATF_LIBM_TEST(name, description) \
52 ATF_TC(name); \
53 ATF_TC_HEAD(name, tc) { atf_tc_set_md_var(tc, "descr", description); } \
54 ATF_TC_BODY(name, tc)
55