t_round.c revision 1.1 1 /* $NetBSD: t_round.c,v 1.1 2011/04/08 06:49:21 jruoho Exp $ */
2
3 #include <atf-c.h>
4 #include <math.h>
5
6 /*
7 * This tests for a bug in the initial implementation where
8 * precision was lost in an internal substraction, leading to
9 * rounding into the wrong direction.
10 */
11
12 /* 0.5 - EPSILON */
13 #define VAL 0x0.7ffffffffffffcp0
14 #define VALF 0x0.7fffff8p0
15
16 ATF_TC(round_dir);
17 ATF_TC_HEAD(round_dir, tc)
18 {
19 atf_tc_set_md_var(tc, "descr","Check for rounding in wrong direction");
20 }
21
22 ATF_TC_BODY(round_dir, tc)
23 {
24 double a = VAL, b, c;
25 float af = VALF, bf, cf;
26
27 b = round(a);
28 bf = roundf(af);
29
30 ATF_REQUIRE(fabs(b) < 1.0e-40);
31 ATF_REQUIRE(fabsf(bf) < 1.0e-40);
32
33 c = round(-a);
34 cf = roundf(-af);
35
36 ATF_REQUIRE(fabs(c) < 1.0e-40);
37 ATF_REQUIRE(fabsf(cf) < 1.0e-40);
38 }
39
40 ATF_TP_ADD_TCS(tp)
41 {
42
43 ATF_TP_ADD_TC(tp, round_dir);
44
45 return atf_no_error();
46 }
47