Back to index

glibc  2.9
s_cosl.c
Go to the documentation of this file.
00001 /* s_cosl.c -- long double version of s_cos.c.
00002  * Conversion to long double by Ulrich Drepper,
00003  * Cygnus Support, drepper@cygnus.com.
00004  */
00005 
00006 /*
00007  * ====================================================
00008  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00009  *
00010  * Developed at SunPro, a Sun Microsystems, Inc. business.
00011  * Permission to use, copy, modify, and distribute this
00012  * software is freely granted, provided that this notice
00013  * is preserved.
00014  * ====================================================
00015  */
00016 
00017 #if defined(LIBM_SCCS) && !defined(lint)
00018 static char rcsid[] = "$NetBSD: $";
00019 #endif
00020 
00021 /* cosl(x)
00022  * Return cosine function of x.
00023  *
00024  * kernel function:
00025  *     __kernel_sinl        ... sine function on [-pi/4,pi/4]
00026  *     __kernel_cosl        ... cosine function on [-pi/4,pi/4]
00027  *     __ieee754_rem_pio2l  ... argument reduction routine
00028  *
00029  * Method.
00030  *      Let S,C and T denote the sin, cos and tan respectively on
00031  *     [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
00032  *     in [-pi/4 , +pi/4], and let n = k mod 4.
00033  *     We have
00034  *
00035  *          n        sin(x)      cos(x)        tan(x)
00036  *     ----------------------------------------------------------
00037  *         0         S         C           T
00038  *         1         C        -S          -1/T
00039  *         2        -S        -C           T
00040  *         3        -C         S          -1/T
00041  *     ----------------------------------------------------------
00042  *
00043  * Special cases:
00044  *      Let trig be any of sin, cos, or tan.
00045  *      trig(+-INF)  is NaN, with signals;
00046  *      trig(NaN)    is that NaN;
00047  *
00048  * Accuracy:
00049  *     TRIG(x) returns trig(x) nearly rounded
00050  */
00051 
00052 #include "math.h"
00053 #include "math_private.h"
00054 
00055 #ifdef __STDC__
00056        long double __cosl(long double x)
00057 #else
00058        long double __cosl(x)
00059        long double x;
00060 #endif
00061 {
00062        long double y[2],z=0.0;
00063        int32_t n, se, i0, i1;
00064 
00065     /* High word of x. */
00066        GET_LDOUBLE_WORDS(se,i0,i1,x);
00067 
00068     /* |x| ~< pi/4 */
00069        se &= 0x7fff;
00070        if(se < 0x3ffe || (se == 0x3ffe && i0 <= 0xc90fdaa2))
00071          return __kernel_cosl(x,z);
00072 
00073     /* cos(Inf or NaN) is NaN */
00074        else if (se==0x7fff) return x-x;
00075 
00076     /* argument reduction needed */
00077        else {
00078            n = __ieee754_rem_pio2l(x,y);
00079            switch(n&3) {
00080               case 0: return  __kernel_cosl(y[0],y[1]);
00081               case 1: return -__kernel_sinl(y[0],y[1],1);
00082               case 2: return -__kernel_cosl(y[0],y[1]);
00083               default:
00084                       return  __kernel_sinl(y[0],y[1],1);
00085            }
00086        }
00087 }
00088 weak_alias (__cosl, cosl)