src/libm/k_cos.c
changeset 11683 48bcba563d9c
parent 6044 35448a5ea044
     1.1 --- a/src/libm/k_cos.c	Sat Nov 04 15:34:14 2017 -0700
     1.2 +++ b/src/libm/k_cos.c	Sat Nov 04 15:53:19 2017 -0700
     1.3 @@ -1,4 +1,3 @@
     1.4 -/* @(#)k_cos.c 5.1 93/09/24 */
     1.5  /*
     1.6   * ====================================================
     1.7   * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
     1.8 @@ -10,11 +9,6 @@
     1.9   * ====================================================
    1.10   */
    1.11  
    1.12 -#if defined(LIBM_SCCS) && !defined(lint)
    1.13 -static const char rcsid[] =
    1.14 -    "$NetBSD: k_cos.c,v 1.8 1995/05/10 20:46:22 jtc Exp $";
    1.15 -#endif
    1.16 -
    1.17  /*
    1.18   * __kernel_cos( x,  y )
    1.19   * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
    1.20 @@ -53,48 +47,36 @@
    1.21  #include "math_libm.h"
    1.22  #include "math_private.h"
    1.23  
    1.24 -#ifdef __STDC__
    1.25  static const double
    1.26 -#else
    1.27 -static double
    1.28 -#endif
    1.29 -  one = 1.00000000000000000000e+00,     /* 0x3FF00000, 0x00000000 */
    1.30 -    C1 = 4.16666666666666019037e-02,    /* 0x3FA55555, 0x5555554C */
    1.31 -    C2 = -1.38888888888741095749e-03,   /* 0xBF56C16C, 0x16C15177 */
    1.32 -    C3 = 2.48015872894767294178e-05,    /* 0x3EFA01A0, 0x19CB1590 */
    1.33 -    C4 = -2.75573143513906633035e-07,   /* 0xBE927E4F, 0x809C52AD */
    1.34 -    C5 = 2.08757232129817482790e-09,    /* 0x3E21EE9E, 0xBDB4B1C4 */
    1.35 -    C6 = -1.13596475577881948265e-11;   /* 0xBDA8FAE9, 0xBE8838D4 */
    1.36 +one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
    1.37 +C1  =  4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
    1.38 +C2  = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
    1.39 +C3  =  2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
    1.40 +C4  = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
    1.41 +C5  =  2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
    1.42 +C6  = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
    1.43  
    1.44 -#ifdef __STDC__
    1.45 -double attribute_hidden
    1.46 -__kernel_cos(double x, double y)
    1.47 -#else
    1.48 -double attribute_hidden
    1.49 -__kernel_cos(x, y)
    1.50 -     double x, y;
    1.51 -#endif
    1.52 +double attribute_hidden __kernel_cos(double x, double y)
    1.53  {
    1.54 -    double a, hz, z, r, qx;
    1.55 -    int32_t ix;
    1.56 -    GET_HIGH_WORD(ix, x);
    1.57 -    ix &= 0x7fffffff;           /* ix = |x|'s high word */
    1.58 -    if (ix < 0x3e400000) {      /* if x < 2**27 */
    1.59 -        if (((int) x) == 0)
    1.60 -            return one;         /* generate inexact */
    1.61 -    }
    1.62 -    z = x * x;
    1.63 -    r = z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * C6)))));
    1.64 -    if (ix < 0x3FD33333)        /* if |x| < 0.3 */
    1.65 -        return one - (0.5 * z - (z * r - x * y));
    1.66 -    else {
    1.67 -        if (ix > 0x3fe90000) {  /* x > 0.78125 */
    1.68 -            qx = 0.28125;
    1.69 -        } else {
    1.70 -            INSERT_WORDS(qx, ix - 0x00200000, 0);       /* x/4 */
    1.71 -        }
    1.72 -        hz = 0.5 * z - qx;
    1.73 -        a = one - qx;
    1.74 -        return a - (hz - (z * r - x * y));
    1.75 -    }
    1.76 +	double a,hz,z,r,qx;
    1.77 +	int32_t ix;
    1.78 +	GET_HIGH_WORD(ix,x);
    1.79 +	ix &= 0x7fffffff;			/* ix = |x|'s high word*/
    1.80 +	if(ix<0x3e400000) {			/* if x < 2**27 */
    1.81 +	    if(((int)x)==0) return one;		/* generate inexact */
    1.82 +	}
    1.83 +	z  = x*x;
    1.84 +	r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
    1.85 +	if(ix < 0x3FD33333) 			/* if |x| < 0.3 */
    1.86 +	    return one - (0.5*z - (z*r - x*y));
    1.87 +	else {
    1.88 +	    if(ix > 0x3fe90000) {		/* x > 0.78125 */
    1.89 +		qx = 0.28125;
    1.90 +	    } else {
    1.91 +	        INSERT_WORDS(qx,ix-0x00200000,0);	/* x/4 */
    1.92 +	    }
    1.93 +	    hz = 0.5*z-qx;
    1.94 +	    a  = one-qx;
    1.95 +	    return a - (hz - (z*r-x*y));
    1.96 +	}
    1.97  }