s_cosf.c revision 152949
12116Sjkh/* s_cosf.c -- float version of s_cos.c. 22116Sjkh * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3152871Sbde * Optimized by Bruce D. Evans. 42116Sjkh */ 52116Sjkh 62116Sjkh/* 72116Sjkh * ==================================================== 82116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 92116Sjkh * 102116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business. 112116Sjkh * Permission to use, copy, modify, and distribute this 128870Srgrimes * software is freely granted, provided that this notice 132116Sjkh * is preserved. 142116Sjkh * ==================================================== 152116Sjkh */ 162116Sjkh 172116Sjkh#ifndef lint 1850476Speterstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/s_cosf.c 152949 2005-11-30 06:47:18Z bde $"; 192116Sjkh#endif 202116Sjkh 212116Sjkh#include "math.h" 22152869Sbde#define INLINE_KERNEL_COSDF 23152869Sbde#define INLINE_KERNEL_SINDF 242116Sjkh#include "math_private.h" 25152647Sbde#include "k_cosf.c" 26152647Sbde#include "k_sinf.c" 272116Sjkh 28152596Sbde/* Small multiples of pi/2 rounded to double precision. */ 29152596Sbdestatic const double 30152596Sbdec1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */ 31152596Sbdec2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */ 32152596Sbdec3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */ 33152596Sbdec4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ 34152596Sbde 3597413Salfredfloat 3697413Salfredcosf(float x) 372116Sjkh{ 38152540Sbde float y[2]; 39152949Sbde int32_t n, hx, ix; 402116Sjkh 41152949Sbde GET_FLOAT_WORD(hx,x); 42152949Sbde ix = hx & 0x7fffffff; 432116Sjkh 44152540Sbde if(ix <= 0x3f490fda) { /* |x| ~<= pi/4 */ 45152540Sbde if(ix<0x39800000) /* |x| < 2**-12 */ 46152540Sbde if(((int)x)==0) return 1.0; /* 1 with inexact if x != 0 */ 47152869Sbde return __kernel_cosdf(x); 48151620Sbde } 49152871Sbde if(ix<=0x407b53d1) { /* |x| ~<= 5*pi/4 */ 50152949Sbde if(ix>0x4016cbe3) /* |x| ~> 3*pi/4 */ 51152949Sbde return -__kernel_cosdf(x + (hx > 0 ? -c2pio2 : c2pio2)); 52152949Sbde else { 53152949Sbde if(hx>0) 54152949Sbde return __kernel_sindf(c1pio2 - x); 55152949Sbde else 56152949Sbde return __kernel_sindf(x + c1pio2); 57152949Sbde } 58152596Sbde } 59152871Sbde if(ix<=0x40e231d5) { /* |x| ~<= 9*pi/4 */ 60152949Sbde if(ix>0x40afeddf) /* |x| ~> 7*pi/4 */ 61152949Sbde return __kernel_cosdf(x + (hx > 0 ? -c4pio2 : c4pio2)); 62152949Sbde else { 63152949Sbde if(hx>0) 64152949Sbde return __kernel_sindf(x - c3pio2); 65152949Sbde else 66152949Sbde return __kernel_sindf(-c3pio2 - x); 67152949Sbde } 68152596Sbde } 692116Sjkh 702116Sjkh /* cos(Inf or NaN) is NaN */ 712116Sjkh else if (ix>=0x7f800000) return x-x; 722116Sjkh 73152596Sbde /* general argument reduction needed */ 742116Sjkh else { 752116Sjkh n = __ieee754_rem_pio2f(x,y); 762116Sjkh switch(n&3) { 77152869Sbde case 0: return __kernel_cosdf((double)y[0]+y[1]); 78152872Sbde case 1: return __kernel_sindf(-(double)y[0]-y[1]); 79152869Sbde case 2: return -__kernel_cosdf((double)y[0]+y[1]); 802116Sjkh default: 81152869Sbde return __kernel_sindf((double)y[0]+y[1]); 822116Sjkh } 832116Sjkh } 842116Sjkh} 85