1 /* $NetBSD: t_cbrt.c,v 1.2 2013/11/19 19:24:33 joerg Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_cbrt.c,v 1.2 2013/11/19 19:24:33 joerg Exp $");
42 ATF_TC_HEAD(cbrt_nan
, tc
)
44 atf_tc_set_md_var(tc
, "descr", "Test cbrt(NaN) == NaN");
47 ATF_TC_BODY(cbrt_nan
, tc
)
50 const double x
= 0.0L / 0.0L;
52 ATF_CHECK(isnan(x
) != 0);
53 ATF_CHECK(isnan(cbrt(x
)) != 0);
58 ATF_TC_HEAD(cbrt_pow
, tc
)
60 atf_tc_set_md_var(tc
, "descr", "Test cbrt(3) vs. pow(3)");
63 ATF_TC_BODY(cbrt_pow
, tc
)
66 const double x
[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
67 const double eps
= 1.0e-14;
71 for (i
= 0; i
< __arraycount(x
); i
++) {
74 z
= pow(x
[i
], 1.0 / 3.0);
76 if (fabs(y
- z
) > eps
)
77 atf_tc_fail_nonfatal("cbrt(%0.03f) != "
78 "pow(%0.03f, 1/3)\n", x
[i
], x
[i
]);
84 ATF_TC_HEAD(cbrt_inf_neg
, tc
)
86 atf_tc_set_md_var(tc
, "descr", "Test cbrt(-Inf) == -Inf");
89 ATF_TC_BODY(cbrt_inf_neg
, tc
)
92 const double x
= -1.0L / 0.0L;
95 ATF_CHECK(isinf(y
) != 0);
96 ATF_CHECK(signbit(y
) != 0);
100 ATF_TC(cbrt_inf_pos
);
101 ATF_TC_HEAD(cbrt_inf_pos
, tc
)
103 atf_tc_set_md_var(tc
, "descr", "Test cbrt(+Inf) == +Inf");
106 ATF_TC_BODY(cbrt_inf_pos
, tc
)
109 const double x
= 1.0L / 0.0L;
112 ATF_CHECK(isinf(y
) != 0);
113 ATF_CHECK(signbit(y
) == 0);
117 ATF_TC(cbrt_zero_neg
);
118 ATF_TC_HEAD(cbrt_zero_neg
, tc
)
120 atf_tc_set_md_var(tc
, "descr", "Test cbrt(-0.0) == -0.0");
123 ATF_TC_BODY(cbrt_zero_neg
, tc
)
126 const double x
= -0.0L;
129 if (fabs(y
) > 0.0 || signbit(y
) == 0)
130 atf_tc_fail_nonfatal("cbrt(-0.0) != -0.0");
134 ATF_TC(cbrt_zero_pos
);
135 ATF_TC_HEAD(cbrt_zero_pos
, tc
)
137 atf_tc_set_md_var(tc
, "descr", "Test cbrt(+0.0) == +0.0");
140 ATF_TC_BODY(cbrt_zero_pos
, tc
)
143 const double x
= 0.0L;
146 if (fabs(y
) > 0.0 || signbit(y
) != 0)
147 atf_tc_fail_nonfatal("cbrt(+0.0) != +0.0");
155 ATF_TC_HEAD(cbrtf_nan
, tc
)
157 atf_tc_set_md_var(tc
, "descr", "Test cbrtf(NaN) == NaN");
160 ATF_TC_BODY(cbrtf_nan
, tc
)
163 const float x
= 0.0L / 0.0L;
165 ATF_CHECK(isnan(x
) != 0);
166 ATF_CHECK(isnan(cbrtf(x
)) != 0);
171 ATF_TC_HEAD(cbrtf_powf
, tc
)
173 atf_tc_set_md_var(tc
, "descr", "Test cbrtf(3) vs. powf(3)");
176 ATF_TC_BODY(cbrtf_powf
, tc
)
179 const float x
[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
180 const float eps
= 1.0e-5;
184 for (i
= 0; i
< __arraycount(x
); i
++) {
187 z
= powf(x
[i
], 1.0 / 3.0);
189 if (fabsf(y
- z
) > eps
)
190 atf_tc_fail_nonfatal("cbrtf(%0.03f) != "
191 "powf(%0.03f, 1/3)\n", x
[i
], x
[i
]);
196 ATF_TC(cbrtf_inf_neg
);
197 ATF_TC_HEAD(cbrtf_inf_neg
, tc
)
199 atf_tc_set_md_var(tc
, "descr", "Test cbrtf(-Inf) == -Inf");
202 ATF_TC_BODY(cbrtf_inf_neg
, tc
)
205 const float x
= -1.0L / 0.0L;
208 ATF_CHECK(isinf(y
) != 0);
209 ATF_CHECK(signbit(y
) != 0);
213 ATF_TC(cbrtf_inf_pos
);
214 ATF_TC_HEAD(cbrtf_inf_pos
, tc
)
216 atf_tc_set_md_var(tc
, "descr", "Test cbrtf(+Inf) == +Inf");
219 ATF_TC_BODY(cbrtf_inf_pos
, tc
)
222 const float x
= 1.0L / 0.0L;
225 ATF_CHECK(isinf(y
) != 0);
226 ATF_CHECK(signbit(y
) == 0);
230 ATF_TC(cbrtf_zero_neg
);
231 ATF_TC_HEAD(cbrtf_zero_neg
, tc
)
233 atf_tc_set_md_var(tc
, "descr", "Test cbrtf(-0.0) == -0.0");
236 ATF_TC_BODY(cbrtf_zero_neg
, tc
)
239 const float x
= -0.0L;
242 if (fabsf(y
) > 0.0 || signbit(y
) == 0)
243 atf_tc_fail_nonfatal("cbrtf(-0.0) != -0.0");
247 ATF_TC(cbrtf_zero_pos
);
248 ATF_TC_HEAD(cbrtf_zero_pos
, tc
)
250 atf_tc_set_md_var(tc
, "descr", "Test cbrtf(+0.0) == +0.0");
253 ATF_TC_BODY(cbrtf_zero_pos
, tc
)
256 const float x
= 0.0L;
259 if (fabsf(y
) > 0.0 || signbit(y
) != 0)
260 atf_tc_fail_nonfatal("cbrtf(+0.0) != +0.0");
268 ATF_TC_HEAD(cbrtl_nan
, tc
)
270 atf_tc_set_md_var(tc
, "descr", "Test cbrtl(NaN) == NaN");
273 ATF_TC_BODY(cbrtl_nan
, tc
)
276 const long double x
= 0.0L / 0.0L;
278 ATF_CHECK(isnan(x
) != 0);
279 ATF_CHECK(isnan(cbrtl(x
)) != 0);
284 ATF_TC_HEAD(cbrtl_powl
, tc
)
286 atf_tc_set_md_var(tc
, "descr", "Test cbrtl(3) vs. powl(3)");
289 ATF_TC_BODY(cbrtl_powl
, tc
)
292 const long double x
[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
293 const long double eps
= 1.0e-15;
297 for (i
= 0; i
< __arraycount(x
); i
++) {
300 z
= powl(x
[i
], 1.0 / 3.0);
302 if (fabsl(y
- z
) > eps
* fabsl(1 + x
[i
]))
303 atf_tc_fail_nonfatal("cbrtl(%0.03Lf) != "
304 "powl(%0.03Lf, 1/3)\n", x
[i
], x
[i
]);
309 ATF_TC(cbrtl_inf_neg
);
310 ATF_TC_HEAD(cbrtl_inf_neg
, tc
)
312 atf_tc_set_md_var(tc
, "descr", "Test cbrtl(-Inf) == -Inf");
315 ATF_TC_BODY(cbrtl_inf_neg
, tc
)
318 const long double x
= -1.0L / 0.0L;
319 long double y
= cbrtl(x
);
321 ATF_CHECK(isinf(y
) != 0);
322 ATF_CHECK(signbit(y
) != 0);
326 ATF_TC(cbrtl_inf_pos
);
327 ATF_TC_HEAD(cbrtl_inf_pos
, tc
)
329 atf_tc_set_md_var(tc
, "descr", "Test cbrtl(+Inf) == +Inf");
332 ATF_TC_BODY(cbrtl_inf_pos
, tc
)
335 const long double x
= 1.0L / 0.0L;
336 long double y
= cbrtl(x
);
338 ATF_CHECK(isinf(y
) != 0);
339 ATF_CHECK(signbit(y
) == 0);
343 ATF_TC(cbrtl_zero_neg
);
344 ATF_TC_HEAD(cbrtl_zero_neg
, tc
)
346 atf_tc_set_md_var(tc
, "descr", "Test cbrtl(-0.0) == -0.0");
349 ATF_TC_BODY(cbrtl_zero_neg
, tc
)
352 const long double x
= -0.0L;
353 long double y
= cbrtl(x
);
355 if (fabsl(y
) > 0.0 || signbit(y
) == 0)
356 atf_tc_fail_nonfatal("cbrtl(-0.0) != -0.0");
360 ATF_TC(cbrtl_zero_pos
);
361 ATF_TC_HEAD(cbrtl_zero_pos
, tc
)
363 atf_tc_set_md_var(tc
, "descr", "Test cbrtl(+0.0) == +0.0");
366 ATF_TC_BODY(cbrtl_zero_pos
, tc
)
369 const long double x
= 0.0L;
370 long double y
= cbrtl(x
);
372 if (fabsl(y
) > 0.0 || signbit(y
) != 0)
373 atf_tc_fail_nonfatal("cbrtl(+0.0) != +0.0");
380 ATF_TP_ADD_TC(tp
, cbrt_nan
);
381 ATF_TP_ADD_TC(tp
, cbrt_pow
);
382 ATF_TP_ADD_TC(tp
, cbrt_inf_neg
);
383 ATF_TP_ADD_TC(tp
, cbrt_inf_pos
);
384 ATF_TP_ADD_TC(tp
, cbrt_zero_neg
);
385 ATF_TP_ADD_TC(tp
, cbrt_zero_pos
);
387 ATF_TP_ADD_TC(tp
, cbrtf_nan
);
388 ATF_TP_ADD_TC(tp
, cbrtf_powf
);
389 ATF_TP_ADD_TC(tp
, cbrtf_inf_neg
);
390 ATF_TP_ADD_TC(tp
, cbrtf_inf_pos
);
391 ATF_TP_ADD_TC(tp
, cbrtf_zero_neg
);
392 ATF_TP_ADD_TC(tp
, cbrtf_zero_pos
);
394 ATF_TP_ADD_TC(tp
, cbrtl_nan
);
395 ATF_TP_ADD_TC(tp
, cbrtl_powl
);
396 ATF_TP_ADD_TC(tp
, cbrtl_inf_neg
);
397 ATF_TP_ADD_TC(tp
, cbrtl_inf_pos
);
398 ATF_TP_ADD_TC(tp
, cbrtl_zero_neg
);
399 ATF_TP_ADD_TC(tp
, cbrtl_zero_pos
);
401 return atf_no_error();