Skip to content

Commit c9cf16d

Browse files
committed
add special cases for powers 3 and 4, in addition to 2
1 parent 3c8738e commit c9cf16d

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/e_pow.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,15 @@ __ieee754_pow(double x, double y)
150150
if(iy==0x3ff00000) { /* y is +-1 */
151151
if(hy<0) return one/x; else return x;
152152
}
153-
if(hy==0x40000000) return x*x; /* y is 2 */
154-
if(hy==0x3fe00000) { /* y is 0.5 */
153+
if(hy==0x40000000) return x*x; /* y is 2 */
154+
if(hy==0x40080000) return x*x*x; /* y is 3 */
155+
if(hy==0x40100000) { /* y is 4 */
156+
u = x*x;
157+
return u*u;
158+
}
159+
if(hy==0x3fe00000) { /* y is 0.5 */
155160
if(hx>=0) /* x >= +0 */
156-
return sqrt(x);
161+
return sqrt(x);
157162
}
158163
}
159164

src/e_powf.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ __ieee754_powf(float x, float y)
102102
if(iy==0x3f800000) { /* y is +-1 */
103103
if(hy<0) return one/x; else return x;
104104
}
105-
if(hy==0x40000000) return x*x; /* y is 2 */
106-
if(hy==0x3f000000) { /* y is 0.5 */
105+
if(hy==0x40000000) return x*x; /* y is 2 */
106+
if(hy==0x40400000) return x*x*x; /* y is 3 */
107+
if(hy==0x40800000) { /* y is 4 */
108+
u = x*x;
109+
return u*u;
110+
}
111+
if(hy==0x3f000000) { /* y is 0.5 */
107112
if(hx>=0) /* x >= +0 */
108-
return __ieee754_sqrtf(x);
113+
return __ieee754_sqrtf(x);
109114
}
110115

111116
ax = fabsf(x);

0 commit comments

Comments
 (0)