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 Jakub Jelinek, jj@ultra.linux.cz.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 /* cosl(x)
00017  * Return cosine function of x.
00018  *
00019  * kernel function:
00020  *     __kernel_sinl        ... sine function on [-pi/4,pi/4]
00021  *     __kernel_cosl        ... cosine function on [-pi/4,pi/4]
00022  *     __ieee754_rem_pio2l  ... argument reduction routine
00023  *
00024  * Method.
00025  *      Let S,C and T denote the sin, cos and tan respectively on
00026  *     [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
00027  *     in [-pi/4 , +pi/4], and let n = k mod 4.
00028  *     We have
00029  *
00030  *          n        sin(x)      cos(x)        tan(x)
00031  *     ----------------------------------------------------------
00032  *         0         S         C           T
00033  *         1         C        -S          -1/T
00034  *         2        -S        -C           T
00035  *         3        -C         S          -1/T
00036  *     ----------------------------------------------------------
00037  *
00038  * Special cases:
00039  *      Let trig be any of sin, cos, or tan.
00040  *      trig(+-INF)  is NaN, with signals;
00041  *      trig(NaN)    is that NaN;
00042  *
00043  * Accuracy:
00044  *     TRIG(x) returns trig(x) nearly rounded
00045  */
00046 
00047 #include "math.h"
00048 #include "math_private.h"
00049 
00050 #ifdef __STDC__
00051        long double __cosl(long double x)
00052 #else
00053        long double __cosl(x)
00054        long double x;
00055 #endif
00056 {
00057        long double y[2],z=0.0L;
00058        int64_t n, ix;
00059 
00060     /* High word of x. */
00061        GET_LDOUBLE_MSW64(ix,x);
00062 
00063     /* |x| ~< pi/4 */
00064        ix &= 0x7fffffffffffffffLL;
00065        if(ix <= 0x3ffe921fb54442d1LL)
00066          return __kernel_cosl(x,z);
00067 
00068     /* cos(Inf or NaN) is NaN */
00069        else if (ix>=0x7fff000000000000LL) return x-x;
00070 
00071     /* argument reduction needed */
00072        else {
00073            n = __ieee754_rem_pio2l(x,y);
00074            switch(n&3) {
00075               case 0: return  __kernel_cosl(y[0],y[1]);
00076               case 1: return -__kernel_sinl(y[0],y[1],1);
00077               case 2: return -__kernel_cosl(y[0],y[1]);
00078               default:
00079                       return  __kernel_sinl(y[0],y[1],1);
00080            }
00081        }
00082 }
00083 weak_alias (__cosl, cosl)