1 /* $NetBSD: t_pow.c,v 1.2 2011/09/23 13:48:28 jruoho 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.2 2011/09/23 13:48:28 jruoho Exp $");
41 ATF_TC_HEAD(pow_nan_x
, tc
)
43 atf_tc_set_md_var(tc
, "descr", "Test pow(NaN, y) == NaN");
46 ATF_TC_BODY(pow_nan_x
, tc
)
49 const double x
= 0.0L / 0.0L;
51 ATF_CHECK(isnan(pow(x
, 2.0)) != 0);
56 ATF_TC_HEAD(pow_nan_y
, tc
)
58 atf_tc_set_md_var(tc
, "descr", "Test pow(x, NaN) == NaN");
61 ATF_TC_BODY(pow_nan_y
, tc
)
64 const double y
= 0.0L / 0.0L;
66 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
)
79 const double x
= -1.0L / 0.0L;
83 * If y is odd, y > 0, and x is -Inf, -Inf is returned.
84 * If y is even, y > 0, and x is -Inf, +Inf is returned.
88 if (isinf(z
) == 0 || signbit(z
) == 0)
89 atf_tc_fail_nonfatal("pow(-Inf, 3.0) != -Inf");
93 if (isinf(z
) == 0 || signbit(z
) != 0)
94 atf_tc_fail_nonfatal("pow(-Inf, 4.0) != +Inf");
97 * If y is odd, y < 0, and x is -Inf, -0.0 is returned.
98 * If y is even, y < 0, and x is -Inf, +0.0 is returned.
102 if (fabs(z
) > 0.0 || signbit(z
) == 0)
103 atf_tc_fail_nonfatal("pow(-Inf, -3.0) != -0.0");
107 if (fabs(z
) > 0.0 || signbit(z
) != 0)
108 atf_tc_fail_nonfatal("pow(-Inf -4.0) != +0.0");
112 ATF_TC(pow_inf_neg_y
);
113 ATF_TC_HEAD(pow_inf_neg_y
, tc
)
115 atf_tc_set_md_var(tc
, "descr", "Test pow(x, -Inf) == +Inf || +0.0");
118 ATF_TC_BODY(pow_inf_neg_y
, tc
)
121 const double y
= -1.0L / 0.0L;
125 * If |x| < 1 and y is -Inf, +Inf is returned.
126 * If |x| > 1 and y is -Inf, +0.0 is returned.
130 if (isinf(z
) == 0 || signbit(z
) != 0)
131 atf_tc_fail_nonfatal("pow(0.1, -Inf) != +Inf");
135 if (fabs(z
) > 0.0 || signbit(z
) != 0)
136 atf_tc_fail_nonfatal("pow(1.1, -Inf) != +0.0");
140 ATF_TC(pow_inf_pos_x
);
141 ATF_TC_HEAD(pow_inf_pos_x
, tc
)
143 atf_tc_set_md_var(tc
, "descr", "Test pow(+Inf, y) == +Inf || +0.0");
146 ATF_TC_BODY(pow_inf_pos_x
, tc
)
149 const double x
= 1.0L / 0.0L;
153 * For y < 0, if x is +Inf, +0.0 is returned.
154 * For y > 0, if x is +Inf, +Inf is returned.
158 if (fabs(z
) > 0.0 || signbit(z
) != 0)
159 atf_tc_fail_nonfatal("pow(+Inf, -2.0) != +0.0");
163 if (isinf(z
) == 0 || signbit(z
) != 0)
164 atf_tc_fail_nonfatal("pow(+Inf, 2.0) != +Inf");
168 ATF_TC(pow_inf_pos_y
);
169 ATF_TC_HEAD(pow_inf_pos_y
, tc
)
171 atf_tc_set_md_var(tc
, "descr", "Test pow(x, +Inf) == +Inf || +0.0");
174 ATF_TC_BODY(pow_inf_pos_y
, tc
)
177 const double y
= 1.0L / 0.0L;
181 * If |x| < 1 and y is +Inf, +0.0 is returned.
182 * If |x| > 1 and y is +Inf, +Inf is returned.
186 if (fabs(z
) > 0.0 || signbit(z
) != 0)
187 atf_tc_fail_nonfatal("pow(0.1, +Inf) != +0.0");
191 if (isinf(z
) == 0 || signbit(z
) != 0)
192 atf_tc_fail_nonfatal("pow(1.1, +Inf) != +Inf");
196 ATF_TC(pow_one_neg_x
);
197 ATF_TC_HEAD(pow_one_neg_x
, tc
)
199 atf_tc_set_md_var(tc
, "descr", "Test pow(-1.0, +-Inf) == 1.0");
202 ATF_TC_BODY(pow_one_neg_x
, tc
)
205 const double infp
= 1.0L / 0.0L;
206 const double infn
= -1.0L / 0.0L;
209 * If x is -1.0, and y is +-Inf, 1.0 shall be returned.
211 ATF_REQUIRE(isinf(infp
) != 0);
212 ATF_REQUIRE(isinf(infn
) != 0);
214 if (pow(-1.0, infp
) != 1.0) {
215 atf_tc_expect_fail("PR lib/45372");
216 atf_tc_fail_nonfatal("pow(-1.0, +Inf) != 1.0");
219 if (pow(-1.0, infn
) != 1.0) {
220 atf_tc_expect_fail("PR lib/45372");
221 atf_tc_fail_nonfatal("pow(-1.0, -Inf) != 1.0");
226 ATF_TC(pow_one_pos_x
);
227 ATF_TC_HEAD(pow_one_pos_x
, tc
)
229 atf_tc_set_md_var(tc
, "descr", "Test pow(1.0, y) == 1.0");
232 ATF_TC_BODY(pow_one_pos_x
, tc
)
235 const double y
[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 };
236 const double z
= 0.0L / 0.0L;
240 * For any value of y (including NaN),
241 * if x is 1.0, 1.0 shall be returned.
243 if (pow(1.0, z
) != 1.0)
244 atf_tc_fail_nonfatal("pow(1.0, NaN) != 1.0");
246 for (i
= 0; i
< __arraycount(y
); i
++) {
248 if (pow(1.0, y
[i
]) != 1.0)
249 atf_tc_fail_nonfatal("pow(1.0, %0.01f) != 1.0", y
[i
]);
255 ATF_TC_HEAD(pow_zero_x
, tc
)
257 atf_tc_set_md_var(tc
, "descr", "Test pow(+-0.0, y) == +-0.0 || HUGE");
260 ATF_TC_BODY(pow_zero_x
, tc
)
266 * If x is +0.0 or -0.0, y > 0, and y
267 * is an odd integer, x is returned.
271 if (fabs(z
) > 0.0 || signbit(z
) != 0)
272 atf_tc_fail_nonfatal("pow(+0.0, 3.0) != +0.0");
276 if (fabs(z
) > 0.0 || signbit(z
) == 0)
277 atf_tc_fail_nonfatal("pow(-0.0, 3.0) != -0.0");
280 * If y > 0 and not an odd integer,
281 * if x is +0.0 or -0.0, +0.0 is returned.
285 if (fabs(z
) > 0.0 || signbit(z
) != 0)
286 atf_tc_fail_nonfatal("pow(+0.0, 4.0) != +0.0");
290 if (fabs(z
) > 0.0 || signbit(z
) != 0)
291 atf_tc_fail_nonfatal("pow(-0.0, 4.0) != +0.0");
294 * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL,
295 * +-HUGE_VALF, or +-HUGE_VALL shall be returned.
300 atf_tc_expect_fail("PR port-amd64/45391");
301 atf_tc_fail_nonfatal("pow(+0.0, -4.0) != HUGE_VAL");
307 atf_tc_expect_fail("PR port-amd64/45391");
308 atf_tc_fail_nonfatal("pow(-0.0, -4.0) != HUGE_VAL");
314 atf_tc_expect_fail("PR port-amd64/45391");
315 atf_tc_fail_nonfatal("pow(+0.0, -5.0) != HUGE_VAL");
321 atf_tc_fail_nonfatal("pow(-0.0, -5.0) != -HUGE_VAL");
326 ATF_TC_HEAD(pow_zero_y
, tc
)
328 atf_tc_set_md_var(tc
, "descr", "Test pow(x, +-0.0) == 1.0");
331 ATF_TC_BODY(pow_zero_y
, tc
)
334 const double x
[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 };
335 const double z
= 0.0L / 0.0L;
339 * For any value of x (including NaN),
340 * if y is +0.0 or -0.0, 1.0 is returned.
342 if (pow(z
, +0.0) != 1.0)
343 atf_tc_fail_nonfatal("pow(NaN, +0.0) != 1.0");
345 if (pow(z
, -0.0) != 1.0)
346 atf_tc_fail_nonfatal("pow(NaN, -0.0) != 1.0");
348 for (i
= 0; i
< __arraycount(x
); i
++) {
350 if (pow(x
[i
], +0.0) != 1.0)
351 atf_tc_fail_nonfatal("pow(%0.01f, +0.0) != 1.0", x
[i
]);
353 if (pow(x
[i
], -0.0) != 1.0)
354 atf_tc_fail_nonfatal("pow(%0.01f, -0.0) != 1.0", x
[i
]);
363 ATF_TC_HEAD(powf_nan_x
, tc
)
365 atf_tc_set_md_var(tc
, "descr", "Test powf(NaN, y) == NaN");
368 ATF_TC_BODY(powf_nan_x
, tc
)
371 const float x
= 0.0L / 0.0L;
373 ATF_CHECK(isnanf(powf(x
, 2.0)) != 0);
378 ATF_TC_HEAD(powf_nan_y
, tc
)
380 atf_tc_set_md_var(tc
, "descr", "Test powf(x, NaN) == NaN");
383 ATF_TC_BODY(powf_nan_y
, tc
)
386 const float y
= 0.0L / 0.0L;
388 ATF_CHECK(isnanf(powf(2.0, y
)) != 0);
392 ATF_TC(powf_inf_neg_x
);
393 ATF_TC_HEAD(powf_inf_neg_x
, tc
)
395 atf_tc_set_md_var(tc
, "descr", "Test powf(-Inf, y) == +-Inf || +-0.0");
398 ATF_TC_BODY(powf_inf_neg_x
, tc
)
401 const float x
= -1.0L / 0.0L;
405 * If y is odd, y > 0, and x is -Inf, -Inf is returned.
406 * If y is even, y > 0, and x is -Inf, +Inf is returned.
410 if (isinff(z
) == 0 || signbit(z
) == 0)
411 atf_tc_fail_nonfatal("powf(-Inf, 3.0) != -Inf");
415 if (isinff(z
) == 0 || signbit(z
) != 0)
416 atf_tc_fail_nonfatal("powf(-Inf, 4.0) != +Inf");
419 * If y is odd, y < 0, and x is -Inf, -0.0 is returned.
420 * If y is even, y < 0, and x is -Inf, +0.0 is returned.
424 if (fabsf(z
) > 0.0 || signbit(z
) == 0) {
425 atf_tc_expect_fail("PR lib/45372");
426 atf_tc_fail_nonfatal("powf(-Inf, -3.0) != -0.0");
431 if (fabsf(z
) > 0.0 || signbit(z
) != 0)
432 atf_tc_fail_nonfatal("powf(-Inf -4.0) != +0.0");
436 ATF_TC(powf_inf_neg_y
);
437 ATF_TC_HEAD(powf_inf_neg_y
, tc
)
439 atf_tc_set_md_var(tc
, "descr", "Test powf(x, -Inf) == +Inf || +0.0");
442 ATF_TC_BODY(powf_inf_neg_y
, tc
)
445 const float y
= -1.0L / 0.0L;
449 * If |x| < 1 and y is -Inf, +Inf is returned.
450 * If |x| > 1 and y is -Inf, +0.0 is returned.
454 if (isinff(z
) == 0 || signbit(z
) != 0)
455 atf_tc_fail_nonfatal("powf(0.1, -Inf) != +Inf");
459 if (fabsf(z
) > 0.0 || signbit(z
) != 0)
460 atf_tc_fail_nonfatal("powf(1.1, -Inf) != +0.0");
464 ATF_TC(powf_inf_pos_x
);
465 ATF_TC_HEAD(powf_inf_pos_x
, tc
)
467 atf_tc_set_md_var(tc
, "descr", "Test powf(+Inf, y) == +Inf || +0.0");
470 ATF_TC_BODY(powf_inf_pos_x
, tc
)
473 const float x
= 1.0L / 0.0L;
477 * For y < 0, if x is +Inf, +0.0 is returned.
478 * For y > 0, if x is +Inf, +Inf is returned.
482 if (fabsf(z
) > 0.0 || signbit(z
) != 0)
483 atf_tc_fail_nonfatal("powf(+Inf, -2.0) != +0.0");
487 if (isinff(z
) == 0 || signbit(z
) != 0)
488 atf_tc_fail_nonfatal("powf(+Inf, 2.0) != +Inf");
492 ATF_TC(powf_inf_pos_y
);
493 ATF_TC_HEAD(powf_inf_pos_y
, tc
)
495 atf_tc_set_md_var(tc
, "descr", "Test powf(x, +Inf) == +Inf || +0.0");
498 ATF_TC_BODY(powf_inf_pos_y
, tc
)
501 const float y
= 1.0L / 0.0L;
505 * If |x| < 1 and y is +Inf, +0.0 is returned.
506 * If |x| > 1 and y is +Inf, +Inf is returned.
510 if (fabsf(z
) > 0.0 || signbit(z
) != 0)
511 atf_tc_fail_nonfatal("powf(0.1, +Inf) != +0.0");
515 if (isinff(z
) == 0 || signbit(z
) != 0)
516 atf_tc_fail_nonfatal("powf(1.1, +Inf) != +Inf");
520 ATF_TC(powf_one_neg_x
);
521 ATF_TC_HEAD(powf_one_neg_x
, tc
)
523 atf_tc_set_md_var(tc
, "descr", "Test powf(-1.0, +-Inf) == 1.0");
526 ATF_TC_BODY(powf_one_neg_x
, tc
)
529 const float infp
= 1.0L / 0.0L;
530 const float infn
= -1.0L / 0.0L;
533 * If x is -1.0, and y is +-Inf, 1.0 shall be returned.
535 ATF_REQUIRE(isinff(infp
) != 0);
536 ATF_REQUIRE(isinff(infn
) != 0);
538 if (powf(-1.0, infp
) != 1.0) {
539 atf_tc_expect_fail("PR lib/45372");
540 atf_tc_fail_nonfatal("powf(-1.0, +Inf) != 1.0");
543 if (powf(-1.0, infn
) != 1.0) {
544 atf_tc_expect_fail("PR lib/45372");
545 atf_tc_fail_nonfatal("powf(-1.0, -Inf) != 1.0");
550 ATF_TC(powf_one_pos_x
);
551 ATF_TC_HEAD(powf_one_pos_x
, tc
)
553 atf_tc_set_md_var(tc
, "descr", "Test powf(1.0, y) == 1.0");
556 ATF_TC_BODY(powf_one_pos_x
, tc
)
559 const float y
[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 };
560 const float z
= 0.0L / 0.0L;
564 * For any value of y (including NaN),
565 * if x is 1.0, 1.0 shall be returned.
567 if (powf(1.0, z
) != 1.0)
568 atf_tc_fail_nonfatal("powf(1.0, NaN) != 1.0");
570 for (i
= 0; i
< __arraycount(y
); i
++) {
572 if (powf(1.0, y
[i
]) != 1.0)
573 atf_tc_fail_nonfatal("powf(1.0, %0.01f) != 1.0", y
[i
]);
579 ATF_TC_HEAD(powf_zero_x
, tc
)
581 atf_tc_set_md_var(tc
, "descr", "Test powf(+-0.0, y) == +-0.0 || HUGE");
584 ATF_TC_BODY(powf_zero_x
, tc
)
590 * If x is +0.0 or -0.0, y > 0, and y
591 * is an odd integer, x is returned.
595 if (fabsf(z
) > 0.0 || signbit(z
) != 0)
596 atf_tc_fail_nonfatal("powf(+0.0, 3.0) != +0.0");
600 if (fabsf(z
) > 0.0 || signbit(z
) == 0)
601 atf_tc_fail_nonfatal("powf(-0.0, 3.0) != -0.0");
604 * If y > 0 and not an odd integer,
605 * if x is +0.0 or -0.0, +0.0 is returned.
609 if (fabsf(z
) > 0.0 || signbit(z
) != 0)
610 atf_tc_fail_nonfatal("powf(+0.0, 4.0) != +0.0");
614 if (fabsf(z
) > 0.0 || signbit(z
) != 0)
615 atf_tc_fail_nonfatal("powf(-0.0, 4.0) != +0.0");
618 * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL,
619 * +-HUGE_VALF, or +-HUGE_VALL shall be returned.
621 z
= powf(+0.0, -4.0);
623 if (z
!= HUGE_VALF
) {
624 atf_tc_expect_fail("PR port-amd64/45391");
625 atf_tc_fail_nonfatal("powf(+0.0, -4.0) != HUGE_VALF");
628 z
= powf(-0.0, -4.0);
630 if (z
!= HUGE_VALF
) {
631 atf_tc_expect_fail("PR port-amd64/45391");
632 atf_tc_fail_nonfatal("powf(-0.0, -4.0) != HUGE_VALF");
635 z
= powf(+0.0, -5.0);
637 if (z
!= HUGE_VALF
) {
638 atf_tc_expect_fail("PR port-amd64/45391");
639 atf_tc_fail_nonfatal("powf(+0.0, -5.0) != HUGE_VALF");
642 z
= powf(-0.0, -5.0);
645 atf_tc_fail_nonfatal("powf(-0.0, -5.0) != -HUGE_VALF");
650 ATF_TC_HEAD(powf_zero_y
, tc
)
652 atf_tc_set_md_var(tc
, "descr", "Test powf(x, +-0.0) == 1.0");
655 ATF_TC_BODY(powf_zero_y
, tc
)
658 const float x
[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 };
659 const float z
= 0.0L / 0.0L;
663 * For any value of x (including NaN),
664 * if y is +0.0 or -0.0, 1.0 is returned.
666 if (powf(z
, +0.0) != 1.0)
667 atf_tc_fail_nonfatal("powf(NaN, +0.0) != 1.0");
669 if (powf(z
, -0.0) != 1.0)
670 atf_tc_fail_nonfatal("powf(NaN, -0.0) != 1.0");
672 for (i
= 0; i
< __arraycount(x
); i
++) {
674 if (powf(x
[i
], +0.0) != 1.0)
675 atf_tc_fail_nonfatal("powf(%0.01f, +0.0) != 1.0",x
[i
]);
677 if (powf(x
[i
], -0.0) != 1.0)
678 atf_tc_fail_nonfatal("powf(%0.01f, -0.0) != 1.0",x
[i
]);
686 ATF_TP_ADD_TC(tp
, pow_nan_x
);
687 ATF_TP_ADD_TC(tp
, pow_nan_y
);
688 ATF_TP_ADD_TC(tp
, pow_inf_neg_x
);
689 ATF_TP_ADD_TC(tp
, pow_inf_neg_y
);
690 ATF_TP_ADD_TC(tp
, pow_inf_pos_x
);
691 ATF_TP_ADD_TC(tp
, pow_inf_pos_y
);
692 ATF_TP_ADD_TC(tp
, pow_one_neg_x
);
693 ATF_TP_ADD_TC(tp
, pow_one_pos_x
);
694 ATF_TP_ADD_TC(tp
, pow_zero_x
);
695 ATF_TP_ADD_TC(tp
, pow_zero_y
);
697 ATF_TP_ADD_TC(tp
, powf_nan_x
);
698 ATF_TP_ADD_TC(tp
, powf_nan_y
);
699 ATF_TP_ADD_TC(tp
, powf_inf_neg_x
);
700 ATF_TP_ADD_TC(tp
, powf_inf_neg_y
);
701 ATF_TP_ADD_TC(tp
, powf_inf_pos_x
);
702 ATF_TP_ADD_TC(tp
, powf_inf_pos_y
);
703 ATF_TP_ADD_TC(tp
, powf_one_neg_x
);
704 ATF_TP_ADD_TC(tp
, powf_one_pos_x
);
705 ATF_TP_ADD_TC(tp
, powf_zero_x
);
706 ATF_TP_ADD_TC(tp
, powf_zero_y
);
708 return atf_no_error();