1 /* $NetBSD: t_pow.c,v 1.4 2015/09/08 05:24:27 dholland 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.4 2015/09/08 05:24:27 dholland 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_fail_nonfatal("pow(+0.0, -4.0) != HUGE_VAL");
293 atf_tc_fail_nonfatal("pow(-0.0, -4.0) != HUGE_VAL");
299 atf_tc_fail_nonfatal("pow(+0.0, -5.0) != HUGE_VAL");
305 atf_tc_fail_nonfatal("pow(-0.0, -5.0) != -HUGE_VAL");
309 ATF_TC_HEAD(pow_zero_y, tc)
311 atf_tc_set_md_var(tc, "descr", "Test pow(x, +-0.0) == 1.0");
314 ATF_TC_BODY(pow_zero_y, tc)
316 const double x[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 };
317 const double z = 0.0L / 0.0L;
321 * For any value of x (including NaN),
322 * if y is +0.0 or -0.0, 1.0 is returned.
324 if (pow(z, +0.0) != 1.0)
325 atf_tc_fail_nonfatal("pow(NaN, +0.0) != 1.0");
327 if (pow(z, -0.0) != 1.0)
328 atf_tc_fail_nonfatal("pow(NaN, -0.0) != 1.0");
330 for (i = 0; i < __arraycount(x); i++) {
332 if (pow(x[i], +0.0) != 1.0)
333 atf_tc_fail_nonfatal("pow(%0.01f, +0.0) != 1.0", 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]);
344 ATF_TC_HEAD(powf_nan_x, tc)
346 atf_tc_set_md_var(tc, "descr", "Test powf(NaN, y) == NaN");
349 ATF_TC_BODY(powf_nan_x, tc)
351 const float x = 0.0L / 0.0L;
353 ATF_CHECK(isnanf(powf(x, 2.0)) != 0);
357 ATF_TC_HEAD(powf_nan_y, tc)
359 atf_tc_set_md_var(tc, "descr", "Test powf(x, NaN) == NaN");
362 ATF_TC_BODY(powf_nan_y, tc)
364 const float y = 0.0L / 0.0L;
366 ATF_CHECK(isnanf(powf(2.0, y)) != 0);
369 ATF_TC(powf_inf_neg_x);
370 ATF_TC_HEAD(powf_inf_neg_x, tc)
372 atf_tc_set_md_var(tc, "descr", "Test powf(-Inf, y) == +-Inf || +-0.0");
375 ATF_TC_BODY(powf_inf_neg_x, tc)
377 const float x = -1.0L / 0.0L;
381 * If y is odd, y > 0, and x is -Inf, -Inf is returned.
382 * If y is even, y > 0, and x is -Inf, +Inf is returned.
386 if (isinff(z) == 0 || signbit(z) == 0)
387 atf_tc_fail_nonfatal("powf(-Inf, 3.0) != -Inf");
391 if (isinff(z) == 0 || signbit(z) != 0)
392 atf_tc_fail_nonfatal("powf(-Inf, 4.0) != +Inf");
395 * If y is odd, y < 0, and x is -Inf, -0.0 is returned.
396 * If y is even, y < 0, and x is -Inf, +0.0 is returned.
400 if (fabsf(z) > 0.0 || signbit(z) == 0) {
401 atf_tc_expect_fail("PR lib/45372");
402 atf_tc_fail_nonfatal("powf(-Inf, -3.0) != -0.0");
407 if (fabsf(z) > 0.0 || signbit(z) != 0)
408 atf_tc_fail_nonfatal("powf(-Inf -4.0) != +0.0");
411 ATF_TC(powf_inf_neg_y);
412 ATF_TC_HEAD(powf_inf_neg_y, tc)
414 atf_tc_set_md_var(tc, "descr", "Test powf(x, -Inf) == +Inf || +0.0");
417 ATF_TC_BODY(powf_inf_neg_y, tc)
419 const float y = -1.0L / 0.0L;
423 * If |x| < 1 and y is -Inf, +Inf is returned.
424 * If |x| > 1 and y is -Inf, +0.0 is returned.
428 if (isinff(z) == 0 || signbit(z) != 0)
429 atf_tc_fail_nonfatal("powf(0.1, -Inf) != +Inf");
433 if (fabsf(z) > 0.0 || signbit(z) != 0)
434 atf_tc_fail_nonfatal("powf(1.1, -Inf) != +0.0");
437 ATF_TC(powf_inf_pos_x);
438 ATF_TC_HEAD(powf_inf_pos_x, tc)
440 atf_tc_set_md_var(tc, "descr", "Test powf(+Inf, y) == +Inf || +0.0");
443 ATF_TC_BODY(powf_inf_pos_x, tc)
445 const float x = 1.0L / 0.0L;
449 * For y < 0, if x is +Inf, +0.0 is returned.
450 * For y > 0, if x is +Inf, +Inf is returned.
454 if (fabsf(z) > 0.0 || signbit(z) != 0)
455 atf_tc_fail_nonfatal("powf(+Inf, -2.0) != +0.0");
459 if (isinff(z) == 0 || signbit(z) != 0)
460 atf_tc_fail_nonfatal("powf(+Inf, 2.0) != +Inf");
463 ATF_TC(powf_inf_pos_y);
464 ATF_TC_HEAD(powf_inf_pos_y, tc)
466 atf_tc_set_md_var(tc, "descr", "Test powf(x, +Inf) == +Inf || +0.0");
469 ATF_TC_BODY(powf_inf_pos_y, tc)
471 const float y = 1.0L / 0.0L;
475 * If |x| < 1 and y is +Inf, +0.0 is returned.
476 * If |x| > 1 and y is +Inf, +Inf is returned.
480 if (fabsf(z) > 0.0 || signbit(z) != 0)
481 atf_tc_fail_nonfatal("powf(0.1, +Inf) != +0.0");
485 if (isinff(z) == 0 || signbit(z) != 0)
486 atf_tc_fail_nonfatal("powf(1.1, +Inf) != +Inf");
489 ATF_TC(powf_one_neg_x);
490 ATF_TC_HEAD(powf_one_neg_x, tc)
492 atf_tc_set_md_var(tc, "descr", "Test powf(-1.0, +-Inf) == 1.0");
495 ATF_TC_BODY(powf_one_neg_x, tc)
497 const float infp = 1.0L / 0.0L;
498 const float infn = -1.0L / 0.0L;
501 * If x is -1.0, and y is +-Inf, 1.0 shall be returned.
503 ATF_REQUIRE(isinff(infp) != 0);
504 ATF_REQUIRE(isinff(infn) != 0);
506 if (powf(-1.0, infp) != 1.0) {
507 atf_tc_expect_fail("PR lib/45372");
508 atf_tc_fail_nonfatal("powf(-1.0, +Inf) != 1.0");
511 if (powf(-1.0, infn) != 1.0) {
512 atf_tc_expect_fail("PR lib/45372");
513 atf_tc_fail_nonfatal("powf(-1.0, -Inf) != 1.0");
517 ATF_TC(powf_one_pos_x);
518 ATF_TC_HEAD(powf_one_pos_x, tc)
520 atf_tc_set_md_var(tc, "descr", "Test powf(1.0, y) == 1.0");
523 ATF_TC_BODY(powf_one_pos_x, tc)
525 const float y[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 };
526 const float z = 0.0L / 0.0L;
530 * For any value of y (including NaN),
531 * if x is 1.0, 1.0 shall be returned.
533 if (powf(1.0, z) != 1.0)
534 atf_tc_fail_nonfatal("powf(1.0, NaN) != 1.0");
536 for (i = 0; i < __arraycount(y); i++) {
538 if (powf(1.0, y[i]) != 1.0)
539 atf_tc_fail_nonfatal("powf(1.0, %0.01f) != 1.0", y[i]);
544 ATF_TC_HEAD(powf_zero_x, tc)
546 atf_tc_set_md_var(tc, "descr", "Test powf(+-0.0, y) == +-0.0 || HUGE");
549 ATF_TC_BODY(powf_zero_x, tc)
554 * If x is +0.0 or -0.0, y > 0, and y
555 * is an odd integer, x is returned.
559 if (fabsf(z) > 0.0 || signbit(z) != 0)
560 atf_tc_fail_nonfatal("powf(+0.0, 3.0) != +0.0");
564 if (fabsf(z) > 0.0 || signbit(z) == 0)
565 atf_tc_fail_nonfatal("powf(-0.0, 3.0) != -0.0");
568 * If y > 0 and not an odd integer,
569 * if x is +0.0 or -0.0, +0.0 is returned.
573 if (fabsf(z) > 0.0 || signbit(z) != 0)
574 atf_tc_fail_nonfatal("powf(+0.0, 4.0) != +0.0");
578 if (fabsf(z) > 0.0 || signbit(z) != 0)
579 atf_tc_fail_nonfatal("powf(-0.0, 4.0) != +0.0");
582 * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL,
583 * +-HUGE_VALF, or +-HUGE_VALL shall be returned.
585 z = powf(+0.0, -4.0);
587 if (z != HUGE_VALF) {
588 atf_tc_expect_fail("PR port-amd64/45391");
589 atf_tc_fail_nonfatal("powf(+0.0, -4.0) != HUGE_VALF");
592 z = powf(-0.0, -4.0);
594 if (z != HUGE_VALF) {
595 atf_tc_expect_fail("PR port-amd64/45391");
596 atf_tc_fail_nonfatal("powf(-0.0, -4.0) != HUGE_VALF");
599 z = powf(+0.0, -5.0);
601 if (z != HUGE_VALF) {
602 atf_tc_expect_fail("PR port-amd64/45391");
603 atf_tc_fail_nonfatal("powf(+0.0, -5.0) != HUGE_VALF");
606 z = powf(-0.0, -5.0);
609 atf_tc_fail_nonfatal("powf(-0.0, -5.0) != -HUGE_VALF");
613 ATF_TC_HEAD(powf_zero_y, tc)
615 atf_tc_set_md_var(tc, "descr", "Test powf(x, +-0.0) == 1.0");
618 ATF_TC_BODY(powf_zero_y, tc)
620 const float x[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 };
621 const float z = 0.0L / 0.0L;
625 * For any value of x (including NaN),
626 * if y is +0.0 or -0.0, 1.0 is returned.
628 if (powf(z, +0.0) != 1.0)
629 atf_tc_fail_nonfatal("powf(NaN, +0.0) != 1.0");
631 if (powf(z, -0.0) != 1.0)
632 atf_tc_fail_nonfatal("powf(NaN, -0.0) != 1.0");
634 for (i = 0; i < __arraycount(x); i++) {
636 if (powf(x[i], +0.0) != 1.0)
637 atf_tc_fail_nonfatal("powf(%0.01f, +0.0) != 1.0",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]);
647 ATF_TP_ADD_TC(tp, pow_nan_x);
648 ATF_TP_ADD_TC(tp, pow_nan_y);
649 ATF_TP_ADD_TC(tp, pow_inf_neg_x);
650 ATF_TP_ADD_TC(tp, pow_inf_neg_y);
651 ATF_TP_ADD_TC(tp, pow_inf_pos_x);
652 ATF_TP_ADD_TC(tp, pow_inf_pos_y);
653 ATF_TP_ADD_TC(tp, pow_one_neg_x);
654 ATF_TP_ADD_TC(tp, pow_one_pos_x);
655 ATF_TP_ADD_TC(tp, pow_zero_x);
656 ATF_TP_ADD_TC(tp, pow_zero_y);
658 ATF_TP_ADD_TC(tp, powf_nan_x);
659 ATF_TP_ADD_TC(tp, powf_nan_y);
660 ATF_TP_ADD_TC(tp, powf_inf_neg_x);
661 ATF_TP_ADD_TC(tp, powf_inf_neg_y);
662 ATF_TP_ADD_TC(tp, powf_inf_pos_x);
663 ATF_TP_ADD_TC(tp, powf_inf_pos_y);
664 ATF_TP_ADD_TC(tp, powf_one_neg_x);
665 ATF_TP_ADD_TC(tp, powf_one_pos_x);
666 ATF_TP_ADD_TC(tp, powf_zero_x);
667 ATF_TP_ADD_TC(tp, powf_zero_y);
669 return atf_no_error();