EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

StdLib/LibC/Math/s_cos.c

Go to the documentation of this file.
00001 /* @(#)s_cos.c 5.1 93/09/24 */
00002 /*
00003  * ====================================================
00004  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00005  *
00006  * Developed at SunPro, a Sun Microsystems, Inc. business.
00007  * Permission to use, copy, modify, and distribute this
00008  * software is freely granted, provided that this notice
00009  * is preserved.
00010  * ====================================================
00011  */
00012 #include  <LibConfig.h>
00013 #include  <sys/EfiCdefs.h>
00014 #if defined(LIBM_SCCS) && !defined(lint)
00015 __RCSID("$NetBSD: s_cos.c,v 1.10 2002/05/26 22:01:54 wiz Exp $");
00016 #endif
00017 
00018 /* cos(x)
00019  * Return cosine function of x.
00020  *
00021  * kernel function:
00022  *  __kernel_sin    ... sine function on [-pi/4,pi/4]
00023  *  __kernel_cos    ... cosine function on [-pi/4,pi/4]
00024  *  __ieee754_rem_pio2  ... argument reduction routine
00025  *
00026  * Method.
00027  *      Let S,C and T denote the sin, cos and tan respectively on
00028  *  [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
00029  *  in [-pi/4 , +pi/4], and let n = k mod 4.
00030  *  We have
00031  *
00032  *          n        sin(x)      cos(x)        tan(x)
00033  *     ----------------------------------------------------------
00034  *      0        S     C     T
00035  *      1        C    -S    -1/T
00036  *      2       -S    -C     T
00037  *      3       -C     S    -1/T
00038  *     ----------------------------------------------------------
00039  *
00040  * Special cases:
00041  *      Let trig be any of sin, cos, or tan.
00042  *      trig(+-INF)  is NaN, with signals;
00043  *      trig(NaN)    is that NaN;
00044  *
00045  * Accuracy:
00046  *  TRIG(x) returns trig(x) nearly rounded
00047  */
00048 
00049 #include "math.h"
00050 #include "math_private.h"
00051 
00052 double
00053 cos(double x)
00054 {
00055   double y[2],z=0.0;
00056   int32_t n, ix;
00057 
00058     /* High word of x. */
00059   GET_HIGH_WORD(ix,x);
00060 
00061     /* |x| ~< pi/4 */
00062   ix &= 0x7fffffff;
00063   if(ix <= 0x3fe921fb) return __kernel_cos(x,z);
00064 
00065     /* cos(Inf or NaN) is NaN */
00066   else if (ix>=0x7ff00000) return x-x;
00067 
00068     /* argument reduction needed */
00069   else {
00070       n = __ieee754_rem_pio2(x,y);
00071       switch(n&3) {
00072     case 0: return  __kernel_cos(y[0],y[1]);
00073     case 1: return -__kernel_sin(y[0],y[1],1);
00074     case 2: return -__kernel_cos(y[0],y[1]);
00075     default:
00076             return  __kernel_sin(y[0],y[1],1);
00077       }
00078   }
00079 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines