t_sinh.c revision 1.4.8.1 1 /* $NetBSD: t_sinh.c,v 1.4.8.1 2013/06/23 06:28:57 tls 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.4.8.1 2013/06/23 06:28:57 tls Exp $");
33
34 #include <atf-c.h>
35 #include <math.h>
36 #include <stdio.h>
37
38 static const struct {
39 double x;
40 double y;
41 double e;
42 } values[] = {
43 { -10, -11013.23287470339, 1e4, },
44 { -2, -3.626860407847019, 1, },
45 { -1, -1.175201193643801, 1, },
46 { -0.05, -0.050020835937655, 1, },
47 { -0.001,-0.001000000166667, 1, },
48 { 0.001, 0.001000000166667, 1, },
49 { 0.05, 0.050020835937655, 1, },
50 { 1, 1.175201193643801, 1, },
51 { 2, 3.626860407847019, 1, },
52 { 10, 11013.23287470339, 1e4, },
53 };
54
55 /*
56 * sinh(3)
57 */
58 ATF_TC(sinh_inrange);
59 ATF_TC_HEAD(sinh_inrange, tc)
60 {
61 atf_tc_set_md_var(tc, "descr", "sinh(x) for some values");
62 }
63
64 ATF_TC_BODY(sinh_inrange, tc)
65 {
66 #ifndef __vax__
67 double eps;
68 double x;
69 double y;
70 size_t i;
71
72 for (i = 0; i < __arraycount(values); i++) {
73 x = values[i].x;
74 y = values[i].y;
75 eps = 1e-15 * values[i].e;
76
77 if (fabs(sinh(x) - y) > eps)
78 atf_tc_fail_nonfatal("sinh(%g) != %g\n", x, y);
79 }
80 #endif
81 }
82
83 ATF_TC(sinh_nan);
84 ATF_TC_HEAD(sinh_nan, tc)
85 {
86 atf_tc_set_md_var(tc, "descr", "Test sinh(NaN) == NaN");
87 }
88
89 ATF_TC_BODY(sinh_nan, tc)
90 {
91 #ifndef __vax__
92 const double x = 0.0L / 0.0L;
93
94 ATF_CHECK(isnan(x) != 0);
95 ATF_CHECK(isnan(sinh(x)) != 0);
96 #endif
97 }
98
99 ATF_TC(sinh_inf_neg);
100 ATF_TC_HEAD(sinh_inf_neg, tc)
101 {
102 atf_tc_set_md_var(tc, "descr", "Test sinh(-Inf) == -Inf");
103 }
104
105 ATF_TC_BODY(sinh_inf_neg, tc)
106 {
107 #ifndef __vax__
108 const double x = -1.0L / 0.0L;
109 double y = sinh(x);
110
111 ATF_CHECK(isinf(y) != 0);
112 ATF_CHECK(signbit(y) != 0);
113 #endif
114 }
115
116 ATF_TC(sinh_inf_pos);
117 ATF_TC_HEAD(sinh_inf_pos, tc)
118 {
119 atf_tc_set_md_var(tc, "descr", "Test sinh(+Inf) == +Inf");
120 }
121
122 ATF_TC_BODY(sinh_inf_pos, tc)
123 {
124 #ifndef __vax__
125 const double x = 1.0L / 0.0L;
126 double y = sinh(x);
127
128 ATF_CHECK(isinf(y) != 0);
129 ATF_CHECK(signbit(y) == 0);
130 #endif
131 }
132
133 ATF_TC(sinh_zero_neg);
134 ATF_TC_HEAD(sinh_zero_neg, tc)
135 {
136 atf_tc_set_md_var(tc, "descr", "Test sinh(-0.0) == -0.0");
137 }
138
139 ATF_TC_BODY(sinh_zero_neg, tc)
140 {
141 #ifndef __vax__
142 const double x = -0.0L;
143 double y = sinh(x);
144
145 if (fabs(y) > 0.0 || signbit(y) == 0)
146 atf_tc_fail_nonfatal("sinh(-0.0) != -0.0");
147 #endif
148 }
149
150 ATF_TC(sinh_zero_pos);
151 ATF_TC_HEAD(sinh_zero_pos, tc)
152 {
153 atf_tc_set_md_var(tc, "descr", "Test sinh(+0.0) == +0.0");
154 }
155
156 ATF_TC_BODY(sinh_zero_pos, tc)
157 {
158 #ifndef __vax__
159 const double x = 0.0L;
160 double y = sinh(x);
161
162 if (fabs(y) > 0.0 || signbit(y) != 0)
163 atf_tc_fail_nonfatal("sinh(+0.0) != +0.0");
164 #endif
165 }
166
167 /*
168 * sinhf(3)
169 */
170 ATF_TC(sinhf_inrange);
171 ATF_TC_HEAD(sinhf_inrange, tc)
172 {
173 atf_tc_set_md_var(tc, "descr", "sinhf(x) for some values");
174 }
175
176 ATF_TC_BODY(sinhf_inrange, tc)
177 {
178 #ifndef __vax__
179 float eps;
180 float x;
181 float y;
182 size_t i;
183
184 for (i = 0; i < __arraycount(values); i++) {
185 x = values[i].x;
186 y = values[i].y;
187 eps = 1e-6 * values[i].e;
188
189 if (fabsf(sinhf(x) - y) > eps)
190 atf_tc_fail_nonfatal("sinhf(%g) != %g\n", x, y);
191 }
192 #endif
193 }
194
195 ATF_TC(sinhf_nan);
196 ATF_TC_HEAD(sinhf_nan, tc)
197 {
198 atf_tc_set_md_var(tc, "descr", "Test sinhf(NaN) == NaN");
199 }
200
201 ATF_TC_BODY(sinhf_nan, tc)
202 {
203 #ifndef __vax__
204 const float x = 0.0L / 0.0L;
205
206 ATF_CHECK(isnan(x) != 0);
207 ATF_CHECK(isnan(sinhf(x)) != 0);
208 #endif
209 }
210
211 ATF_TC(sinhf_inf_neg);
212 ATF_TC_HEAD(sinhf_inf_neg, tc)
213 {
214 atf_tc_set_md_var(tc, "descr", "Test sinhf(-Inf) == -Inf");
215 }
216
217 ATF_TC_BODY(sinhf_inf_neg, tc)
218 {
219 #ifndef __vax__
220 const float x = -1.0L / 0.0L;
221 float y = sinhf(x);
222
223 ATF_CHECK(isinf(y) != 0);
224 ATF_CHECK(signbit(y) != 0);
225 #endif
226 }
227
228 ATF_TC(sinhf_inf_pos);
229 ATF_TC_HEAD(sinhf_inf_pos, tc)
230 {
231 atf_tc_set_md_var(tc, "descr", "Test sinhf(+Inf) == +Inf");
232 }
233
234 ATF_TC_BODY(sinhf_inf_pos, tc)
235 {
236 #ifndef __vax__
237 const float x = 1.0L / 0.0L;
238 float y = sinhf(x);
239
240 ATF_CHECK(isinf(y) != 0);
241 ATF_CHECK(signbit(y) == 0);
242 #endif
243 }
244
245 ATF_TC(sinhf_zero_neg);
246 ATF_TC_HEAD(sinhf_zero_neg, tc)
247 {
248 atf_tc_set_md_var(tc, "descr", "Test sinhf(-0.0) == -0.0");
249 }
250
251 ATF_TC_BODY(sinhf_zero_neg, tc)
252 {
253 #ifndef __vax__
254 const float x = -0.0L;
255 float y = sinhf(x);
256
257 if (fabsf(y) > 0.0 || signbit(y) == 0)
258 atf_tc_fail_nonfatal("sinhf(-0.0) != -0.0");
259 #endif
260 }
261
262 ATF_TC(sinhf_zero_pos);
263 ATF_TC_HEAD(sinhf_zero_pos, tc)
264 {
265 atf_tc_set_md_var(tc, "descr", "Test sinhf(+0.0) == +0.0");
266 }
267
268 ATF_TC_BODY(sinhf_zero_pos, tc)
269 {
270 #ifndef __vax__
271 const float x = 0.0L;
272 float y = sinhf(x);
273
274 if (fabsf(y) > 0.0 || signbit(y) != 0)
275 atf_tc_fail_nonfatal("sinhf(+0.0) != +0.0");
276 #endif
277 }
278
279 ATF_TP_ADD_TCS(tp)
280 {
281
282 ATF_TP_ADD_TC(tp, sinh_inrange);
283 ATF_TP_ADD_TC(tp, sinh_nan);
284 ATF_TP_ADD_TC(tp, sinh_inf_neg);
285 ATF_TP_ADD_TC(tp, sinh_inf_pos);
286 ATF_TP_ADD_TC(tp, sinh_zero_neg);
287 ATF_TP_ADD_TC(tp, sinh_zero_pos);
288
289 ATF_TP_ADD_TC(tp, sinhf_inrange);
290 ATF_TP_ADD_TC(tp, sinhf_nan);
291 ATF_TP_ADD_TC(tp, sinhf_inf_neg);
292 ATF_TP_ADD_TC(tp, sinhf_inf_pos);
293 ATF_TP_ADD_TC(tp, sinhf_zero_neg);
294 ATF_TP_ADD_TC(tp, sinhf_zero_pos);
295
296 return atf_no_error();
297 }
298