1 /* $NetBSD: t_pow.c,v 1.3 2014/03/03 10:39:08 martin 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_pow.c,v 1.3 2014/03/03 10:39:08 martin Exp $");
45 ATF_TC_HEAD(pow_nan_x, tc)
47 atf_tc_set_md_var(tc, "descr", "Test pow(NaN, y) == NaN");
50 ATF_TC_BODY(pow_nan_x, tc)
52 const double x = 0.0L / 0.0L;
54 ATF_CHECK(isnan(pow(x, 2.0)) != 0);
58 ATF_TC_HEAD(pow_nan_y, tc)
60 atf_tc_set_md_var(tc, "descr", "Test pow(x, NaN) == NaN");
63 ATF_TC_BODY(pow_nan_y, tc)
65 const double y = 0.0L / 0.0L;
67 ATF_CHECK(isnan(pow(2.0, y)) != 0);
70 ATF_TC(pow_inf_neg_x);
71 ATF_TC_HEAD(pow_inf_neg_x, tc)
73 atf_tc_set_md_var(tc, "descr", "Test pow(-Inf, y) == +-Inf || +-0.0");
76 ATF_TC_BODY(pow_inf_neg_x, tc)
78 const double x = -1.0L / 0.0L;
82 * If y is odd, y > 0, and x is -Inf, -Inf is returned.
83 * If y is even, y > 0, and x is -Inf, +Inf is returned.
87 if (isinf(z) == 0 || signbit(z) == 0)
88 atf_tc_fail_nonfatal("pow(-Inf, 3.0) != -Inf");
92 if (isinf(z) == 0 || signbit(z) != 0)
93 atf_tc_fail_nonfatal("pow(-Inf, 4.0) != +Inf");
96 * If y is odd, y < 0, and x is -Inf, -0.0 is returned.
97 * If y is even, y < 0, and x is -Inf, +0.0 is returned.
101 if (fabs(z) > 0.0 || signbit(z) == 0)
102 atf_tc_fail_nonfatal("pow(-Inf, -3.0) != -0.0");
106 if (fabs(z) > 0.0 || signbit(z) != 0)
107 atf_tc_fail_nonfatal("pow(-Inf -4.0) != +0.0");
110 ATF_TC(pow_inf_neg_y);
111 ATF_TC_HEAD(pow_inf_neg_y, tc)
113 atf_tc_set_md_var(tc, "descr", "Test pow(x, -Inf) == +Inf || +0.0");
116 ATF_TC_BODY(pow_inf_neg_y, tc)
118 const double y = -1.0L / 0.0L;
122 * If |x| < 1 and y is -Inf, +Inf is returned.
123 * If |x| > 1 and y is -Inf, +0.0 is returned.
127 if (isinf(z) == 0 || signbit(z) != 0)
128 atf_tc_fail_nonfatal("pow(0.1, -Inf) != +Inf");
132 if (fabs(z) > 0.0 || signbit(z) != 0)
133 atf_tc_fail_nonfatal("pow(1.1, -Inf) != +0.0");
136 ATF_TC(pow_inf_pos_x);
137 ATF_TC_HEAD(pow_inf_pos_x, tc)
139 atf_tc_set_md_var(tc, "descr", "Test pow(+Inf, y) == +Inf || +0.0");
142 ATF_TC_BODY(pow_inf_pos_x, tc)
144 const double x = 1.0L / 0.0L;
148 * For y < 0, if x is +Inf, +0.0 is returned.
149 * For y > 0, if x is +Inf, +Inf is returned.
153 if (fabs(z) > 0.0 || signbit(z) != 0)
154 atf_tc_fail_nonfatal("pow(+Inf, -2.0) != +0.0");
158 if (isinf(z) == 0 || signbit(z) != 0)
159 atf_tc_fail_nonfatal("pow(+Inf, 2.0) != +Inf");
162 ATF_TC(pow_inf_pos_y);
163 ATF_TC_HEAD(pow_inf_pos_y, tc)
165 atf_tc_set_md_var(tc, "descr", "Test pow(x, +Inf) == +Inf || +0.0");
168 ATF_TC_BODY(pow_inf_pos_y, tc)
170 const double y = 1.0L / 0.0L;
174 * If |x| < 1 and y is +Inf, +0.0 is returned.
175 * If |x| > 1 and y is +Inf, +Inf is returned.
179 if (fabs(z) > 0.0 || signbit(z) != 0)
180 atf_tc_fail_nonfatal("pow(0.1, +Inf) != +0.0");
184 if (isinf(z) == 0 || signbit(z) != 0)
185 atf_tc_fail_nonfatal("pow(1.1, +Inf) != +Inf");
188 ATF_TC(pow_one_neg_x);
189 ATF_TC_HEAD(pow_one_neg_x, tc)
191 atf_tc_set_md_var(tc, "descr", "Test pow(-1.0, +-Inf) == 1.0");
194 ATF_TC_BODY(pow_one_neg_x, tc)
196 const double infp = 1.0L / 0.0L;
197 const double infn = -1.0L / 0.0L;
200 * If x is -1.0, and y is +-Inf, 1.0 shall be returned.
202 ATF_REQUIRE(isinf(infp) != 0);
203 ATF_REQUIRE(isinf(infn) != 0);
205 if (pow(-1.0, infp) != 1.0) {
206 atf_tc_expect_fail("PR lib/45372");
207 atf_tc_fail_nonfatal("pow(-1.0, +Inf) != 1.0");
210 if (pow(-1.0, infn) != 1.0) {
211 atf_tc_expect_fail("PR lib/45372");
212 atf_tc_fail_nonfatal("pow(-1.0, -Inf) != 1.0");
216 ATF_TC(pow_one_pos_x);
217 ATF_TC_HEAD(pow_one_pos_x, tc)
219 atf_tc_set_md_var(tc, "descr", "Test pow(1.0, y) == 1.0");
222 ATF_TC_BODY(pow_one_pos_x, tc)
224 const double y[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 };
225 const double z = 0.0L / 0.0L;
229 * For any value of y (including NaN),
230 * if x is 1.0, 1.0 shall be returned.
232 if (pow(1.0, z) != 1.0)
233 atf_tc_fail_nonfatal("pow(1.0, NaN) != 1.0");
235 for (i = 0; i < __arraycount(y); i++) {
237 if (pow(1.0, y[i]) != 1.0)
238 atf_tc_fail_nonfatal("pow(1.0, %0.01f) != 1.0", y[i]);
243 ATF_TC_HEAD(pow_zero_x, tc)
245 atf_tc_set_md_var(tc, "descr", "Test pow(+-0.0, y) == +-0.0 || HUGE");
248 ATF_TC_BODY(pow_zero_x, tc)
253 * If x is +0.0 or -0.0, y > 0, and y
254 * is an odd integer, x is returned.
258 if (fabs(z) > 0.0 || signbit(z) != 0)
259 atf_tc_fail_nonfatal("pow(+0.0, 3.0) != +0.0");
263 if (fabs(z) > 0.0 || signbit(z) == 0)
264 atf_tc_fail_nonfatal("pow(-0.0, 3.0) != -0.0");
267 * If y > 0 and not an odd integer,
268 * if x is +0.0 or -0.0, +0.0 is returned.
272 if (fabs(z) > 0.0 || signbit(z) != 0)
273 atf_tc_fail_nonfatal("pow(+0.0, 4.0) != +0.0");
277 if (fabs(z) > 0.0 || signbit(z) != 0)
278 atf_tc_fail_nonfatal("pow(-0.0, 4.0) != +0.0");
281 * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL,
282 * +-HUGE_VALF, or +-HUGE_VALL shall be returned.
287 atf_tc_expect_fail("PR port-amd64/45391");
288 atf_tc_fail_nonfatal("pow(+0.0, -4.0) != HUGE_VAL");
294 atf_tc_expect_fail("PR port-amd64/45391");
295 atf_tc_fail_nonfatal("pow(-0.0, -4.0) != HUGE_VAL");
301 atf_tc_expect_fail("PR port-amd64/45391");
302 atf_tc_fail_nonfatal("pow(+0.0, -5.0) != HUGE_VAL");
308 atf_tc_fail_nonfatal("pow(-0.0, -5.0) != -HUGE_VAL");
312 ATF_TC_HEAD(pow_zero_y, tc)
314 atf_tc_set_md_var(tc, "descr", "Test pow(x, +-0.0) == 1.0");
317 ATF_TC_BODY(pow_zero_y, tc)
319 const double x[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 };
320 const double z = 0.0L / 0.0L;
324 * For any value of x (including NaN),
325 * if y is +0.0 or -0.0, 1.0 is returned.
327 if (pow(z, +0.0) != 1.0)
328 atf_tc_fail_nonfatal("pow(NaN, +0.0) != 1.0");
330 if (pow(z, -0.0) != 1.0)
331 atf_tc_fail_nonfatal("pow(NaN, -0.0) != 1.0");
333 for (i = 0; i < __arraycount(x); i++) {
335 if (pow(x[i], +0.0) != 1.0)
336 atf_tc_fail_nonfatal("pow(%0.01f, +0.0) != 1.0", x[i]);
338 if (pow(x[i], -0.0) != 1.0)
339 atf_tc_fail_nonfatal("pow(%0.01f, -0.0) != 1.0", x[i]);
347 ATF_TC_HEAD(powf_nan_x, tc)
349 atf_tc_set_md_var(tc, "descr", "Test powf(NaN, y) == NaN");
352 ATF_TC_BODY(powf_nan_x, tc)
354 const float x = 0.0L / 0.0L;
356 ATF_CHECK(isnanf(powf(x, 2.0)) != 0);
360 ATF_TC_HEAD(powf_nan_y, tc)
362 atf_tc_set_md_var(tc, "descr", "Test powf(x, NaN) == NaN");
365 ATF_TC_BODY(powf_nan_y, tc)
367 const float y = 0.0L / 0.0L;
369 ATF_CHECK(isnanf(powf(2.0, y)) != 0);
372 ATF_TC(powf_inf_neg_x);
373 ATF_TC_HEAD(powf_inf_neg_x, tc)
375 atf_tc_set_md_var(tc, "descr", "Test powf(-Inf, y) == +-Inf || +-0.0");
378 ATF_TC_BODY(powf_inf_neg_x, tc)
380 const float x = -1.0L / 0.0L;
384 * If y is odd, y > 0, and x is -Inf, -Inf is returned.
385 * If y is even, y > 0, and x is -Inf, +Inf is returned.
389 if (isinff(z) == 0 || signbit(z) == 0)
390 atf_tc_fail_nonfatal("powf(-Inf, 3.0) != -Inf");
394 if (isinff(z) == 0 || signbit(z) != 0)
395 atf_tc_fail_nonfatal("powf(-Inf, 4.0) != +Inf");
398 * If y is odd, y < 0, and x is -Inf, -0.0 is returned.
399 * If y is even, y < 0, and x is -Inf, +0.0 is returned.
403 if (fabsf(z) > 0.0 || signbit(z) == 0) {
404 atf_tc_expect_fail("PR lib/45372");
405 atf_tc_fail_nonfatal("powf(-Inf, -3.0) != -0.0");
410 if (fabsf(z) > 0.0 || signbit(z) != 0)
411 atf_tc_fail_nonfatal("powf(-Inf -4.0) != +0.0");
414 ATF_TC(powf_inf_neg_y);
415 ATF_TC_HEAD(powf_inf_neg_y, tc)
417 atf_tc_set_md_var(tc, "descr", "Test powf(x, -Inf) == +Inf || +0.0");
420 ATF_TC_BODY(powf_inf_neg_y, tc)
422 const float y = -1.0L / 0.0L;
426 * If |x| < 1 and y is -Inf, +Inf is returned.
427 * If |x| > 1 and y is -Inf, +0.0 is returned.
431 if (isinff(z) == 0 || signbit(z) != 0)
432 atf_tc_fail_nonfatal("powf(0.1, -Inf) != +Inf");
436 if (fabsf(z) > 0.0 || signbit(z) != 0)
437 atf_tc_fail_nonfatal("powf(1.1, -Inf) != +0.0");
440 ATF_TC(powf_inf_pos_x);
441 ATF_TC_HEAD(powf_inf_pos_x, tc)
443 atf_tc_set_md_var(tc, "descr", "Test powf(+Inf, y) == +Inf || +0.0");
446 ATF_TC_BODY(powf_inf_pos_x, tc)
448 const float x = 1.0L / 0.0L;
452 * For y < 0, if x is +Inf, +0.0 is returned.
453 * For y > 0, if x is +Inf, +Inf is returned.
457 if (fabsf(z) > 0.0 || signbit(z) != 0)
458 atf_tc_fail_nonfatal("powf(+Inf, -2.0) != +0.0");
462 if (isinff(z) == 0 || signbit(z) != 0)
463 atf_tc_fail_nonfatal("powf(+Inf, 2.0) != +Inf");
466 ATF_TC(powf_inf_pos_y);
467 ATF_TC_HEAD(powf_inf_pos_y, tc)
469 atf_tc_set_md_var(tc, "descr", "Test powf(x, +Inf) == +Inf || +0.0");
472 ATF_TC_BODY(powf_inf_pos_y, tc)
474 const float y = 1.0L / 0.0L;
478 * If |x| < 1 and y is +Inf, +0.0 is returned.
479 * If |x| > 1 and y is +Inf, +Inf is returned.
483 if (fabsf(z) > 0.0 || signbit(z) != 0)
484 atf_tc_fail_nonfatal("powf(0.1, +Inf) != +0.0");
488 if (isinff(z) == 0 || signbit(z) != 0)
489 atf_tc_fail_nonfatal("powf(1.1, +Inf) != +Inf");
492 ATF_TC(powf_one_neg_x);
493 ATF_TC_HEAD(powf_one_neg_x, tc)
495 atf_tc_set_md_var(tc, "descr", "Test powf(-1.0, +-Inf) == 1.0");
498 ATF_TC_BODY(powf_one_neg_x, tc)
500 const float infp = 1.0L / 0.0L;
501 const float infn = -1.0L / 0.0L;
504 * If x is -1.0, and y is +-Inf, 1.0 shall be returned.
506 ATF_REQUIRE(isinff(infp) != 0);
507 ATF_REQUIRE(isinff(infn) != 0);
509 if (powf(-1.0, infp) != 1.0) {
510 atf_tc_expect_fail("PR lib/45372");
511 atf_tc_fail_nonfatal("powf(-1.0, +Inf) != 1.0");
514 if (powf(-1.0, infn) != 1.0) {
515 atf_tc_expect_fail("PR lib/45372");
516 atf_tc_fail_nonfatal("powf(-1.0, -Inf) != 1.0");
520 ATF_TC(powf_one_pos_x);
521 ATF_TC_HEAD(powf_one_pos_x, tc)
523 atf_tc_set_md_var(tc, "descr", "Test powf(1.0, y) == 1.0");
526 ATF_TC_BODY(powf_one_pos_x, tc)
528 const float y[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 };
529 const float z = 0.0L / 0.0L;
533 * For any value of y (including NaN),
534 * if x is 1.0, 1.0 shall be returned.
536 if (powf(1.0, z) != 1.0)
537 atf_tc_fail_nonfatal("powf(1.0, NaN) != 1.0");
539 for (i = 0; i < __arraycount(y); i++) {
541 if (powf(1.0, y[i]) != 1.0)
542 atf_tc_fail_nonfatal("powf(1.0, %0.01f) != 1.0", y[i]);
547 ATF_TC_HEAD(powf_zero_x, tc)
549 atf_tc_set_md_var(tc, "descr", "Test powf(+-0.0, y) == +-0.0 || HUGE");
552 ATF_TC_BODY(powf_zero_x, tc)
557 * If x is +0.0 or -0.0, y > 0, and y
558 * is an odd integer, x is returned.
562 if (fabsf(z) > 0.0 || signbit(z) != 0)
563 atf_tc_fail_nonfatal("powf(+0.0, 3.0) != +0.0");
567 if (fabsf(z) > 0.0 || signbit(z) == 0)
568 atf_tc_fail_nonfatal("powf(-0.0, 3.0) != -0.0");
571 * If y > 0 and not an odd integer,
572 * if x is +0.0 or -0.0, +0.0 is returned.
576 if (fabsf(z) > 0.0 || signbit(z) != 0)
577 atf_tc_fail_nonfatal("powf(+0.0, 4.0) != +0.0");
581 if (fabsf(z) > 0.0 || signbit(z) != 0)
582 atf_tc_fail_nonfatal("powf(-0.0, 4.0) != +0.0");
585 * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL,
586 * +-HUGE_VALF, or +-HUGE_VALL shall be returned.
588 z = powf(+0.0, -4.0);
590 if (z != HUGE_VALF) {
591 atf_tc_expect_fail("PR port-amd64/45391");
592 atf_tc_fail_nonfatal("powf(+0.0, -4.0) != HUGE_VALF");
595 z = powf(-0.0, -4.0);
597 if (z != HUGE_VALF) {
598 atf_tc_expect_fail("PR port-amd64/45391");
599 atf_tc_fail_nonfatal("powf(-0.0, -4.0) != HUGE_VALF");
602 z = powf(+0.0, -5.0);
604 if (z != HUGE_VALF) {
605 atf_tc_expect_fail("PR port-amd64/45391");
606 atf_tc_fail_nonfatal("powf(+0.0, -5.0) != HUGE_VALF");
609 z = powf(-0.0, -5.0);
612 atf_tc_fail_nonfatal("powf(-0.0, -5.0) != -HUGE_VALF");
616 ATF_TC_HEAD(powf_zero_y, tc)
618 atf_tc_set_md_var(tc, "descr", "Test powf(x, +-0.0) == 1.0");
621 ATF_TC_BODY(powf_zero_y, tc)
623 const float x[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 };
624 const float z = 0.0L / 0.0L;
628 * For any value of x (including NaN),
629 * if y is +0.0 or -0.0, 1.0 is returned.
631 if (powf(z, +0.0) != 1.0)
632 atf_tc_fail_nonfatal("powf(NaN, +0.0) != 1.0");
634 if (powf(z, -0.0) != 1.0)
635 atf_tc_fail_nonfatal("powf(NaN, -0.0) != 1.0");
637 for (i = 0; i < __arraycount(x); i++) {
639 if (powf(x[i], +0.0) != 1.0)
640 atf_tc_fail_nonfatal("powf(%0.01f, +0.0) != 1.0",x[i]);
642 if (powf(x[i], -0.0) != 1.0)
643 atf_tc_fail_nonfatal("powf(%0.01f, -0.0) != 1.0",x[i]);
650 ATF_TP_ADD_TC(tp, pow_nan_x);
651 ATF_TP_ADD_TC(tp, pow_nan_y);
652 ATF_TP_ADD_TC(tp, pow_inf_neg_x);
653 ATF_TP_ADD_TC(tp, pow_inf_neg_y);
654 ATF_TP_ADD_TC(tp, pow_inf_pos_x);
655 ATF_TP_ADD_TC(tp, pow_inf_pos_y);
656 ATF_TP_ADD_TC(tp, pow_one_neg_x);
657 ATF_TP_ADD_TC(tp, pow_one_pos_x);
658 ATF_TP_ADD_TC(tp, pow_zero_x);
659 ATF_TP_ADD_TC(tp, pow_zero_y);
661 ATF_TP_ADD_TC(tp, powf_nan_x);
662 ATF_TP_ADD_TC(tp, powf_nan_y);
663 ATF_TP_ADD_TC(tp, powf_inf_neg_x);
664 ATF_TP_ADD_TC(tp, powf_inf_neg_y);
665 ATF_TP_ADD_TC(tp, powf_inf_pos_x);
666 ATF_TP_ADD_TC(tp, powf_inf_pos_y);
667 ATF_TP_ADD_TC(tp, powf_one_neg_x);
668 ATF_TP_ADD_TC(tp, powf_one_pos_x);
669 ATF_TP_ADD_TC(tp, powf_zero_x);
670 ATF_TP_ADD_TC(tp, powf_zero_y);
672 return atf_no_error();