Back to index

glibc  2.9
k_cosf.c
Go to the documentation of this file.
00001 /* k_cosf.c -- float version of k_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: k_cosf.c,v 1.4 1995/05/10 20:46:23 jtc Exp $";
00018 #endif
00019 
00020 #include "math.h"
00021 #include "math_private.h"
00022 
00023 #ifdef __STDC__
00024 static const float 
00025 #else
00026 static float 
00027 #endif
00028 one =  1.0000000000e+00, /* 0x3f800000 */
00029 C1  =  4.1666667908e-02, /* 0x3d2aaaab */
00030 C2  = -1.3888889225e-03, /* 0xbab60b61 */
00031 C3  =  2.4801587642e-05, /* 0x37d00d01 */
00032 C4  = -2.7557314297e-07, /* 0xb493f27c */
00033 C5  =  2.0875723372e-09, /* 0x310f74f6 */
00034 C6  = -1.1359647598e-11; /* 0xad47d74e */
00035 
00036 #ifdef __STDC__
00037        float __kernel_cosf(float x, float y)
00038 #else
00039        float __kernel_cosf(x, y)
00040        float x,y;
00041 #endif
00042 {
00043        float a,hz,z,r,qx;
00044        int32_t ix;
00045        GET_FLOAT_WORD(ix,x);
00046        ix &= 0x7fffffff;                  /* ix = |x|'s high word*/
00047        if(ix<0x32000000) {                /* if x < 2**27 */
00048            if(((int)x)==0) return one;           /* generate inexact */
00049        }
00050        z  = x*x;
00051        r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
00052        if(ix < 0x3e99999a)                /* if |x| < 0.3 */ 
00053            return one - ((float)0.5*z - (z*r - x*y));
00054        else {
00055            if(ix > 0x3f480000) {          /* x > 0.78125 */
00056               qx = (float)0.28125;
00057            } else {
00058                SET_FLOAT_WORD(qx,ix-0x01000000); /* x/4 */
00059            }
00060            hz = (float)0.5*z-qx;
00061            a  = one-qx;
00062            return a - (hz - (z*r-x*y));
00063        }
00064 }