src/libm/s_cos.c
changeset 11683 48bcba563d9c
parent 6044 35448a5ea044
equal deleted inserted replaced
11682:b26412a89fbb 11683:48bcba563d9c
     1 /* @(#)s_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: s_cos.c,v 1.7 1995/05/10 20:47:02 jtc Exp $";
       
    16 #endif
       
    17 
    11 
    18 /* cos(x)
    12 /* cos(x)
    19  * Return cosine function of x.
    13  * Return cosine function of x.
    20  *
    14  *
    21  * kernel function:
    15  * kernel function:
    47  */
    41  */
    48 
    42 
    49 #include "math_libm.h"
    43 #include "math_libm.h"
    50 #include "math_private.h"
    44 #include "math_private.h"
    51 
    45 
    52 libm_hidden_proto(cos)
    46 double cos(double x)
    53 #ifdef __STDC__
       
    54      double cos(double x)
       
    55 #else
       
    56      double cos(x)
       
    57      double x;
       
    58 #endif
       
    59 {
    47 {
    60     double y[2], z = 0.0;
    48 	double y[2],z=0.0;
    61     int32_t n, ix;
    49 	int32_t n, ix;
    62 
    50 
    63     /* High word of x. */
    51     /* High word of x. */
    64     GET_HIGH_WORD(ix, x);
    52 	GET_HIGH_WORD(ix,x);
    65 
    53 
    66     /* |x| ~< pi/4 */
    54     /* |x| ~< pi/4 */
    67     ix &= 0x7fffffff;
    55 	ix &= 0x7fffffff;
    68     if (ix <= 0x3fe921fb)
    56 	if(ix <= 0x3fe921fb) return __kernel_cos(x,z);
    69         return __kernel_cos(x, z);
       
    70 
    57 
    71     /* cos(Inf or NaN) is NaN */
    58     /* cos(Inf or NaN) is NaN */
    72     else if (ix >= 0x7ff00000)
    59 	else if (ix>=0x7ff00000) return x-x;
    73         return x - x;
       
    74 
    60 
    75     /* argument reduction needed */
    61     /* argument reduction needed */
    76     else {
    62 	else {
    77         n = __ieee754_rem_pio2(x, y);
    63 	    n = __ieee754_rem_pio2(x,y);
    78         switch (n & 3) {
    64 	    switch(n&3) {
    79         case 0:
    65 		case 0: return  __kernel_cos(y[0],y[1]);
    80             return __kernel_cos(y[0], y[1]);
    66 		case 1: return -__kernel_sin(y[0],y[1],1);
    81         case 1:
    67 		case 2: return -__kernel_cos(y[0],y[1]);
    82             return -__kernel_sin(y[0], y[1], 1);
    68 		default:
    83         case 2:
    69 		        return  __kernel_sin(y[0],y[1],1);
    84             return -__kernel_cos(y[0], y[1]);
    70 	    }
    85         default:
    71 	}
    86             return __kernel_sin(y[0], y[1], 1);
       
    87         }
       
    88     }
       
    89 }
    72 }
    90 
       
    91 libm_hidden_def(cos)
    73 libm_hidden_def(cos)