summaryrefslogtreecommitdiff
path: root/src/math/powf.c
diff options
context:
space:
mode:
authornsz <nsz@port70.net>2012-03-20 20:04:53 +0100
committernsz <nsz@port70.net>2012-03-20 20:04:53 +0100
commitf1347a3a453ce38bf55cd92f5922311235810fd1 (patch)
treef34ab3397f7b51e07c360f7a926ccbc6b452748a /src/math/powf.c
parent615bbd365f322cd8d0b1a4383ee0a6ce8e35b33b (diff)
downloadmusl-f1347a3a453ce38bf55cd92f5922311235810fd1.tar.gz
clean up pow.c and powf.c
fix comments about special cases
Diffstat (limited to 'src/math/powf.c')
-rw-r--r--src/math/powf.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/src/math/powf.c b/src/math/powf.c
index c101d95c..427c8965 100644
--- a/src/math/powf.c
+++ b/src/math/powf.c
@@ -57,17 +57,15 @@ float powf(float x, float y)
ix = hx & 0x7fffffff;
iy = hy & 0x7fffffff;
- /* y == 0: x**0 = 1 */
+ /* x**0 = 1, even if x is NaN */
if (iy == 0)
return 1.0f;
-
- /* x == 1: 1**y = 1, even if y is NaN */
+ /* 1**y = 1, even if y is NaN */
if (hx == 0x3f800000)
return 1.0f;
-
- /* y != 0: result is NaN if either arg is NaN */
+ /* NaN if either arg is NaN */
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
@@ -93,13 +91,10 @@ float powf(float x, float y)
else if (ix > 0x3f800000) /* (|x|>1)**+-inf = inf,0 */
return hy >= 0 ? y : 0.0f;
else /* (|x|<1)**+-inf = 0,inf */
- return hy < 0 ? -y : 0.0f;
- }
- if (iy == 0x3f800000) { /* y is +-1 */
- if (hy < 0)
- return 1.0f/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 */
@@ -122,15 +117,13 @@ float powf(float x, float y)
return z;
}
- n = ((uint32_t)hx>>31) - 1;
-
- /* (x<0)**(non-int) is NaN */
- if ((n|yisint) == 0)
- return (x-x)/(x-x);
-
- sn = 1.0f; /* s (sign of result -ve**odd) = -1 else = 1 */
- if ((n|(yisint-1)) == 0) /* (-ve)**(odd int) */
- sn = -1.0f;
+ 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 */