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 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 /* tanl(x)
00022  * Return tangent function of x.
00023  *
00024  * kernel function:
00025  *     __kernel_tanl        ... tangent function on [-pi/4,pi/4]
00026  *     __ieee754_rem_pio2l  ... argument reduction routine
00027  *
00028  * Method.
00029  *      Let S,C and T denote the sin, cos and tan respectively on
00030  *     [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
00031  *     in [-pi/4 , +pi/4], and let n = k mod 4.
00032  *     We have
00033  *
00034  *          n        sin(x)      cos(x)        tan(x)
00035  *     ----------------------------------------------------------
00036  *         0         S         C           T
00037  *         1         C        -S          -1/T
00038  *         2        -S        -C           T
00039  *         3        -C         S          -1/T
00040  *     ----------------------------------------------------------
00041  *
00042  * Special cases:
00043  *      Let trig be any of sin, cos, or tan.
00044  *      trig(+-INF)  is NaN, with signals;
00045  *      trig(NaN)    is that NaN;
00046  *
00047  * Accuracy:
00048  *     TRIG(x) returns trig(x) nearly rounded
00049  */
00050 
00051 #include "math.h"
00052 #include "math_private.h"
00053 
00054 #ifdef __STDC__
00055        long double __tanl(long double x)
00056 #else
00057        long double __tanl(x)
00058        long double x;
00059 #endif
00060 {
00061        long double y[2],z=0.0;
00062        int32_t n, se;
00063 
00064     /* High word of x. */
00065        GET_LDOUBLE_EXP(se,x);
00066 
00067     /* |x| ~< pi/4 */
00068        se &= 0x7fff;
00069        if(se <= 0x3ffe) return __kernel_tanl(x,z,1);
00070 
00071     /* tan(Inf or NaN) is NaN */
00072        else if (se==0x7fff) return x-x;          /* NaN */
00073 
00074     /* argument reduction needed */
00075        else {
00076            n = __ieee754_rem_pio2l(x,y);
00077            return __kernel_tanl(y[0],y[1],1-((n&1)<<1)); /*   1 -- n even
00078                                                  -1 -- n odd */
00079        }
00080 }
00081 weak_alias (__tanl, tanl)