s_cosf.c revision 152540
12116Sjkh/* s_cosf.c -- float version of s_cos.c. 22116Sjkh * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 32116Sjkh */ 42116Sjkh 52116Sjkh/* 62116Sjkh * ==================================================== 72116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 82116Sjkh * 92116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business. 102116Sjkh * Permission to use, copy, modify, and distribute this 118870Srgrimes * software is freely granted, provided that this notice 122116Sjkh * is preserved. 132116Sjkh * ==================================================== 142116Sjkh */ 152116Sjkh 162116Sjkh#ifndef lint 1750476Speterstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/s_cosf.c 152540 2005-11-17 03:53:22Z bde $"; 182116Sjkh#endif 192116Sjkh 202116Sjkh#include "math.h" 212116Sjkh#include "math_private.h" 222116Sjkh 2397413Salfredfloat 2497413Salfredcosf(float x) 252116Sjkh{ 26152540Sbde float y[2]; 272116Sjkh int32_t n,ix; 282116Sjkh 292116Sjkh GET_FLOAT_WORD(ix,x); 30152540Sbde ix &= 0x7fffffff; 312116Sjkh 32152540Sbde if(ix <= 0x3f490fda) { /* |x| ~<= pi/4 */ 33152540Sbde if(ix<0x39800000) /* |x| < 2**-12 */ 34152540Sbde if(((int)x)==0) return 1.0; /* 1 with inexact if x != 0 */ 35152540Sbde return __kernel_cosf(x,0.0); 36151620Sbde } 372116Sjkh 382116Sjkh /* cos(Inf or NaN) is NaN */ 392116Sjkh else if (ix>=0x7f800000) return x-x; 402116Sjkh 412116Sjkh /* argument reduction needed */ 422116Sjkh else { 432116Sjkh n = __ieee754_rem_pio2f(x,y); 442116Sjkh switch(n&3) { 452116Sjkh case 0: return __kernel_cosf(y[0],y[1]); 462116Sjkh case 1: return -__kernel_sinf(y[0],y[1],1); 472116Sjkh case 2: return -__kernel_cosf(y[0],y[1]); 482116Sjkh default: 492116Sjkh return __kernel_sinf(y[0],y[1],1); 502116Sjkh } 512116Sjkh } 522116Sjkh} 53