1 /* $NetBSD: t_round.c,v 1.4 2013/11/11 23:57:34 joerg Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
34 * This tests for a bug in the initial implementation where
35 * precision was lost in an internal substraction, leading to
36 * rounding into the wrong direction.
40 #define VAL 0x0.7ffffffffffffcp0
41 #define VALF 0x0.7fffff8p0
42 #define VALL (0.5 - LDBL_EPSILON)
45 #define SMALL_NUM 1.0e-38
47 #define SMALL_NUM 1.0e-40
51 ATF_TC_HEAD(round_dir
, tc
)
53 atf_tc_set_md_var(tc
, "descr","Check for rounding in wrong direction");
56 ATF_TC_BODY(round_dir
, tc
)
59 float af
= VALF
, bf
, cf
;
60 long double al
= VALL
, bl
, cl
;
66 ATF_CHECK(fabs(b
) < SMALL_NUM
);
67 ATF_CHECK(fabsf(bf
) < SMALL_NUM
);
68 ATF_CHECK(fabsl(bl
) < SMALL_NUM
);
74 ATF_CHECK(fabs(c
) < SMALL_NUM
);
75 ATF_CHECK(fabsf(cf
) < SMALL_NUM
);
76 ATF_CHECK(fabsl(cl
) < SMALL_NUM
);
82 ATF_TP_ADD_TC(tp
, round_dir
);
84 return atf_no_error();