Back to index

glibc  2.9
s_sinl.c
Go to the documentation of this file.
00001 /* s_sinl.c -- long double version of s_sin.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 /* sinl(x)
00017  * Return sine function of x.
00018  *
00019  * kernel function:
00020  *     __kernel_sinl        ... sine function on [-pi/4,pi/4]
00021  *     __kernel_cosl        ... cose 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 #include <math_ldbl_opt.h>
00050 
00051 #ifdef __STDC__
00052        long double __sinl(long double x)
00053 #else
00054        long double __sinl(x)
00055        long double x;
00056 #endif
00057 {
00058        long double y[2],z=0.0L;
00059        int64_t n, ix;
00060 
00061     /* High word of x. */
00062        GET_LDOUBLE_MSW64(ix,x);
00063 
00064     /* |x| ~< pi/4 */
00065        ix &= 0x7fffffffffffffffLL;
00066        if(ix <= 0x3fe921fb54442d10LL)
00067          return __kernel_sinl(x,z,0);
00068 
00069     /* sin(Inf or NaN) is NaN */
00070        else if (ix>=0x7ff0000000000000LL) return x-x;
00071 
00072     /* argument reduction needed */
00073        else {
00074            n = __ieee754_rem_pio2l(x,y);
00075            switch(n&3) {
00076               case 0: return  __kernel_sinl(y[0],y[1],1);
00077               case 1: return  __kernel_cosl(y[0],y[1]);
00078               case 2: return -__kernel_sinl(y[0],y[1],1);
00079               default:
00080                      return -__kernel_cosl(y[0],y[1]);
00081            }
00082        }
00083 }
00084 long_double_symbol (libm, __sinl, sinl);