etc/protocols - sync with NetBSD-8
[minix.git] / tests / lib / libm / t_round.c
blobf47e1a0f8a13392057f855b458d6b5e87da9b4f7
1 /* $NetBSD: t_round.c,v 1.4 2013/11/11 23:57:34 joerg Exp $ */
3 /*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
29 #include <atf-c.h>
30 #include <float.h>
31 #include <math.h>
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.
39 /* 0.5 - EPSILON */
40 #define VAL 0x0.7ffffffffffffcp0
41 #define VALF 0x0.7fffff8p0
42 #define VALL (0.5 - LDBL_EPSILON)
44 #ifdef __vax__
45 #define SMALL_NUM 1.0e-38
46 #else
47 #define SMALL_NUM 1.0e-40
48 #endif
50 ATF_TC(round_dir);
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)
58 double a = VAL, b, c;
59 float af = VALF, bf, cf;
60 long double al = VALL, bl, cl;
62 b = round(a);
63 bf = roundf(af);
64 bl = roundl(al);
66 ATF_CHECK(fabs(b) < SMALL_NUM);
67 ATF_CHECK(fabsf(bf) < SMALL_NUM);
68 ATF_CHECK(fabsl(bl) < SMALL_NUM);
70 c = round(-a);
71 cf = roundf(-af);
72 cl = roundl(-al);
74 ATF_CHECK(fabs(c) < SMALL_NUM);
75 ATF_CHECK(fabsf(cf) < SMALL_NUM);
76 ATF_CHECK(fabsl(cl) < SMALL_NUM);
79 ATF_TP_ADD_TCS(tp)
82 ATF_TP_ADD_TC(tp, round_dir);
84 return atf_no_error();