src/libm/k_cos.c
changeset 11683 48bcba563d9c
parent 6044 35448a5ea044
equal deleted inserted replaced
11682:b26412a89fbb 11683:48bcba563d9c
     1 /* @(#)k_cos.c 5.1 93/09/24 */
       
     2 /*
     1 /*
     3  * ====================================================
     2  * ====================================================
     4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
     3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
     5  *
     4  *
     6  * Developed at SunPro, a Sun Microsystems, Inc. business.
     5  * Developed at SunPro, a Sun Microsystems, Inc. business.
     7  * Permission to use, copy, modify, and distribute this
     6  * Permission to use, copy, modify, and distribute this
     8  * software is freely granted, provided that this notice
     7  * software is freely granted, provided that this notice
     9  * is preserved.
     8  * is preserved.
    10  * ====================================================
     9  * ====================================================
    11  */
    10  */
    12 
       
    13 #if defined(LIBM_SCCS) && !defined(lint)
       
    14 static const char rcsid[] =
       
    15     "$NetBSD: k_cos.c,v 1.8 1995/05/10 20:46:22 jtc Exp $";
       
    16 #endif
       
    17 
    11 
    18 /*
    12 /*
    19  * __kernel_cos( x,  y )
    13  * __kernel_cos( x,  y )
    20  * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
    14  * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
    21  * Input x is assumed to be bounded by ~pi/4 in magnitude.
    15  * Input x is assumed to be bounded by ~pi/4 in magnitude.
    51  */
    45  */
    52 
    46 
    53 #include "math_libm.h"
    47 #include "math_libm.h"
    54 #include "math_private.h"
    48 #include "math_private.h"
    55 
    49 
    56 #ifdef __STDC__
       
    57 static const double
    50 static const double
    58 #else
    51 one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
    59 static double
    52 C1  =  4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
    60 #endif
    53 C2  = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
    61   one = 1.00000000000000000000e+00,     /* 0x3FF00000, 0x00000000 */
    54 C3  =  2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
    62     C1 = 4.16666666666666019037e-02,    /* 0x3FA55555, 0x5555554C */
    55 C4  = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
    63     C2 = -1.38888888888741095749e-03,   /* 0xBF56C16C, 0x16C15177 */
    56 C5  =  2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
    64     C3 = 2.48015872894767294178e-05,    /* 0x3EFA01A0, 0x19CB1590 */
    57 C6  = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
    65     C4 = -2.75573143513906633035e-07,   /* 0xBE927E4F, 0x809C52AD */
       
    66     C5 = 2.08757232129817482790e-09,    /* 0x3E21EE9E, 0xBDB4B1C4 */
       
    67     C6 = -1.13596475577881948265e-11;   /* 0xBDA8FAE9, 0xBE8838D4 */
       
    68 
    58 
    69 #ifdef __STDC__
    59 double attribute_hidden __kernel_cos(double x, double y)
    70 double attribute_hidden
       
    71 __kernel_cos(double x, double y)
       
    72 #else
       
    73 double attribute_hidden
       
    74 __kernel_cos(x, y)
       
    75      double x, y;
       
    76 #endif
       
    77 {
    60 {
    78     double a, hz, z, r, qx;
    61 	double a,hz,z,r,qx;
    79     int32_t ix;
    62 	int32_t ix;
    80     GET_HIGH_WORD(ix, x);
    63 	GET_HIGH_WORD(ix,x);
    81     ix &= 0x7fffffff;           /* ix = |x|'s high word */
    64 	ix &= 0x7fffffff;			/* ix = |x|'s high word*/
    82     if (ix < 0x3e400000) {      /* if x < 2**27 */
    65 	if(ix<0x3e400000) {			/* if x < 2**27 */
    83         if (((int) x) == 0)
    66 	    if(((int)x)==0) return one;		/* generate inexact */
    84             return one;         /* generate inexact */
    67 	}
    85     }
    68 	z  = x*x;
    86     z = x * x;
    69 	r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
    87     r = z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * C6)))));
    70 	if(ix < 0x3FD33333) 			/* if |x| < 0.3 */
    88     if (ix < 0x3FD33333)        /* if |x| < 0.3 */
    71 	    return one - (0.5*z - (z*r - x*y));
    89         return one - (0.5 * z - (z * r - x * y));
    72 	else {
    90     else {
    73 	    if(ix > 0x3fe90000) {		/* x > 0.78125 */
    91         if (ix > 0x3fe90000) {  /* x > 0.78125 */
    74 		qx = 0.28125;
    92             qx = 0.28125;
    75 	    } else {
    93         } else {
    76 	        INSERT_WORDS(qx,ix-0x00200000,0);	/* x/4 */
    94             INSERT_WORDS(qx, ix - 0x00200000, 0);       /* x/4 */
    77 	    }
    95         }
    78 	    hz = 0.5*z-qx;
    96         hz = 0.5 * z - qx;
    79 	    a  = one-qx;
    97         a = one - qx;
    80 	    return a - (hz - (z*r-x*y));
    98         return a - (hz - (z * r - x * y));
    81 	}
    99     }
       
   100 }
    82 }