Remove building with NOCRYPTO option
[minix3.git] / tests / lib / libm / t_pow.c
blobee513db27ddb235b075ea54670189f95400a21cf
1 /* $NetBSD: t_pow.c,v 1.4 2015/09/08 05:24:27 dholland Exp $ */
3 /*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jukka Ruohonen.
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.
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 $");
34 #include <atf-c.h>
35 #include <math.h>
38 * pow(3)
40 ATF_TC(pow_nan_x);
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)
48 const double x = 0.0L / 0.0L;
50 ATF_CHECK(isnan(pow(x, 2.0)) != 0);
53 ATF_TC(pow_nan_y);
54 ATF_TC_HEAD(pow_nan_y, tc)
56 atf_tc_set_md_var(tc, "descr", "Test pow(x, NaN) == NaN");
59 ATF_TC_BODY(pow_nan_y, tc)
61 const double y = 0.0L / 0.0L;
63 ATF_CHECK(isnan(pow(2.0, y)) != 0);
66 ATF_TC(pow_inf_neg_x);
67 ATF_TC_HEAD(pow_inf_neg_x, tc)
69 atf_tc_set_md_var(tc, "descr", "Test pow(-Inf, y) == +-Inf || +-0.0");
72 ATF_TC_BODY(pow_inf_neg_x, tc)
74 const double x = -1.0L / 0.0L;
75 double z;
78 * If y is odd, y > 0, and x is -Inf, -Inf is returned.
79 * If y is even, y > 0, and x is -Inf, +Inf is returned.
81 z = pow(x, 3.0);
83 if (isinf(z) == 0 || signbit(z) == 0)
84 atf_tc_fail_nonfatal("pow(-Inf, 3.0) != -Inf");
86 z = pow(x, 4.0);
88 if (isinf(z) == 0 || signbit(z) != 0)
89 atf_tc_fail_nonfatal("pow(-Inf, 4.0) != +Inf");
92 * If y is odd, y < 0, and x is -Inf, -0.0 is returned.
93 * If y is even, y < 0, and x is -Inf, +0.0 is returned.
95 z = pow(x, -3.0);
97 if (fabs(z) > 0.0 || signbit(z) == 0)
98 atf_tc_fail_nonfatal("pow(-Inf, -3.0) != -0.0");
100 z = pow(x, -4.0);
102 if (fabs(z) > 0.0 || signbit(z) != 0)
103 atf_tc_fail_nonfatal("pow(-Inf -4.0) != +0.0");
106 ATF_TC(pow_inf_neg_y);
107 ATF_TC_HEAD(pow_inf_neg_y, tc)
109 atf_tc_set_md_var(tc, "descr", "Test pow(x, -Inf) == +Inf || +0.0");
112 ATF_TC_BODY(pow_inf_neg_y, tc)
114 const double y = -1.0L / 0.0L;
115 double z;
118 * If |x| < 1 and y is -Inf, +Inf is returned.
119 * If |x| > 1 and y is -Inf, +0.0 is returned.
121 z = pow(0.1, y);
123 if (isinf(z) == 0 || signbit(z) != 0)
124 atf_tc_fail_nonfatal("pow(0.1, -Inf) != +Inf");
126 z = pow(1.1, y);
128 if (fabs(z) > 0.0 || signbit(z) != 0)
129 atf_tc_fail_nonfatal("pow(1.1, -Inf) != +0.0");
132 ATF_TC(pow_inf_pos_x);
133 ATF_TC_HEAD(pow_inf_pos_x, tc)
135 atf_tc_set_md_var(tc, "descr", "Test pow(+Inf, y) == +Inf || +0.0");
138 ATF_TC_BODY(pow_inf_pos_x, tc)
140 const double x = 1.0L / 0.0L;
141 double z;
144 * For y < 0, if x is +Inf, +0.0 is returned.
145 * For y > 0, if x is +Inf, +Inf is returned.
147 z = pow(x, -2.0);
149 if (fabs(z) > 0.0 || signbit(z) != 0)
150 atf_tc_fail_nonfatal("pow(+Inf, -2.0) != +0.0");
152 z = pow(x, 2.0);
154 if (isinf(z) == 0 || signbit(z) != 0)
155 atf_tc_fail_nonfatal("pow(+Inf, 2.0) != +Inf");
158 ATF_TC(pow_inf_pos_y);
159 ATF_TC_HEAD(pow_inf_pos_y, tc)
161 atf_tc_set_md_var(tc, "descr", "Test pow(x, +Inf) == +Inf || +0.0");
164 ATF_TC_BODY(pow_inf_pos_y, tc)
166 const double y = 1.0L / 0.0L;
167 double z;
170 * If |x| < 1 and y is +Inf, +0.0 is returned.
171 * If |x| > 1 and y is +Inf, +Inf is returned.
173 z = pow(0.1, y);
175 if (fabs(z) > 0.0 || signbit(z) != 0)
176 atf_tc_fail_nonfatal("pow(0.1, +Inf) != +0.0");
178 z = pow(1.1, y);
180 if (isinf(z) == 0 || signbit(z) != 0)
181 atf_tc_fail_nonfatal("pow(1.1, +Inf) != +Inf");
184 ATF_TC(pow_one_neg_x);
185 ATF_TC_HEAD(pow_one_neg_x, tc)
187 atf_tc_set_md_var(tc, "descr", "Test pow(-1.0, +-Inf) == 1.0");
190 ATF_TC_BODY(pow_one_neg_x, tc)
192 const double infp = 1.0L / 0.0L;
193 const double infn = -1.0L / 0.0L;
196 * If x is -1.0, and y is +-Inf, 1.0 shall be returned.
198 ATF_REQUIRE(isinf(infp) != 0);
199 ATF_REQUIRE(isinf(infn) != 0);
201 if (pow(-1.0, infp) != 1.0) {
202 atf_tc_expect_fail("PR lib/45372");
203 atf_tc_fail_nonfatal("pow(-1.0, +Inf) != 1.0");
206 if (pow(-1.0, infn) != 1.0) {
207 atf_tc_expect_fail("PR lib/45372");
208 atf_tc_fail_nonfatal("pow(-1.0, -Inf) != 1.0");
212 ATF_TC(pow_one_pos_x);
213 ATF_TC_HEAD(pow_one_pos_x, tc)
215 atf_tc_set_md_var(tc, "descr", "Test pow(1.0, y) == 1.0");
218 ATF_TC_BODY(pow_one_pos_x, tc)
220 const double y[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 };
221 const double z = 0.0L / 0.0L;
222 size_t i;
225 * For any value of y (including NaN),
226 * if x is 1.0, 1.0 shall be returned.
228 if (pow(1.0, z) != 1.0)
229 atf_tc_fail_nonfatal("pow(1.0, NaN) != 1.0");
231 for (i = 0; i < __arraycount(y); i++) {
233 if (pow(1.0, y[i]) != 1.0)
234 atf_tc_fail_nonfatal("pow(1.0, %0.01f) != 1.0", y[i]);
238 ATF_TC(pow_zero_x);
239 ATF_TC_HEAD(pow_zero_x, tc)
241 atf_tc_set_md_var(tc, "descr", "Test pow(+-0.0, y) == +-0.0 || HUGE");
244 ATF_TC_BODY(pow_zero_x, tc)
246 double z;
249 * If x is +0.0 or -0.0, y > 0, and y
250 * is an odd integer, x is returned.
252 z = pow(+0.0, 3.0);
254 if (fabs(z) > 0.0 || signbit(z) != 0)
255 atf_tc_fail_nonfatal("pow(+0.0, 3.0) != +0.0");
257 z = pow(-0.0, 3.0);
259 if (fabs(z) > 0.0 || signbit(z) == 0)
260 atf_tc_fail_nonfatal("pow(-0.0, 3.0) != -0.0");
263 * If y > 0 and not an odd integer,
264 * if x is +0.0 or -0.0, +0.0 is returned.
266 z = pow(+0.0, 4.0);
268 if (fabs(z) > 0.0 || signbit(z) != 0)
269 atf_tc_fail_nonfatal("pow(+0.0, 4.0) != +0.0");
271 z = pow(-0.0, 4.0);
273 if (fabs(z) > 0.0 || signbit(z) != 0)
274 atf_tc_fail_nonfatal("pow(-0.0, 4.0) != +0.0");
277 * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL,
278 * +-HUGE_VALF, or +-HUGE_VALL shall be returned.
280 z = pow(+0.0, -4.0);
282 if (z != HUGE_VAL) {
283 atf_tc_fail_nonfatal("pow(+0.0, -4.0) != HUGE_VAL");
286 z = pow(-0.0, -4.0);
288 if (z != HUGE_VAL) {
289 atf_tc_fail_nonfatal("pow(-0.0, -4.0) != HUGE_VAL");
292 z = pow(+0.0, -5.0);
294 if (z != HUGE_VAL) {
295 atf_tc_fail_nonfatal("pow(+0.0, -5.0) != HUGE_VAL");
298 z = pow(-0.0, -5.0);
300 if (z != -HUGE_VAL)
301 atf_tc_fail_nonfatal("pow(-0.0, -5.0) != -HUGE_VAL");
304 ATF_TC(pow_zero_y);
305 ATF_TC_HEAD(pow_zero_y, tc)
307 atf_tc_set_md_var(tc, "descr", "Test pow(x, +-0.0) == 1.0");
310 ATF_TC_BODY(pow_zero_y, tc)
312 const double x[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 };
313 const double z = 0.0L / 0.0L;
314 size_t i;
317 * For any value of x (including NaN),
318 * if y is +0.0 or -0.0, 1.0 is returned.
320 if (pow(z, +0.0) != 1.0)
321 atf_tc_fail_nonfatal("pow(NaN, +0.0) != 1.0");
323 if (pow(z, -0.0) != 1.0)
324 atf_tc_fail_nonfatal("pow(NaN, -0.0) != 1.0");
326 for (i = 0; i < __arraycount(x); i++) {
328 if (pow(x[i], +0.0) != 1.0)
329 atf_tc_fail_nonfatal("pow(%0.01f, +0.0) != 1.0", x[i]);
331 if (pow(x[i], -0.0) != 1.0)
332 atf_tc_fail_nonfatal("pow(%0.01f, -0.0) != 1.0", x[i]);
337 * powf(3)
339 ATF_TC(powf_nan_x);
340 ATF_TC_HEAD(powf_nan_x, tc)
342 atf_tc_set_md_var(tc, "descr", "Test powf(NaN, y) == NaN");
345 ATF_TC_BODY(powf_nan_x, tc)
347 const float x = 0.0L / 0.0L;
349 ATF_CHECK(isnanf(powf(x, 2.0)) != 0);
352 ATF_TC(powf_nan_y);
353 ATF_TC_HEAD(powf_nan_y, tc)
355 atf_tc_set_md_var(tc, "descr", "Test powf(x, NaN) == NaN");
358 ATF_TC_BODY(powf_nan_y, tc)
360 const float y = 0.0L / 0.0L;
362 ATF_CHECK(isnanf(powf(2.0, y)) != 0);
365 ATF_TC(powf_inf_neg_x);
366 ATF_TC_HEAD(powf_inf_neg_x, tc)
368 atf_tc_set_md_var(tc, "descr", "Test powf(-Inf, y) == +-Inf || +-0.0");
371 ATF_TC_BODY(powf_inf_neg_x, tc)
373 const float x = -1.0L / 0.0L;
374 float z;
377 * If y is odd, y > 0, and x is -Inf, -Inf is returned.
378 * If y is even, y > 0, and x is -Inf, +Inf is returned.
380 z = powf(x, 3.0);
382 if (isinff(z) == 0 || signbit(z) == 0)
383 atf_tc_fail_nonfatal("powf(-Inf, 3.0) != -Inf");
385 z = powf(x, 4.0);
387 if (isinff(z) == 0 || signbit(z) != 0)
388 atf_tc_fail_nonfatal("powf(-Inf, 4.0) != +Inf");
391 * If y is odd, y < 0, and x is -Inf, -0.0 is returned.
392 * If y is even, y < 0, and x is -Inf, +0.0 is returned.
394 z = powf(x, -3.0);
396 if (fabsf(z) > 0.0 || signbit(z) == 0) {
397 atf_tc_expect_fail("PR lib/45372");
398 atf_tc_fail_nonfatal("powf(-Inf, -3.0) != -0.0");
401 z = powf(x, -4.0);
403 if (fabsf(z) > 0.0 || signbit(z) != 0)
404 atf_tc_fail_nonfatal("powf(-Inf -4.0) != +0.0");
407 ATF_TC(powf_inf_neg_y);
408 ATF_TC_HEAD(powf_inf_neg_y, tc)
410 atf_tc_set_md_var(tc, "descr", "Test powf(x, -Inf) == +Inf || +0.0");
413 ATF_TC_BODY(powf_inf_neg_y, tc)
415 const float y = -1.0L / 0.0L;
416 float z;
419 * If |x| < 1 and y is -Inf, +Inf is returned.
420 * If |x| > 1 and y is -Inf, +0.0 is returned.
422 z = powf(0.1, y);
424 if (isinff(z) == 0 || signbit(z) != 0)
425 atf_tc_fail_nonfatal("powf(0.1, -Inf) != +Inf");
427 z = powf(1.1, y);
429 if (fabsf(z) > 0.0 || signbit(z) != 0)
430 atf_tc_fail_nonfatal("powf(1.1, -Inf) != +0.0");
433 ATF_TC(powf_inf_pos_x);
434 ATF_TC_HEAD(powf_inf_pos_x, tc)
436 atf_tc_set_md_var(tc, "descr", "Test powf(+Inf, y) == +Inf || +0.0");
439 ATF_TC_BODY(powf_inf_pos_x, tc)
441 const float x = 1.0L / 0.0L;
442 float z;
445 * For y < 0, if x is +Inf, +0.0 is returned.
446 * For y > 0, if x is +Inf, +Inf is returned.
448 z = powf(x, -2.0);
450 if (fabsf(z) > 0.0 || signbit(z) != 0)
451 atf_tc_fail_nonfatal("powf(+Inf, -2.0) != +0.0");
453 z = powf(x, 2.0);
455 if (isinff(z) == 0 || signbit(z) != 0)
456 atf_tc_fail_nonfatal("powf(+Inf, 2.0) != +Inf");
459 ATF_TC(powf_inf_pos_y);
460 ATF_TC_HEAD(powf_inf_pos_y, tc)
462 atf_tc_set_md_var(tc, "descr", "Test powf(x, +Inf) == +Inf || +0.0");
465 ATF_TC_BODY(powf_inf_pos_y, tc)
467 const float y = 1.0L / 0.0L;
468 float z;
471 * If |x| < 1 and y is +Inf, +0.0 is returned.
472 * If |x| > 1 and y is +Inf, +Inf is returned.
474 z = powf(0.1, y);
476 if (fabsf(z) > 0.0 || signbit(z) != 0)
477 atf_tc_fail_nonfatal("powf(0.1, +Inf) != +0.0");
479 z = powf(1.1, y);
481 if (isinff(z) == 0 || signbit(z) != 0)
482 atf_tc_fail_nonfatal("powf(1.1, +Inf) != +Inf");
485 ATF_TC(powf_one_neg_x);
486 ATF_TC_HEAD(powf_one_neg_x, tc)
488 atf_tc_set_md_var(tc, "descr", "Test powf(-1.0, +-Inf) == 1.0");
491 ATF_TC_BODY(powf_one_neg_x, tc)
493 const float infp = 1.0L / 0.0L;
494 const float infn = -1.0L / 0.0L;
497 * If x is -1.0, and y is +-Inf, 1.0 shall be returned.
499 ATF_REQUIRE(isinff(infp) != 0);
500 ATF_REQUIRE(isinff(infn) != 0);
502 if (powf(-1.0, infp) != 1.0) {
503 atf_tc_expect_fail("PR lib/45372");
504 atf_tc_fail_nonfatal("powf(-1.0, +Inf) != 1.0");
507 if (powf(-1.0, infn) != 1.0) {
508 atf_tc_expect_fail("PR lib/45372");
509 atf_tc_fail_nonfatal("powf(-1.0, -Inf) != 1.0");
513 ATF_TC(powf_one_pos_x);
514 ATF_TC_HEAD(powf_one_pos_x, tc)
516 atf_tc_set_md_var(tc, "descr", "Test powf(1.0, y) == 1.0");
519 ATF_TC_BODY(powf_one_pos_x, tc)
521 const float y[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 };
522 const float z = 0.0L / 0.0L;
523 size_t i;
526 * For any value of y (including NaN),
527 * if x is 1.0, 1.0 shall be returned.
529 if (powf(1.0, z) != 1.0)
530 atf_tc_fail_nonfatal("powf(1.0, NaN) != 1.0");
532 for (i = 0; i < __arraycount(y); i++) {
534 if (powf(1.0, y[i]) != 1.0)
535 atf_tc_fail_nonfatal("powf(1.0, %0.01f) != 1.0", y[i]);
539 ATF_TC(powf_zero_x);
540 ATF_TC_HEAD(powf_zero_x, tc)
542 atf_tc_set_md_var(tc, "descr", "Test powf(+-0.0, y) == +-0.0 || HUGE");
545 ATF_TC_BODY(powf_zero_x, tc)
547 float z;
550 * If x is +0.0 or -0.0, y > 0, and y
551 * is an odd integer, x is returned.
553 z = powf(+0.0, 3.0);
555 if (fabsf(z) > 0.0 || signbit(z) != 0)
556 atf_tc_fail_nonfatal("powf(+0.0, 3.0) != +0.0");
558 z = powf(-0.0, 3.0);
560 if (fabsf(z) > 0.0 || signbit(z) == 0)
561 atf_tc_fail_nonfatal("powf(-0.0, 3.0) != -0.0");
564 * If y > 0 and not an odd integer,
565 * if x is +0.0 or -0.0, +0.0 is returned.
567 z = powf(+0.0, 4.0);
569 if (fabsf(z) > 0.0 || signbit(z) != 0)
570 atf_tc_fail_nonfatal("powf(+0.0, 4.0) != +0.0");
572 z = powf(-0.0, 4.0);
574 if (fabsf(z) > 0.0 || signbit(z) != 0)
575 atf_tc_fail_nonfatal("powf(-0.0, 4.0) != +0.0");
578 * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL,
579 * +-HUGE_VALF, or +-HUGE_VALL shall be returned.
581 z = powf(+0.0, -4.0);
583 if (z != HUGE_VALF) {
584 atf_tc_expect_fail("PR port-amd64/45391");
585 atf_tc_fail_nonfatal("powf(+0.0, -4.0) != HUGE_VALF");
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, -5.0);
597 if (z != HUGE_VALF) {
598 atf_tc_expect_fail("PR port-amd64/45391");
599 atf_tc_fail_nonfatal("powf(+0.0, -5.0) != HUGE_VALF");
602 z = powf(-0.0, -5.0);
604 if (z != -HUGE_VALF)
605 atf_tc_fail_nonfatal("powf(-0.0, -5.0) != -HUGE_VALF");
608 ATF_TC(powf_zero_y);
609 ATF_TC_HEAD(powf_zero_y, tc)
611 atf_tc_set_md_var(tc, "descr", "Test powf(x, +-0.0) == 1.0");
614 ATF_TC_BODY(powf_zero_y, tc)
616 const float x[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 };
617 const float z = 0.0L / 0.0L;
618 size_t i;
621 * For any value of x (including NaN),
622 * if y is +0.0 or -0.0, 1.0 is returned.
624 if (powf(z, +0.0) != 1.0)
625 atf_tc_fail_nonfatal("powf(NaN, +0.0) != 1.0");
627 if (powf(z, -0.0) != 1.0)
628 atf_tc_fail_nonfatal("powf(NaN, -0.0) != 1.0");
630 for (i = 0; i < __arraycount(x); i++) {
632 if (powf(x[i], +0.0) != 1.0)
633 atf_tc_fail_nonfatal("powf(%0.01f, +0.0) != 1.0",x[i]);
635 if (powf(x[i], -0.0) != 1.0)
636 atf_tc_fail_nonfatal("powf(%0.01f, -0.0) != 1.0",x[i]);
640 ATF_TP_ADD_TCS(tp)
643 ATF_TP_ADD_TC(tp, pow_nan_x);
644 ATF_TP_ADD_TC(tp, pow_nan_y);
645 ATF_TP_ADD_TC(tp, pow_inf_neg_x);
646 ATF_TP_ADD_TC(tp, pow_inf_neg_y);
647 ATF_TP_ADD_TC(tp, pow_inf_pos_x);
648 ATF_TP_ADD_TC(tp, pow_inf_pos_y);
649 ATF_TP_ADD_TC(tp, pow_one_neg_x);
650 ATF_TP_ADD_TC(tp, pow_one_pos_x);
651 ATF_TP_ADD_TC(tp, pow_zero_x);
652 ATF_TP_ADD_TC(tp, pow_zero_y);
654 ATF_TP_ADD_TC(tp, powf_nan_x);
655 ATF_TP_ADD_TC(tp, powf_nan_y);
656 ATF_TP_ADD_TC(tp, powf_inf_neg_x);
657 ATF_TP_ADD_TC(tp, powf_inf_neg_y);
658 ATF_TP_ADD_TC(tp, powf_inf_pos_x);
659 ATF_TP_ADD_TC(tp, powf_inf_pos_y);
660 ATF_TP_ADD_TC(tp, powf_one_neg_x);
661 ATF_TP_ADD_TC(tp, powf_one_pos_x);
662 ATF_TP_ADD_TC(tp, powf_zero_x);
663 ATF_TP_ADD_TC(tp, powf_zero_y);
665 return atf_no_error();