Back to index

glibc  2.9
s_cosf.c
Go to the documentation of this file.
00001 /* s_cosf.c -- float version of s_cos.c.
00002  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice 
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 #if defined(LIBM_SCCS) && !defined(lint)
00017 static char rcsid[] = "$NetBSD: s_cosf.c,v 1.4 1995/05/10 20:47:03 jtc Exp $";
00018 #endif
00019 
00020 #include "math.h"
00021 #include "math_private.h"
00022 
00023 #ifdef __STDC__
00024 static const float one=1.0;
00025 #else
00026 static float one=1.0;
00027 #endif
00028 
00029 #ifdef __STDC__
00030        float __cosf(float x)
00031 #else
00032        float __cosf(x)
00033        float x;
00034 #endif
00035 {
00036        float y[2],z=0.0;
00037        int32_t n,ix;
00038 
00039        GET_FLOAT_WORD(ix,x);
00040 
00041     /* |x| ~< pi/4 */
00042        ix &= 0x7fffffff;
00043        if(ix <= 0x3f490fd8) return __kernel_cosf(x,z);
00044 
00045     /* cos(Inf or NaN) is NaN */
00046        else if (ix>=0x7f800000) return x-x;
00047 
00048     /* argument reduction needed */
00049        else {
00050            n = __ieee754_rem_pio2f(x,y);
00051            switch(n&3) {
00052               case 0: return  __kernel_cosf(y[0],y[1]);
00053               case 1: return -__kernel_sinf(y[0],y[1],1);
00054               case 2: return -__kernel_cosf(y[0],y[1]);
00055               default:
00056                       return  __kernel_sinf(y[0],y[1],1);
00057            }
00058        }
00059 }
00060 weak_alias (__cosf, cosf)