Updated to fedora-glibc-20090427T1419
[glibc/history.git] / sysdeps / ieee754 / ldbl-96 / s_tanl.c
blob97a0b27f32feaa00c4290afb71e075e6856ca228
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 */
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
19 #endif
21 /* tanl(x)
22 * Return tangent function of x.
24 * kernel function:
25 * __kernel_tanl ... tangent function on [-pi/4,pi/4]
26 * __ieee754_rem_pio2l ... argument reduction routine
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
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 * ----------------------------------------------------------
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;
47 * Accuracy:
48 * TRIG(x) returns trig(x) nearly rounded
51 #include "math.h"
52 #include "math_private.h"
54 #ifdef __STDC__
55 long double __tanl(long double x)
56 #else
57 long double __tanl(x)
58 long double x;
59 #endif
61 long double y[2],z=0.0;
62 int32_t n, se;
64 /* High word of x. */
65 GET_LDOUBLE_EXP(se,x);
67 /* |x| ~< pi/4 */
68 se &= 0x7fff;
69 if(se <= 0x3ffe) return __kernel_tanl(x,z,1);
71 /* tan(Inf or NaN) is NaN */
72 else if (se==0x7fff) return x-x; /* NaN */
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 */
81 weak_alias (__tanl, tanl)