t_libm.h revision 1.5 1 1.5 dsl /* $NetBSD: t_libm.h,v 1.5 2014/03/16 22:49:27 dsl 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.1 dsl #define T_LIBM_CHECK(subtest, fn, arg, expect, epsilon) do { \
11 1.5 dsl long double r = fn(arg); \
12 1.1 dsl double e = fabs(r - expect); \
13 1.4 dsl if (r != expect && e > epsilon) \
14 1.1 dsl atf_tc_fail_nonfatal( \
15 1.5 dsl "subtest %u: " #fn "(%g) is %Lg (%.14La) not %g (%.13a), error %g (%.6a) > %g", \
16 1.4 dsl subtest, arg, r, r, expect, expect, e, e, epsilon); \
17 1.1 dsl } while (0)
18 1.1 dsl
19 1.1 dsl /* Check that the result of fn(arg) is NaN */
20 1.1 dsl #ifndef __vax__
21 1.1 dsl #define T_LIBM_CHECK_NAN(subtest, fn, arg) do { \
22 1.1 dsl double r = fn(arg); \
23 1.1 dsl if (!isnan(r)) \
24 1.1 dsl atf_tc_fail_nonfatal("subtest %u: " #fn "(%g) is %g not NaN", \
25 1.1 dsl subtest, arg, r); \
26 1.1 dsl } while (0)
27 1.1 dsl #else
28 1.1 dsl /* vax doesn't support NaN */
29 1.1 dsl #define T_LIBM_CHECK_NAN(subtest, fn, arg) (void)(arg)
30 1.1 dsl #endif
31 1.1 dsl
32 1.1 dsl /* Check that the result of fn(arg) is +0.0 */
33 1.1 dsl #define T_LIBM_CHECK_PLUS_ZERO(subtest, fn, arg) do { \
34 1.1 dsl double r = fn(arg); \
35 1.1 dsl if (fabs(r) > 0.0 || signbit(r) != 0) \
36 1.1 dsl atf_tc_fail_nonfatal("subtest %u: " #fn "(%g) is %g not +0.0", \
37 1.1 dsl subtest, arg, r); \
38 1.1 dsl } while (0)
39 1.1 dsl
40 1.1 dsl /* Check that the result of fn(arg) is -0.0 */
41 1.1 dsl #define T_LIBM_CHECK_MINUS_ZERO(subtest, fn, arg) do { \
42 1.1 dsl double r = fn(arg); \
43 1.1 dsl if (fabs(r) > 0.0 || signbit(r) == 0) \
44 1.1 dsl atf_tc_fail_nonfatal("subtest %u: " #fn "(%g) is %g not -0.0", \
45 1.1 dsl subtest, arg, r); \
46 1.1 dsl } while (0)
47 1.1 dsl
48 1.1 dsl /* Some useful constants (for test vectors) */
49 1.3 martin #ifndef __vax__ /* no NAN nor +/- INF on vax */
50 1.2 dsl #define T_LIBM_NAN (0.0 / 0.0)
51 1.2 dsl #define T_LIBM_PLUS_INF (+1.0 / 0.0)
52 1.2 dsl #define T_LIBM_MINUS_INF (-1.0 / 0.0)
53 1.3 martin #endif
54 1.1 dsl
55 1.1 dsl /* One line definition of a simple test */
56 1.2 dsl #define ATF_LIBM_TEST(name, description) \
57 1.1 dsl ATF_TC(name); \
58 1.1 dsl ATF_TC_HEAD(name, tc) { atf_tc_set_md_var(tc, "descr", description); } \
59 1.1 dsl ATF_TC_BODY(name, tc)
60