s_cosf.c revision 152871
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 152871 2005-11-28 05:46:13Z 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]; 392116Sjkh int32_t n,ix; 402116Sjkh 41152596Sbde x = fabsf(x); 422116Sjkh GET_FLOAT_WORD(ix,x); 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 */ 50152871Sbde if(ix<=0x4016cbe3) /* |x| ~<= 3pi/4 */ 51152596Sbde return -__kernel_sindf(x - c1pio2); 52152596Sbde else 53152596Sbde return -__kernel_cosdf(x - c2pio2); 54152596Sbde } 55152871Sbde if(ix<=0x40e231d5) { /* |x| ~<= 9*pi/4 */ 56152871Sbde if(ix<=0x40afeddf) /* |x| ~<= 7*pi/4 */ 57152596Sbde return __kernel_sindf(x - c3pio2); 58152596Sbde else 59152596Sbde return __kernel_cosdf(x - c4pio2); 60152596Sbde } 612116Sjkh 622116Sjkh /* cos(Inf or NaN) is NaN */ 632116Sjkh else if (ix>=0x7f800000) return x-x; 642116Sjkh 65152596Sbde /* general argument reduction needed */ 662116Sjkh else { 672116Sjkh n = __ieee754_rem_pio2f(x,y); 682116Sjkh switch(n&3) { 69152869Sbde case 0: return __kernel_cosdf((double)y[0]+y[1]); 70152869Sbde case 1: return -__kernel_sindf((double)y[0]+y[1]); 71152869Sbde case 2: return -__kernel_cosdf((double)y[0]+y[1]); 722116Sjkh default: 73152869Sbde return __kernel_sindf((double)y[0]+y[1]); 742116Sjkh } 752116Sjkh } 762116Sjkh} 77