97a0b27f32feaa00c4290afb71e075e6856ca228
[platform/upstream/glibc.git] / sysdeps / ieee754 / ldbl-96 / s_tanl.c
1 /* s_tanl.c -- long double version of s_tan.c.
2  * Conversion to long double by Ulrich Drepper,
3  * Cygnus Support, drepper@cygnus.com.
4  */
5
6 /*
7  * ====================================================
8  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9  *
10  * Developed at SunPro, a Sun Microsystems, Inc. business.
11  * Permission to use, copy, modify, and distribute this
12  * software is freely granted, provided that this notice
13  * is preserved.
14  * ====================================================
15  */
16
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
19 #endif
20
21 /* tanl(x)
22  * Return tangent function of x.
23  *
24  * kernel function:
25  *      __kernel_tanl           ... tangent function on [-pi/4,pi/4]
26  *      __ieee754_rem_pio2l     ... argument reduction routine
27  *
28  * Method.
29  *      Let S,C and T denote the sin, cos and tan respectively on
30  *      [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
31  *      in [-pi/4 , +pi/4], and let n = k mod 4.
32  *      We have
33  *
34  *          n        sin(x)      cos(x)        tan(x)
35  *     ----------------------------------------------------------
36  *          0          S           C             T
37  *          1          C          -S            -1/T
38  *          2         -S          -C             T
39  *          3         -C           S            -1/T
40  *     ----------------------------------------------------------
41  *
42  * Special cases:
43  *      Let trig be any of sin, cos, or tan.
44  *      trig(+-INF)  is NaN, with signals;
45  *      trig(NaN)    is that NaN;
46  *
47  * Accuracy:
48  *      TRIG(x) returns trig(x) nearly rounded
49  */
50
51 #include "math.h"
52 #include "math_private.h"
53
54 #ifdef __STDC__
55         long double __tanl(long double x)
56 #else
57         long double __tanl(x)
58         long double x;
59 #endif
60 {
61         long double y[2],z=0.0;
62         int32_t n, se;
63
64     /* High word of x. */
65         GET_LDOUBLE_EXP(se,x);
66
67     /* |x| ~< pi/4 */
68         se &= 0x7fff;
69         if(se <= 0x3ffe) return __kernel_tanl(x,z,1);
70
71     /* tan(Inf or NaN) is NaN */
72         else if (se==0x7fff) return x-x;                /* NaN */
73
74     /* argument reduction needed */
75         else {
76             n = __ieee754_rem_pio2l(x,y);
77             return __kernel_tanl(y[0],y[1],1-((n&1)<<1)); /*   1 -- n even
78                                                         -1 -- n odd */
79         }
80 }
81 weak_alias (__tanl, tanl)