Merge common usage of mul_split function
[glibc.git] / sysdeps / ieee754 / ldbl-96 / s_tanl.c
blob3fbe4a8f6baa97219b350c68fe665c0247bd4ca2
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 <errno.h>
52 #include <math.h>
53 #include <math_private.h>
55 long double __tanl(long double x)
57 long double y[2],z=0.0;
58 int32_t n, se, i0, i1;
60 /* High word of x. */
61 GET_LDOUBLE_WORDS(se,i0,i1,x);
63 /* |x| ~< pi/4 */
64 se &= 0x7fff;
65 if(se <= 0x3ffe) return __kernel_tanl(x,z,1);
67 /* tan(Inf or NaN) is NaN */
68 else if (se==0x7fff) {
69 if (i1 == 0 && i0 == 0x80000000)
70 __set_errno (EDOM);
71 return x-x;
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)