diff --git a/contrib/netbsd-tests/lib/libm/t_pow.c b/contrib/netbsd-tests/lib/libm/t_pow.c index 7afee9f6dffa..09e72be7311b 100644 --- a/contrib/netbsd-tests/lib/libm/t_pow.c +++ b/contrib/netbsd-tests/lib/libm/t_pow.c @@ -1,666 +1,688 @@ /* $NetBSD: t_pow.c,v 1.5 2017/01/20 21:15:56 maya Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_pow.c,v 1.5 2017/01/20 21:15:56 maya Exp $"); #include #include /* * pow(3) */ ATF_TC(pow_nan_x); ATF_TC_HEAD(pow_nan_x, tc) { atf_tc_set_md_var(tc, "descr", "Test pow(NaN, y) == NaN"); } ATF_TC_BODY(pow_nan_x, tc) { const double x = 0.0L / 0.0L; ATF_CHECK(isnan(pow(x, 2.0)) != 0); } ATF_TC(pow_nan_y); ATF_TC_HEAD(pow_nan_y, tc) { atf_tc_set_md_var(tc, "descr", "Test pow(x, NaN) == NaN"); } ATF_TC_BODY(pow_nan_y, tc) { const double y = 0.0L / 0.0L; ATF_CHECK(isnan(pow(2.0, y)) != 0); } ATF_TC(pow_inf_neg_x); ATF_TC_HEAD(pow_inf_neg_x, tc) { atf_tc_set_md_var(tc, "descr", "Test pow(-Inf, y) == +-Inf || +-0.0"); } ATF_TC_BODY(pow_inf_neg_x, tc) { const double x = -1.0L / 0.0L; double z; /* * If y is odd, y > 0, and x is -Inf, -Inf is returned. * If y is even, y > 0, and x is -Inf, +Inf is returned. */ z = pow(x, 3.0); if (isinf(z) == 0 || signbit(z) == 0) atf_tc_fail_nonfatal("pow(-Inf, 3.0) != -Inf"); z = pow(x, 4.0); if (isinf(z) == 0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(-Inf, 4.0) != +Inf"); /* * If y is odd, y < 0, and x is -Inf, -0.0 is returned. * If y is even, y < 0, and x is -Inf, +0.0 is returned. */ z = pow(x, -3.0); if (fabs(z) > 0.0 || signbit(z) == 0) atf_tc_fail_nonfatal("pow(-Inf, -3.0) != -0.0"); z = pow(x, -4.0); if (fabs(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(-Inf -4.0) != +0.0"); } ATF_TC(pow_inf_neg_y); ATF_TC_HEAD(pow_inf_neg_y, tc) { atf_tc_set_md_var(tc, "descr", "Test pow(x, -Inf) == +Inf || +0.0"); } ATF_TC_BODY(pow_inf_neg_y, tc) { const double y = -1.0L / 0.0L; double z; /* * If |x| < 1 and y is -Inf, +Inf is returned. * If |x| > 1 and y is -Inf, +0.0 is returned. */ z = pow(0.1, y); if (isinf(z) == 0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(0.1, -Inf) != +Inf"); z = pow(1.1, y); if (fabs(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(1.1, -Inf) != +0.0"); } ATF_TC(pow_inf_pos_x); ATF_TC_HEAD(pow_inf_pos_x, tc) { atf_tc_set_md_var(tc, "descr", "Test pow(+Inf, y) == +Inf || +0.0"); } ATF_TC_BODY(pow_inf_pos_x, tc) { const double x = 1.0L / 0.0L; double z; /* * For y < 0, if x is +Inf, +0.0 is returned. * For y > 0, if x is +Inf, +Inf is returned. */ z = pow(x, -2.0); if (fabs(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(+Inf, -2.0) != +0.0"); z = pow(x, 2.0); if (isinf(z) == 0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(+Inf, 2.0) != +Inf"); } ATF_TC(pow_inf_pos_y); ATF_TC_HEAD(pow_inf_pos_y, tc) { atf_tc_set_md_var(tc, "descr", "Test pow(x, +Inf) == +Inf || +0.0"); } ATF_TC_BODY(pow_inf_pos_y, tc) { const double y = 1.0L / 0.0L; double z; /* * If |x| < 1 and y is +Inf, +0.0 is returned. * If |x| > 1 and y is +Inf, +Inf is returned. */ z = pow(0.1, y); if (fabs(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(0.1, +Inf) != +0.0"); z = pow(1.1, y); if (isinf(z) == 0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(1.1, +Inf) != +Inf"); } ATF_TC(pow_one_neg_x); ATF_TC_HEAD(pow_one_neg_x, tc) { atf_tc_set_md_var(tc, "descr", "Test pow(-1.0, +-Inf) == 1.0"); } ATF_TC_BODY(pow_one_neg_x, tc) { const double infp = 1.0L / 0.0L; const double infn = -1.0L / 0.0L; /* * If x is -1.0, and y is +-Inf, 1.0 shall be returned. */ ATF_REQUIRE(isinf(infp) != 0); ATF_REQUIRE(isinf(infn) != 0); if (pow(-1.0, infp) != 1.0) { atf_tc_expect_fail("PR lib/45372"); atf_tc_fail_nonfatal("pow(-1.0, +Inf) != 1.0"); } if (pow(-1.0, infn) != 1.0) { atf_tc_expect_fail("PR lib/45372"); atf_tc_fail_nonfatal("pow(-1.0, -Inf) != 1.0"); } } ATF_TC(pow_one_pos_x); ATF_TC_HEAD(pow_one_pos_x, tc) { atf_tc_set_md_var(tc, "descr", "Test pow(1.0, y) == 1.0"); } ATF_TC_BODY(pow_one_pos_x, tc) { const double y[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 }; const double z = 0.0L / 0.0L; size_t i; /* * For any value of y (including NaN), * if x is 1.0, 1.0 shall be returned. */ if (pow(1.0, z) != 1.0) atf_tc_fail_nonfatal("pow(1.0, NaN) != 1.0"); for (i = 0; i < __arraycount(y); i++) { if (pow(1.0, y[i]) != 1.0) atf_tc_fail_nonfatal("pow(1.0, %0.01f) != 1.0", y[i]); } } ATF_TC(pow_zero_x); ATF_TC_HEAD(pow_zero_x, tc) { atf_tc_set_md_var(tc, "descr", "Test pow(+-0.0, y) == +-0.0 || HUGE"); } ATF_TC_BODY(pow_zero_x, tc) { double z; /* * If x is +0.0 or -0.0, y > 0, and y * is an odd integer, x is returned. */ z = pow(+0.0, 3.0); if (fabs(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(+0.0, 3.0) != +0.0"); z = pow(-0.0, 3.0); if (fabs(z) > 0.0 || signbit(z) == 0) atf_tc_fail_nonfatal("pow(-0.0, 3.0) != -0.0"); /* * If y > 0 and not an odd integer, * if x is +0.0 or -0.0, +0.0 is returned. */ z = pow(+0.0, 4.0); if (fabs(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(+0.0, 4.0) != +0.0"); z = pow(-0.0, 4.0); if (fabs(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("pow(-0.0, 4.0) != +0.0"); /* * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL, * +-HUGE_VALF, or +-HUGE_VALL shall be returned. */ z = pow(+0.0, -4.0); if (z != HUGE_VAL) { atf_tc_fail_nonfatal("pow(+0.0, -4.0) != HUGE_VAL"); } z = pow(-0.0, -4.0); if (z != HUGE_VAL) { atf_tc_fail_nonfatal("pow(-0.0, -4.0) != HUGE_VAL"); } z = pow(+0.0, -5.0); if (z != HUGE_VAL) { atf_tc_fail_nonfatal("pow(+0.0, -5.0) != HUGE_VAL"); } z = pow(-0.0, -5.0); if (z != -HUGE_VAL) atf_tc_fail_nonfatal("pow(-0.0, -5.0) != -HUGE_VAL"); } ATF_TC(pow_zero_y); ATF_TC_HEAD(pow_zero_y, tc) { atf_tc_set_md_var(tc, "descr", "Test pow(x, +-0.0) == 1.0"); } ATF_TC_BODY(pow_zero_y, tc) { const double x[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 }; const double z = 0.0L / 0.0L; size_t i; /* * For any value of x (including NaN), * if y is +0.0 or -0.0, 1.0 is returned. */ if (pow(z, +0.0) != 1.0) atf_tc_fail_nonfatal("pow(NaN, +0.0) != 1.0"); if (pow(z, -0.0) != 1.0) atf_tc_fail_nonfatal("pow(NaN, -0.0) != 1.0"); for (i = 0; i < __arraycount(x); i++) { if (pow(x[i], +0.0) != 1.0) atf_tc_fail_nonfatal("pow(%0.01f, +0.0) != 1.0", x[i]); if (pow(x[i], -0.0) != 1.0) atf_tc_fail_nonfatal("pow(%0.01f, -0.0) != 1.0", x[i]); } } /* * powf(3) */ ATF_TC(powf_nan_x); ATF_TC_HEAD(powf_nan_x, tc) { atf_tc_set_md_var(tc, "descr", "Test powf(NaN, y) == NaN"); } ATF_TC_BODY(powf_nan_x, tc) { const float x = 0.0L / 0.0L; ATF_CHECK(isnanf(powf(x, 2.0)) != 0); } ATF_TC(powf_nan_y); ATF_TC_HEAD(powf_nan_y, tc) { atf_tc_set_md_var(tc, "descr", "Test powf(x, NaN) == NaN"); } ATF_TC_BODY(powf_nan_y, tc) { const float y = 0.0L / 0.0L; ATF_CHECK(isnanf(powf(2.0, y)) != 0); } ATF_TC(powf_inf_neg_x); ATF_TC_HEAD(powf_inf_neg_x, tc) { atf_tc_set_md_var(tc, "descr", "Test powf(-Inf, y) == +-Inf || +-0.0"); } ATF_TC_BODY(powf_inf_neg_x, tc) { const float x = -1.0L / 0.0L; float z; /* * If y is odd, y > 0, and x is -Inf, -Inf is returned. * If y is even, y > 0, and x is -Inf, +Inf is returned. */ z = powf(x, 3.0); if (isinf(z) == 0 || signbit(z) == 0) atf_tc_fail_nonfatal("powf(-Inf, 3.0) != -Inf"); z = powf(x, 4.0); if (isinf(z) == 0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(-Inf, 4.0) != +Inf"); /* * If y is odd, y < 0, and x is -Inf, -0.0 is returned. * If y is even, y < 0, and x is -Inf, +0.0 is returned. */ z = powf(x, -3.0); if (fabsf(z) > 0.0 || signbit(z) == 0) { atf_tc_expect_fail("PR lib/45372"); atf_tc_fail_nonfatal("powf(-Inf, -3.0) != -0.0"); } z = powf(x, -4.0); if (fabsf(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(-Inf -4.0) != +0.0"); } ATF_TC(powf_inf_neg_y); ATF_TC_HEAD(powf_inf_neg_y, tc) { atf_tc_set_md_var(tc, "descr", "Test powf(x, -Inf) == +Inf || +0.0"); } ATF_TC_BODY(powf_inf_neg_y, tc) { const float y = -1.0L / 0.0L; float z; /* * If |x| < 1 and y is -Inf, +Inf is returned. * If |x| > 1 and y is -Inf, +0.0 is returned. */ z = powf(0.1, y); if (isinf(z) == 0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(0.1, -Inf) != +Inf"); z = powf(1.1, y); if (fabsf(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(1.1, -Inf) != +0.0"); } ATF_TC(powf_inf_pos_x); ATF_TC_HEAD(powf_inf_pos_x, tc) { atf_tc_set_md_var(tc, "descr", "Test powf(+Inf, y) == +Inf || +0.0"); } ATF_TC_BODY(powf_inf_pos_x, tc) { const float x = 1.0L / 0.0L; float z; /* * For y < 0, if x is +Inf, +0.0 is returned. * For y > 0, if x is +Inf, +Inf is returned. */ z = powf(x, -2.0); if (fabsf(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(+Inf, -2.0) != +0.0"); z = powf(x, 2.0); if (isinf(z) == 0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(+Inf, 2.0) != +Inf"); } ATF_TC(powf_inf_pos_y); ATF_TC_HEAD(powf_inf_pos_y, tc) { atf_tc_set_md_var(tc, "descr", "Test powf(x, +Inf) == +Inf || +0.0"); } ATF_TC_BODY(powf_inf_pos_y, tc) { const float y = 1.0L / 0.0L; float z; /* * If |x| < 1 and y is +Inf, +0.0 is returned. * If |x| > 1 and y is +Inf, +Inf is returned. */ z = powf(0.1, y); if (fabsf(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(0.1, +Inf) != +0.0"); z = powf(1.1, y); if (isinf(z) == 0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(1.1, +Inf) != +Inf"); } ATF_TC(powf_one_neg_x); ATF_TC_HEAD(powf_one_neg_x, tc) { atf_tc_set_md_var(tc, "descr", "Test powf(-1.0, +-Inf) == 1.0"); } ATF_TC_BODY(powf_one_neg_x, tc) { const float infp = 1.0L / 0.0L; const float infn = -1.0L / 0.0L; /* * If x is -1.0, and y is +-Inf, 1.0 shall be returned. */ ATF_REQUIRE(isinf(infp) != 0); ATF_REQUIRE(isinf(infn) != 0); if (powf(-1.0, infp) != 1.0) { atf_tc_expect_fail("PR lib/45372"); atf_tc_fail_nonfatal("powf(-1.0, +Inf) != 1.0"); } if (powf(-1.0, infn) != 1.0) { atf_tc_expect_fail("PR lib/45372"); atf_tc_fail_nonfatal("powf(-1.0, -Inf) != 1.0"); } } ATF_TC(powf_one_pos_x); ATF_TC_HEAD(powf_one_pos_x, tc) { atf_tc_set_md_var(tc, "descr", "Test powf(1.0, y) == 1.0"); } ATF_TC_BODY(powf_one_pos_x, tc) { const float y[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 }; const float z = 0.0L / 0.0L; size_t i; /* * For any value of y (including NaN), * if x is 1.0, 1.0 shall be returned. */ if (powf(1.0, z) != 1.0) atf_tc_fail_nonfatal("powf(1.0, NaN) != 1.0"); for (i = 0; i < __arraycount(y); i++) { if (powf(1.0, y[i]) != 1.0) atf_tc_fail_nonfatal("powf(1.0, %0.01f) != 1.0", y[i]); } } ATF_TC(powf_zero_x); ATF_TC_HEAD(powf_zero_x, tc) { atf_tc_set_md_var(tc, "descr", "Test powf(+-0.0, y) == +-0.0 || HUGE"); } ATF_TC_BODY(powf_zero_x, tc) { float z; /* * If x is +0.0 or -0.0, y > 0, and y * is an odd integer, x is returned. */ z = powf(+0.0, 3.0); if (fabsf(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(+0.0, 3.0) != +0.0"); z = powf(-0.0, 3.0); if (fabsf(z) > 0.0 || signbit(z) == 0) atf_tc_fail_nonfatal("powf(-0.0, 3.0) != -0.0"); /* * If y > 0 and not an odd integer, * if x is +0.0 or -0.0, +0.0 is returned. */ z = powf(+0.0, 4.0); if (fabsf(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(+0.0, 4.0) != +0.0"); z = powf(-0.0, 4.0); if (fabsf(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(-0.0, 4.0) != +0.0"); /* * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL, * +-HUGE_VALF, or +-HUGE_VALL shall be returned. */ z = powf(+0.0, -4.0); if (z != HUGE_VALF) { atf_tc_expect_fail("PR port-amd64/45391"); atf_tc_fail_nonfatal("powf(+0.0, -4.0) != HUGE_VALF"); } z = powf(-0.0, -4.0); if (z != HUGE_VALF) { atf_tc_expect_fail("PR port-amd64/45391"); atf_tc_fail_nonfatal("powf(-0.0, -4.0) != HUGE_VALF"); } z = powf(+0.0, -5.0); if (z != HUGE_VALF) { atf_tc_expect_fail("PR port-amd64/45391"); atf_tc_fail_nonfatal("powf(+0.0, -5.0) != HUGE_VALF"); } z = powf(-0.0, -5.0); if (z != -HUGE_VALF) atf_tc_fail_nonfatal("powf(-0.0, -5.0) != -HUGE_VALF"); } ATF_TC(powf_zero_y); ATF_TC_HEAD(powf_zero_y, tc) { atf_tc_set_md_var(tc, "descr", "Test powf(x, +-0.0) == 1.0"); } ATF_TC_BODY(powf_zero_y, tc) { const float x[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 }; const float z = 0.0L / 0.0L; size_t i; /* * For any value of x (including NaN), * if y is +0.0 or -0.0, 1.0 is returned. */ if (powf(z, +0.0) != 1.0) atf_tc_fail_nonfatal("powf(NaN, +0.0) != 1.0"); if (powf(z, -0.0) != 1.0) atf_tc_fail_nonfatal("powf(NaN, -0.0) != 1.0"); for (i = 0; i < __arraycount(x); i++) { if (powf(x[i], +0.0) != 1.0) atf_tc_fail_nonfatal("powf(%0.01f, +0.0) != 1.0",x[i]); if (powf(x[i], -0.0) != 1.0) atf_tc_fail_nonfatal("powf(%0.01f, -0.0) != 1.0",x[i]); } } +ATF_TC(powf_near_one_x_huge_y); +ATF_TC_HEAD(powf_near_one_x_huge_y, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test powf(->1, huge) != inf"); +} + +ATF_TC_BODY(powf_near_one_x_huge_y, tc) +{ + const float x = 0x1.ffffeep-1f; /* 9.999995e-01f */ + const float y = -0x1.000002p+27f; /* -1.342177e+08f */ + const float e = 0x1.d53532p+103f; /* 1.858724e+31f */ + const float ulp = __FLT_EPSILON__; + float z; + + z = powf(x, y); + + ATF_CHECK(isinf(z) == 0); + ATF_CHECK(fabsf(z - e) <= 2 * ulp); +} + + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, pow_nan_x); ATF_TP_ADD_TC(tp, pow_nan_y); ATF_TP_ADD_TC(tp, pow_inf_neg_x); ATF_TP_ADD_TC(tp, pow_inf_neg_y); ATF_TP_ADD_TC(tp, pow_inf_pos_x); ATF_TP_ADD_TC(tp, pow_inf_pos_y); ATF_TP_ADD_TC(tp, pow_one_neg_x); ATF_TP_ADD_TC(tp, pow_one_pos_x); ATF_TP_ADD_TC(tp, pow_zero_x); ATF_TP_ADD_TC(tp, pow_zero_y); ATF_TP_ADD_TC(tp, powf_nan_x); ATF_TP_ADD_TC(tp, powf_nan_y); ATF_TP_ADD_TC(tp, powf_inf_neg_x); ATF_TP_ADD_TC(tp, powf_inf_neg_y); ATF_TP_ADD_TC(tp, powf_inf_pos_x); ATF_TP_ADD_TC(tp, powf_inf_pos_y); ATF_TP_ADD_TC(tp, powf_one_neg_x); ATF_TP_ADD_TC(tp, powf_one_pos_x); ATF_TP_ADD_TC(tp, powf_zero_x); ATF_TP_ADD_TC(tp, powf_zero_y); + ATF_TP_ADD_TC(tp, powf_near_one_x_huge_y); return atf_no_error(); } diff --git a/lib/msun/src/e_powf.c b/lib/msun/src/e_powf.c index 53f1d37d6bec..33eedad50b16 100644 --- a/lib/msun/src/e_powf.c +++ b/lib/msun/src/e_powf.c @@ -1,252 +1,252 @@ /* e_powf.c -- float version of e_pow.c. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunPro, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include __FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" static const float bp[] = {1.0, 1.5,}, dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */ dp_l[] = { 0.0, 1.56322085e-06,}, /* 0x35d1cfdc */ zero = 0.0, half = 0.5, qrtr = 0.25, thrd = 3.33333343e-01, /* 0x3eaaaaab */ one = 1.0, two = 2.0, two24 = 16777216.0, /* 0x4b800000 */ huge = 1.0e30, tiny = 1.0e-30, /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ L1 = 6.0000002384e-01, /* 0x3f19999a */ L2 = 4.2857143283e-01, /* 0x3edb6db7 */ L3 = 3.3333334327e-01, /* 0x3eaaaaab */ L4 = 2.7272811532e-01, /* 0x3e8ba305 */ L5 = 2.3066075146e-01, /* 0x3e6c3255 */ L6 = 2.0697501302e-01, /* 0x3e53f142 */ P1 = 1.6666667163e-01, /* 0x3e2aaaab */ P2 = -2.7777778450e-03, /* 0xbb360b61 */ P3 = 6.6137559770e-05, /* 0x388ab355 */ P4 = -1.6533901999e-06, /* 0xb5ddea0e */ P5 = 4.1381369442e-08, /* 0x3331bb4c */ lg2 = 6.9314718246e-01, /* 0x3f317218 */ lg2_h = 6.93145752e-01, /* 0x3f317200 */ lg2_l = 1.42860654e-06, /* 0x35bfbe8c */ ovt = 4.2995665694e-08, /* -(128-log2(ovfl+.5ulp)) */ cp = 9.6179670095e-01, /* 0x3f76384f =2/(3ln2) */ cp_h = 9.6191406250e-01, /* 0x3f764000 =12b cp */ cp_l = -1.1736857402e-04, /* 0xb8f623c6 =tail of cp_h */ ivln2 = 1.4426950216e+00, /* 0x3fb8aa3b =1/ln2 */ ivln2_h = 1.4426879883e+00, /* 0x3fb8aa00 =16b 1/ln2*/ ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/ float __ieee754_powf(float x, float y) { float z,ax,z_h,z_l,p_h,p_l; float y1,t1,t2,r,s,sn,t,u,v,w; int32_t i,j,k,yisint,n; int32_t hx,hy,ix,iy,is; GET_FLOAT_WORD(hx,x); GET_FLOAT_WORD(hy,y); ix = hx&0x7fffffff; iy = hy&0x7fffffff; /* y==zero: x**0 = 1 */ if(iy==0) return one; /* x==1: 1**y = 1, even if y is NaN */ if (hx==0x3f800000) return one; /* y!=zero: result is NaN if either arg is NaN */ if(ix > 0x7f800000 || iy > 0x7f800000) return nan_mix(x, y); /* determine if y is an odd int when x < 0 * yisint = 0 ... y is not an integer * yisint = 1 ... y is an odd int * yisint = 2 ... y is an even int */ yisint = 0; if(hx<0) { if(iy>=0x4b800000) yisint = 2; /* even integer y */ else if(iy>=0x3f800000) { k = (iy>>23)-0x7f; /* exponent */ j = iy>>(23-k); if((j<<(23-k))==iy) yisint = 2-(j&1); } } /* special value of y */ if (iy==0x7f800000) { /* y is +-inf */ if (ix==0x3f800000) return one; /* (-1)**+-inf is NaN */ else if (ix > 0x3f800000)/* (|x|>1)**+-inf = inf,0 */ return (hy>=0)? y: zero; else /* (|x|<1)**-,+inf = inf,0 */ return (hy<0)?-y: zero; } if(iy==0x3f800000) { /* y is +-1 */ if(hy<0) return one/x; else return x; } if(hy==0x40000000) return x*x; /* y is 2 */ if(hy==0x3f000000) { /* y is 0.5 */ if(hx>=0) /* x >= +0 */ return __ieee754_sqrtf(x); } ax = fabsf(x); /* special value of x */ if(ix==0x7f800000||ix==0||ix==0x3f800000){ z = ax; /*x is +-0,+-inf,+-1*/ if(hy<0) z = one/z; /* z = (1/|x|) */ if(hx<0) { if(((ix-0x3f800000)|yisint)==0) { z = (z-z)/(z-z); /* (-1)**non-int is NaN */ } else if(yisint==1) z = -z; /* (x<0)**odd = -(|x|**odd) */ } return z; } n = ((u_int32_t)hx>>31)-1; /* (x<0)**(non-int) is NaN */ if((n|yisint)==0) return (x-x)/(x-x); sn = one; /* s (sign of result -ve**odd) = -1 else = 1 */ if((n|(yisint-1))==0) sn = -one;/* (-ve)**(odd int) */ /* |y| is huge */ if(iy>0x4d000000) { /* if |y| > 2**27 */ /* over/underflow if x is not close to one */ - if(ix<0x3f7ffff8) return (hy<0)? sn*huge*huge:sn*tiny*tiny; + if(ix<0x3f7ffff7) return (hy<0)? sn*huge*huge:sn*tiny*tiny; if(ix>0x3f800007) return (hy>0)? sn*huge*huge:sn*tiny*tiny; /* now |1-x| is tiny <= 2**-20, suffice to compute log(x) by x-x^2/2+x^3/3-x^4/4 */ t = ax-1; /* t has 20 trailing zeros */ w = (t*t)*(half-t*(thrd-t*qrtr)); u = ivln2_h*t; /* ivln2_h has 16 sig. bits */ v = t*ivln2_l-w*ivln2; t1 = u+v; GET_FLOAT_WORD(is,t1); SET_FLOAT_WORD(t1,is&0xfffff000); t2 = v-(t1-u); } else { float s2,s_h,s_l,t_h,t_l; n = 0; /* take care subnormal number */ if(ix<0x00800000) {ax *= two24; n -= 24; GET_FLOAT_WORD(ix,ax); } n += ((ix)>>23)-0x7f; j = ix&0x007fffff; /* determine interval */ ix = j|0x3f800000; /* normalize ix */ if(j<=0x1cc471) k=0; /* |x|>1)&0xfffff000)|0x20000000; SET_FLOAT_WORD(t_h,is+0x00400000+(k<<21)); t_l = ax - (t_h-bp[k]); s_l = v*((u-s_h*t_h)-s_h*t_l); /* compute log(ax) */ s2 = s*s; r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); r += s_l*(s_h+s); s2 = s_h*s_h; t_h = 3+s2+r; GET_FLOAT_WORD(is,t_h); SET_FLOAT_WORD(t_h,is&0xfffff000); t_l = r-((t_h-3)-s2); /* u+v = s*(1+...) */ u = s_h*t_h; v = s_l*t_h+t_l*s; /* 2/(3log2)*(s+...) */ p_h = u+v; GET_FLOAT_WORD(is,p_h); SET_FLOAT_WORD(p_h,is&0xfffff000); p_l = v-(p_h-u); z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ z_l = cp_l*p_h+p_l*cp+dp_l[k]; /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */ t = n; t1 = (((z_h+z_l)+dp_h[k])+t); GET_FLOAT_WORD(is,t1); SET_FLOAT_WORD(t1,is&0xfffff000); t2 = z_l-(((t1-t)-dp_h[k])-z_h); } /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ GET_FLOAT_WORD(is,y); SET_FLOAT_WORD(y1,is&0xfffff000); p_l = (y-y1)*t1+y*t2; p_h = y1*t1; z = p_l+p_h; GET_FLOAT_WORD(j,z); if (j>0x43000000) /* if z > 128 */ return sn*huge*huge; /* overflow */ else if (j==0x43000000) { /* if z == 128 */ if(p_l+ovt>z-p_h) return sn*huge*huge; /* overflow */ } else if ((j&0x7fffffff)>0x43160000) /* z <= -150 */ return sn*tiny*tiny; /* underflow */ else if (j==0xc3160000){ /* z == -150 */ if(p_l<=z-p_h) return sn*tiny*tiny; /* underflow */ } /* * compute 2**(p_h+p_l) */ i = j&0x7fffffff; k = (i>>23)-0x7f; n = 0; if(i>0x3f000000) { /* if |z| > 0.5, set n = [z+0.5] */ n = j+(0x00800000>>(k+1)); k = ((n&0x7fffffff)>>23)-0x7f; /* new k for n */ SET_FLOAT_WORD(t,n&~(0x007fffff>>k)); n = ((n&0x007fffff)|0x00800000)>>(23-k); if(j<0) n = -n; p_h -= t; } t = p_l+p_h; GET_FLOAT_WORD(is,t); SET_FLOAT_WORD(t,is&0xffff8000); u = t*lg2_h; v = (p_l-(t-p_h))*lg2+t*lg2_l; z = u+v; w = v-(z-u); t = z*z; t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); r = (z*t1)/(t1-two)-(w+z*w); z = one-(r-z); GET_FLOAT_WORD(j,z); j += (n<<23); if((j>>23)<=0) z = scalbnf(z,n); /* subnormal output */ else SET_FLOAT_WORD(z,j); return sn*z; }