POK
/home/jaouen/pok_official/pok/trunk/libpok/libm/k_cosf.c
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Sat Jan 31 20:12:07 2009 
00015  */
00016 
00017 /* k_cosf.c -- float version of k_cos.c
00018  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
00019  */
00020 
00021 /*
00022  * ====================================================
00023  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00024  *
00025  * Developed at SunPro, a Sun Microsystems, Inc. business.
00026  * Permission to use, copy, modify, and distribute this
00027  * software is freely granted, provided that this notice
00028  * is preserved.
00029  * ====================================================
00030  */
00031 
00032 #ifdef POK_NEEDS_LIBMATH
00033 
00034 #include <libm.h>
00035 #include "math_private.h"
00036 
00037 static const float
00038 one =  1.0000000000e+00, /* 0x3f800000 */
00039 C1  =  4.1666667908e-02, /* 0x3d2aaaab */
00040 C2  = -1.3888889225e-03, /* 0xbab60b61 */
00041 C3  =  2.4801587642e-05, /* 0x37d00d01 */
00042 C4  = -2.7557314297e-07, /* 0xb493f27c */
00043 C5  =  2.0875723372e-09, /* 0x310f74f6 */
00044 C6  = -1.1359647598e-11; /* 0xad47d74e */
00045 
00046 float
00047 __kernel_cosf(float x, float y)
00048 {
00049         float a,hz,z,r,qx;
00050         int32_t ix;
00051         GET_FLOAT_WORD(ix,x);
00052         ix &= 0x7fffffff;                       /* ix = |x|'s high word*/
00053         if(ix<0x32000000) {                     /* if x < 2**27 */
00054             if(((int)x)==0) return one;         /* generate inexact */
00055         }
00056         z  = x*x;
00057         r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
00058         if(ix < 0x3e99999a)                     /* if |x| < 0.3 */
00059             return one - ((float)0.5*z - (z*r - x*y));
00060         else {
00061             if(ix > 0x3f480000) {               /* x > 0.78125 */
00062                 qx = (float)0.28125;
00063             } else {
00064                 SET_FLOAT_WORD(qx,ix-0x01000000);       /* x/4 */
00065             }
00066             hz = (float)0.5*z-qx;
00067             a  = one-qx;
00068             return a - (hz - (z*r-x*y));
00069         }
00070 }
00071 
00072 #endif
00073