diff options
| -rw-r--r-- | lib/msun/src/s_cosf.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/msun/src/s_cosf.c b/lib/msun/src/s_cosf.c index 84fbc6d24e749..b800a8e5896ef 100644 --- a/lib/msun/src/s_cosf.c +++ b/lib/msun/src/s_cosf.c @@ -36,10 +36,10 @@ float cosf(float x) { float y[2]; - int32_t n,ix; + int32_t n, hx, ix; - x = fabsf(x); - GET_FLOAT_WORD(ix,x); + GET_FLOAT_WORD(hx,x); + ix = hx & 0x7fffffff; if(ix <= 0x3f490fda) { /* |x| ~<= pi/4 */ if(ix<0x39800000) /* |x| < 2**-12 */ @@ -47,16 +47,24 @@ cosf(float x) return __kernel_cosdf(x); } if(ix<=0x407b53d1) { /* |x| ~<= 5*pi/4 */ - if(ix<=0x4016cbe3) /* |x| ~<= 3pi/4 */ - return __kernel_sindf(c1pio2 - x); - else - return -__kernel_cosdf(x - c2pio2); + if(ix>0x4016cbe3) /* |x| ~> 3*pi/4 */ + return -__kernel_cosdf(x + (hx > 0 ? -c2pio2 : c2pio2)); + else { + if(hx>0) + return __kernel_sindf(c1pio2 - x); + else + return __kernel_sindf(x + c1pio2); + } } if(ix<=0x40e231d5) { /* |x| ~<= 9*pi/4 */ - if(ix<=0x40afeddf) /* |x| ~<= 7*pi/4 */ - return __kernel_sindf(x - c3pio2); - else - return __kernel_cosdf(x - c4pio2); + if(ix>0x40afeddf) /* |x| ~> 7*pi/4 */ + return __kernel_cosdf(x + (hx > 0 ? -c4pio2 : c4pio2)); + else { + if(hx>0) + return __kernel_sindf(x - c3pio2); + else + return __kernel_sindf(-c3pio2 - x); + } } /* cos(Inf or NaN) is NaN */ |
