t_sinh.c revision 1.1 1 /* $NetBSD: t_sinh.c,v 1.1 2011/10/16 07:40:47 jruoho Exp $ */
2
3 /*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jukka Ruohonen.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_sinh.c,v 1.1 2011/10/16 07:40:47 jruoho Exp $");
33
34 #include <atf-c.h>
35 #include <math.h>
36 #include <stdio.h>
37
38 /*
39 * sinh(3)
40 */
41 ATF_TC(sinh_def);
42 ATF_TC_HEAD(sinh_def, tc)
43 {
44 atf_tc_set_md_var(tc, "descr", "Test the definition of sinh(3)");
45 }
46
47 ATF_TC_BODY(sinh_def, tc)
48 {
49 #ifndef __vax__
50 const double x[] = { -9.0, -1.0, -0.05, 0.0, 1.0, 10.0, 20.0 };
51 const double eps = 1.0e-16;
52 double y, z;
53 size_t i;
54
55 for (i = 0; i < __arraycount(x); i++) {
56
57 y = sinh(x[i]);
58 z = (exp(x[i]) - exp(-x[i])) / 2;
59
60 if (fabs(y - z) > eps)
61 atf_tc_fail_nonfatal("sinh(%0.03f) != %0.03f\n",
62 x[i], z);
63 }
64 #endif
65 }
66
67 ATF_TC(sinh_nan);
68 ATF_TC_HEAD(sinh_nan, tc)
69 {
70 atf_tc_set_md_var(tc, "descr", "Test sinh(NaN) == NaN");
71 }
72
73 ATF_TC_BODY(sinh_nan, tc)
74 {
75 #ifndef __vax__
76 const double x = 0.0L / 0.0L;
77
78 ATF_CHECK(isnan(x) != 0);
79 ATF_CHECK(isnan(sinh(x)) != 0);
80 #endif
81 }
82
83 ATF_TC(sinh_inf_neg);
84 ATF_TC_HEAD(sinh_inf_neg, tc)
85 {
86 atf_tc_set_md_var(tc, "descr", "Test sinh(-Inf) == -Inf");
87 }
88
89 ATF_TC_BODY(sinh_inf_neg, tc)
90 {
91 #ifndef __vax__
92 const double x = -1.0L / 0.0L;
93 double y = sinh(x);
94
95 ATF_CHECK(isinf(y) != 0);
96 ATF_CHECK(signbit(y) != 0);
97 #endif
98 }
99
100 ATF_TC(sinh_inf_pos);
101 ATF_TC_HEAD(sinh_inf_pos, tc)
102 {
103 atf_tc_set_md_var(tc, "descr", "Test sinh(+Inf) == +Inf");
104 }
105
106 ATF_TC_BODY(sinh_inf_pos, tc)
107 {
108 #ifndef __vax__
109 const double x = 1.0L / 0.0L;
110 double y = sinh(x);
111
112 ATF_CHECK(isinf(y) != 0);
113 ATF_CHECK(signbit(y) == 0);
114 #endif
115 }
116
117 ATF_TC(sinh_zero_neg);
118 ATF_TC_HEAD(sinh_zero_neg, tc)
119 {
120 atf_tc_set_md_var(tc, "descr", "Test sinh(-0.0) == -0.0");
121 }
122
123 ATF_TC_BODY(sinh_zero_neg, tc)
124 {
125 #ifndef __vax__
126 const double x = -0.0L;
127 double y = sinh(x);
128
129 if (fabs(y) > 0.0 || signbit(y) == 0)
130 atf_tc_fail_nonfatal("sinh(-0.0) != -0.0");
131 #endif
132 }
133
134 ATF_TC(sinh_zero_pos);
135 ATF_TC_HEAD(sinh_zero_pos, tc)
136 {
137 atf_tc_set_md_var(tc, "descr", "Test sinh(+0.0) == +0.0");
138 }
139
140 ATF_TC_BODY(sinh_zero_pos, tc)
141 {
142 #ifndef __vax__
143 const double x = 0.0L;
144 double y = sinh(x);
145
146 if (fabs(y) > 0.0 || signbit(y) != 0)
147 atf_tc_fail_nonfatal("sinh(+0.0) != +0.0");
148 #endif
149 }
150
151 /*
152 * sinhf(3)
153 */
154 ATF_TC(sinhf_def);
155 ATF_TC_HEAD(sinhf_def, tc)
156 {
157 atf_tc_set_md_var(tc, "descr", "Test the definition of sinhf(3)");
158 }
159
160 ATF_TC_BODY(sinhf_def, tc)
161 {
162 #ifndef __vax__
163 const float x[] = { -9.0, -1.0, -0.05, 0.0, 1.0, 10.0, 20.0 };
164 const float eps = 1.0e-7;
165 float y, z;
166 size_t i;
167
168 for (i = 0; i < __arraycount(x); i++) {
169
170 y = sinhf(x[i]);
171 z = (expf(x[i]) - expf(-x[i])) / 2;
172
173 if (fabsf(y - z) > eps)
174 atf_tc_fail_nonfatal("sinhf(%0.03f) != %0.03f\n",
175 x[i], z);
176 }
177 #endif
178 }
179
180 ATF_TC(sinhf_nan);
181 ATF_TC_HEAD(sinhf_nan, tc)
182 {
183 atf_tc_set_md_var(tc, "descr", "Test sinhf(NaN) == NaN");
184 }
185
186 ATF_TC_BODY(sinhf_nan, tc)
187 {
188 #ifndef __vax__
189 const float x = 0.0L / 0.0L;
190
191 ATF_CHECK(isnan(x) != 0);
192 ATF_CHECK(isnan(sinhf(x)) != 0);
193 #endif
194 }
195
196 ATF_TC(sinhf_inf_neg);
197 ATF_TC_HEAD(sinhf_inf_neg, tc)
198 {
199 atf_tc_set_md_var(tc, "descr", "Test sinhf(-Inf) == -Inf");
200 }
201
202 ATF_TC_BODY(sinhf_inf_neg, tc)
203 {
204 #ifndef __vax__
205 const float x = -1.0L / 0.0L;
206 float y = sinhf(x);
207
208 ATF_CHECK(isinf(y) != 0);
209 ATF_CHECK(signbit(y) != 0);
210 #endif
211 }
212
213 ATF_TC(sinhf_inf_pos);
214 ATF_TC_HEAD(sinhf_inf_pos, tc)
215 {
216 atf_tc_set_md_var(tc, "descr", "Test sinhf(+Inf) == +Inf");
217 }
218
219 ATF_TC_BODY(sinhf_inf_pos, tc)
220 {
221 #ifndef __vax__
222 const float x = 1.0L / 0.0L;
223 float y = sinhf(x);
224
225 ATF_CHECK(isinf(y) != 0);
226 ATF_CHECK(signbit(y) == 0);
227 #endif
228 }
229
230 ATF_TC(sinhf_zero_neg);
231 ATF_TC_HEAD(sinhf_zero_neg, tc)
232 {
233 atf_tc_set_md_var(tc, "descr", "Test sinhf(-0.0) == -0.0");
234 }
235
236 ATF_TC_BODY(sinhf_zero_neg, tc)
237 {
238 #ifndef __vax__
239 const float x = -0.0L;
240 float y = sinhf(x);
241
242 if (fabsf(y) > 0.0 || signbit(y) == 0)
243 atf_tc_fail_nonfatal("sinhf(-0.0) != -0.0");
244 #endif
245 }
246
247 ATF_TC(sinhf_zero_pos);
248 ATF_TC_HEAD(sinhf_zero_pos, tc)
249 {
250 atf_tc_set_md_var(tc, "descr", "Test sinhf(+0.0) == +0.0");
251 }
252
253 ATF_TC_BODY(sinhf_zero_pos, tc)
254 {
255 #ifndef __vax__
256 const float x = 0.0L;
257 float y = sinhf(x);
258
259 if (fabsf(y) > 0.0 || signbit(y) != 0)
260 atf_tc_fail_nonfatal("sinhf(+0.0) != +0.0");
261 #endif
262 }
263
264 ATF_TP_ADD_TCS(tp)
265 {
266
267 ATF_TP_ADD_TC(tp, sinh_def);
268 ATF_TP_ADD_TC(tp, sinh_nan);
269 ATF_TP_ADD_TC(tp, sinh_inf_neg);
270 ATF_TP_ADD_TC(tp, sinh_inf_pos);
271 ATF_TP_ADD_TC(tp, sinh_zero_neg);
272 ATF_TP_ADD_TC(tp, sinh_zero_pos);
273
274 ATF_TP_ADD_TC(tp, sinhf_def);
275 ATF_TP_ADD_TC(tp, sinhf_nan);
276 ATF_TP_ADD_TC(tp, sinhf_inf_neg);
277 ATF_TP_ADD_TC(tp, sinhf_inf_pos);
278 ATF_TP_ADD_TC(tp, sinhf_zero_neg);
279 ATF_TP_ADD_TC(tp, sinhf_zero_pos);
280
281 return atf_no_error();
282 }
283