1 /* $NetBSD: t_fpclassify.c,v 1.3 2011/10/01 21:47:08 christos 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.
36 #ifndef _FLOAT_IEEE754
39 ATF_TC_HEAD(no_test
, tc
)
41 atf_tc_set_md_var(tc
, "descr", "Dummy test");
44 ATF_TC_BODY(no_test
,tc
)
46 atf_tc_skip("Test not available on this architecture");
49 #else /* defined(_FLOAT_IEEE754) */
51 ATF_TC(fpclassify_float
);
52 ATF_TC_HEAD(fpclassify_float
, tc
)
55 atf_tc_set_md_var(tc
, "descr", "Test float operations");
58 ATF_TC_BODY(fpclassify_float
, tc
)
60 float d0
, d1
, d2
, f
, ip
;
64 ATF_REQUIRE_EQ(fpclassify(d0
), FP_NORMAL
);
66 ATF_REQUIRE_EQ(e
, FLT_MIN_EXP
);
67 ATF_REQUIRE_EQ(f
, 0.5);
70 /* shift a "1" bit through the mantissa (skip the implicit bit) */
71 for (i
= 1; i
< FLT_MANT_DIG
; i
++) {
73 ATF_REQUIRE_EQ(fpclassify(d1
), FP_SUBNORMAL
);
74 ATF_REQUIRE(d1
> 0 && d1
< d0
);
77 ATF_REQUIRE_EQ(d2
, d1
);
80 ATF_REQUIRE_EQ(d2
, d1
);
81 ATF_REQUIRE_EQ(ip
, 0);
84 ATF_REQUIRE_EQ(e
, FLT_MIN_EXP
- i
);
85 ATF_REQUIRE_EQ(f
, 0.5);
89 ATF_REQUIRE_EQ(fpclassify(d1
), FP_ZERO
);
95 ATF_TC(fpclassify_double
);
96 ATF_TC_HEAD(fpclassify_double
, tc
)
99 atf_tc_set_md_var(tc
, "descr", "Test double operations");
102 ATF_TC_BODY(fpclassify_double
, tc
)
104 double d0
, d1
, d2
, f
, ip
;
108 ATF_REQUIRE_EQ(fpclassify(d0
), FP_NORMAL
);
110 ATF_REQUIRE_EQ(e
, DBL_MIN_EXP
);
111 ATF_REQUIRE_EQ(f
, 0.5);
114 /* shift a "1" bit through the mantissa (skip the implicit bit) */
115 for (i
= 1; i
< DBL_MANT_DIG
; i
++) {
117 ATF_REQUIRE_EQ(fpclassify(d1
), FP_SUBNORMAL
);
118 ATF_REQUIRE(d1
> 0 && d1
< d0
);
121 ATF_REQUIRE_EQ(d2
, d1
);
124 ATF_REQUIRE_EQ(d2
, d1
);
125 ATF_REQUIRE_EQ(ip
, 0);
128 ATF_REQUIRE_EQ(e
, DBL_MIN_EXP
- i
);
129 ATF_REQUIRE_EQ(f
, 0.5);
133 ATF_REQUIRE_EQ(fpclassify(d1
), FP_ZERO
);
135 ATF_REQUIRE_EQ(e
, 0);
136 ATF_REQUIRE_EQ(f
, 0);
140 * XXX NetBSD doesn't have long-double flavors of frexp, ldexp, and modf,
141 * XXX so this test is disabled.
144 #ifdef TEST_LONG_DOUBLE
146 ATF_TC(fpclassify_long_double
);
147 ATF_TC_HEAD(fpclassify_long_double
, tc
)
150 atf_tc_set_md_var(tc
, "descr", "Test long double operations");
153 ATF_TC_BODY(fpclassify_long_double
, tc
)
155 long double d0
, d1
, d2
, f
, ip
;
159 ATF_REQUIRE_EQ(fpclassify(d0
), FP_NORMAL
);
161 ATF_REQUIRE_EQ(e
, LDBL_MIN_EXP
);
162 ATF_REQUIRE_EQ(f
, 0.5);
165 /* shift a "1" bit through the mantissa (skip the implicit bit) */
166 for (i
= 1; i
< LDBL_MANT_DIG
; i
++) {
168 ATF_REQUIRE_EQ(fpclassify(d1
), FP_SUBNORMAL
);
169 ATF_REQUIRE(d1
> 0 && d1
< d0
);
172 ATF_REQUIRE_EQ(d2
, d1
);
175 ATF_REQUIRE_EQ(d2
, d1
);
176 ATF_REQUIRE_EQ(ip
, 0);
179 ATF_REQUIRE_EQ(e
, LDBL_MIN_EXP
- i
);
180 ATF_REQUIRE_EQ(f
, 0.5);
184 ATF_REQUIRE_EQ(fpclassify(d1
), FP_ZERO
);
186 ATF_REQUIRE_EQ(e
, 0);
187 ATF_REQUIRE_EQ(f
, 0);
189 #endif /* TEST_LONG_DOUBLE */
190 #endif /* _FLOAT_IEEE754 */
195 #ifndef _FLOAT_IEEE754
196 ATF_TP_ADD_TC(tp
, no_test
);
198 ATF_TP_ADD_TC(tp
, fpclassify_float
);
199 ATF_TP_ADD_TC(tp
, fpclassify_double
);
200 #ifdef TEST_LONG_DOUBLE
201 ATF_TP_ADD_TC(tp
, fpclassify_long_double
);
202 #endif /* TEST_LONG_DOUBLE */
203 #endif /* _FLOAT_IEEE754 */
205 return atf_no_error();