s_cosf.c revision 8870
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
178870Srgrimesstatic char rcsid[] = "$Id: s_cosf.c,v 1.1.1.1 1994/08/19 09:39:58 jkh Exp $";
182116Sjkh#endif
192116Sjkh
202116Sjkh#include "math.h"
212116Sjkh#include "math_private.h"
222116Sjkh
232116Sjkh#ifdef __STDC__
242116Sjkhstatic const float one=1.0;
252116Sjkh#else
262116Sjkhstatic float one=1.0;
272116Sjkh#endif
282116Sjkh
292116Sjkh#ifdef __STDC__
302116Sjkh	float cosf(float x)
312116Sjkh#else
322116Sjkh	float cosf(x)
332116Sjkh	float x;
342116Sjkh#endif
352116Sjkh{
362116Sjkh	float y[2],z=0.0;
372116Sjkh	int32_t n,ix;
382116Sjkh
392116Sjkh	GET_FLOAT_WORD(ix,x);
402116Sjkh
412116Sjkh    /* |x| ~< pi/4 */
422116Sjkh	ix &= 0x7fffffff;
432116Sjkh	if(ix <= 0x3f490fd8) return __kernel_cosf(x,z);
442116Sjkh
452116Sjkh    /* cos(Inf or NaN) is NaN */
462116Sjkh	else if (ix>=0x7f800000) return x-x;
472116Sjkh
482116Sjkh    /* argument reduction needed */
492116Sjkh	else {
502116Sjkh	    n = __ieee754_rem_pio2f(x,y);
512116Sjkh	    switch(n&3) {
522116Sjkh		case 0: return  __kernel_cosf(y[0],y[1]);
532116Sjkh		case 1: return -__kernel_sinf(y[0],y[1],1);
542116Sjkh		case 2: return -__kernel_cosf(y[0],y[1]);
552116Sjkh		default:
562116Sjkh		        return  __kernel_sinf(y[0],y[1],1);
572116Sjkh	    }
582116Sjkh	}
592116Sjkh}
60