Back to index

glibc  2.9
s_tanl.c
Go to the documentation of this file.
00001 /* s_tanl.c -- long double version of s_tan.c.
00002  * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
00003  */
00004   
00005 /* @(#)s_tan.c 5.1 93/09/24 */
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 /* tanl(x)
00018  * Return tangent function of x.
00019  *
00020  * kernel function:
00021  *     __kernel_tanl        ... tangent 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 __tanl(long double x)
00052 #else
00053        long double __tanl(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) return __kernel_tanl(x,z,1);
00066 
00067     /* tanl(Inf or NaN) is NaN */
00068        else if (ix>=0x7fff000000000000LL) return x-x;          /* NaN */
00069 
00070     /* argument reduction needed */
00071        else {
00072            n = __ieee754_rem_pio2l(x,y);
00073            return __kernel_tanl(y[0],y[1],1-((n&1)<<1)); /*   1 -- n even
00074                                                  -1 -- n odd */
00075        }
00076 }
00077 weak_alias (__tanl, tanl)