projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add more arch-specific MAP_ macros to bits/mman.h
[musl]
/
src
/
math
/
powf.c
diff --git
a/src/math/powf.c
b/src/math/powf.c
index
e322ff2
..
427c896
100644
(file)
--- a/
src/math/powf.c
+++ b/
src/math/powf.c
@@
-19,9
+19,6
@@
static const float
bp[] = {1.0, 1.5,},
dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */
dp_l[] = { 0.0, 1.56322085e-06,}, /* 0x35d1cfdc */
bp[] = {1.0, 1.5,},
dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */
dp_l[] = { 0.0, 1.56322085e-06,}, /* 0x35d1cfdc */
-zero = 0.0,
-one = 1.0,
-two = 2.0,
two24 = 16777216.0, /* 0x4b800000 */
huge = 1.0e30,
tiny = 1.0e-30,
two24 = 16777216.0, /* 0x4b800000 */
huge = 1.0e30,
tiny = 1.0e-30,
@@
-60,17
+57,15
@@
float powf(float x, float y)
ix = hx & 0x7fffffff;
iy = hy & 0x7fffffff;
ix = hx & 0x7fffffff;
iy = hy & 0x7fffffff;
- /*
y == zero: x**0 = 1
*/
+ /*
x**0 = 1, even if x is NaN
*/
if (iy == 0)
if (iy == 0)
- return one;
-
- /* x == 1: 1**y = 1, even if y is NaN */
+ return 1.0f;
+ /* 1**y = 1, even if y is NaN */
if (hx == 0x3f800000)
if (hx == 0x3f800000)
- return one;
-
- /* y != zero: result is NaN if either arg is NaN */
+ return 1.0f;
+ /* NaN if either arg is NaN */
if (ix > 0x7f800000 || iy > 0x7f800000)
if (ix > 0x7f800000 || iy > 0x7f800000)
- return
(x+0.0F) + (y+0.0F)
;
+ return
x + y
;
/* determine if y is an odd int when x < 0
* yisint = 0 ... y is not an integer
/* determine if y is an odd int when x < 0
* yisint = 0 ... y is not an integer
@@
-92,17
+87,14
@@
float powf(float x, float y)
/* special value of y */
if (iy == 0x7f800000) { /* y is +-inf */
if (ix == 0x3f800000) /* (-1)**+-inf is 1 */
/* special value of y */
if (iy == 0x7f800000) { /* y is +-inf */
if (ix == 0x3f800000) /* (-1)**+-inf is 1 */
- return
one
;
+ return
1.0f
;
else if (ix > 0x3f800000) /* (|x|>1)**+-inf = inf,0 */
else if (ix > 0x3f800000) /* (|x|>1)**+-inf = inf,0 */
- return hy >= 0 ? y :
zero
;
+ return hy >= 0 ? y :
0.0f
;
else /* (|x|<1)**+-inf = 0,inf */
else /* (|x|<1)**+-inf = 0,inf */
- return hy < 0 ? -y : zero;
- }
- if (iy == 0x3f800000) { /* y is +-1 */
- if (hy < 0)
- return one/x;
- return x;
+ return hy >= 0 ? 0.0f: -y;
}
}
+ if (iy == 0x3f800000) /* y is +-1 */
+ return hy >= 0 ? x : 1.0f/x;
if (hy == 0x40000000) /* y is 2 */
return x*x;
if (hy == 0x3f000000) { /* y is 0.5 */
if (hy == 0x40000000) /* y is 2 */
return x*x;
if (hy == 0x3f000000) { /* y is 0.5 */
@@
-115,7
+107,7
@@
float powf(float x, float y)
if (ix == 0x7f800000 || ix == 0 || ix == 0x3f800000) { /* x is +-0,+-inf,+-1 */
z = ax;
if (hy < 0) /* z = (1/|x|) */
if (ix == 0x7f800000 || ix == 0 || ix == 0x3f800000) { /* x is +-0,+-inf,+-1 */
z = ax;
if (hy < 0) /* z = (1/|x|) */
- z =
one
/z;
+ z =
1.0f
/z;
if (hx < 0) {
if (((ix-0x3f800000)|yisint) == 0) {
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
if (hx < 0) {
if (((ix-0x3f800000)|yisint) == 0) {
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
@@
-125,15
+117,13
@@
float powf(float x, float y)
return z;
}
return z;
}
- n = ((uint32_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) /* (-ve)**(odd int) */
- sn = -one;
+ sn = 1.0f; /* sign of result */
+ if (hx < 0) {
+ if (yisint == 0) /* (x<0)**(non-int) is NaN */
+ return (x-x)/(x-x);
+ if (yisint == 1) /* (x<0)**(odd int) */
+ sn = -1.0f;
+ }
/* |y| is huge */
if (iy > 0x4d000000) { /* if |y| > 2**27 */
/* |y| is huge */
if (iy > 0x4d000000) { /* if |y| > 2**27 */
@@
-145,7
+135,7
@@
float powf(float x, float y)
/* 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 */
/* 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)*(
(float)0.5-t*((float)0.333333333333-t*(float)0.25
));
+ w = (t*t)*(
0.5f - t*(0.333333333333f - t*0.25f
));
u = ivln2_h*t; /* ivln2_h has 16 sig. bits */
v = t*ivln2_l - w*ivln2;
t1 = u + v;
u = ivln2_h*t; /* ivln2_h has 16 sig. bits */
v = t*ivln2_l - w*ivln2;
t1 = u + v;
@@
-178,7
+168,7
@@
float powf(float x, float y)
/* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
u = ax - bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
/* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
u = ax - bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
- v =
one
/(ax+bp[k]);
+ v =
1.0f
/(ax+bp[k]);
s = u*v;
s_h = s;
GET_FLOAT_WORD(is, s_h);
s = u*v;
s_h = s;
GET_FLOAT_WORD(is, s_h);
@@
-193,10
+183,10
@@
float powf(float x, float y)
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;
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 =
(float)3.0
+ s2 + r;
+ t_h =
3.0f
+ s2 + r;
GET_FLOAT_WORD(is, t_h);
SET_FLOAT_WORD(t_h, is & 0xfffff000);
GET_FLOAT_WORD(is, t_h);
SET_FLOAT_WORD(t_h, is & 0xfffff000);
- t_l = r - ((t_h -
(float)3.0
) - s2);
+ t_l = r - ((t_h -
3.0f
) - s2);
/* u+v = s*(1+...) */
u = s_h*t_h;
v = s_l*t_h + t_l*s;
/* u+v = s*(1+...) */
u = s_h*t_h;
v = s_l*t_h + t_l*s;
@@
-257,8
+247,8
@@
float powf(float x, float y)
w = v - (z - u);
t = z*z;
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
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);
+ r = (z*t1)/(t1-
2.0f
) - (w+z*w);
+ z =
1.0f
- (r - z);
GET_FLOAT_WORD(j, z);
j += n<<23;
if ((j>>23) <= 0) /* subnormal output */
GET_FLOAT_WORD(j, z);
j += n<<23;
if ((j>>23) <= 0) /* subnormal output */