1*181254a7Smrg /* s_tanl.c -- long double version of s_tan.c.
2*181254a7Smrg * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
3*181254a7Smrg */
4*181254a7Smrg
5*181254a7Smrg /* @(#)s_tan.c 5.1 93/09/24 */
6*181254a7Smrg /*
7*181254a7Smrg * ====================================================
8*181254a7Smrg * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9*181254a7Smrg *
10*181254a7Smrg * Developed at SunPro, a Sun Microsystems, Inc. business.
11*181254a7Smrg * Permission to use, copy, modify, and distribute this
12*181254a7Smrg * software is freely granted, provided that this notice
13*181254a7Smrg * is preserved.
14*181254a7Smrg * ====================================================
15*181254a7Smrg */
16*181254a7Smrg
17*181254a7Smrg /* tanq(x)
18*181254a7Smrg * Return tangent function of x.
19*181254a7Smrg *
20*181254a7Smrg * kernel function:
21*181254a7Smrg * __quadmath_kernel_tanq ... tangent function on [-pi/4,pi/4]
22*181254a7Smrg * __quadmath_rem_pio2q ... argument reduction routine
23*181254a7Smrg *
24*181254a7Smrg * Method.
25*181254a7Smrg * Let S,C and T denote the sin, cos and tan respectively on
26*181254a7Smrg * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
27*181254a7Smrg * in [-pi/4 , +pi/4], and let n = k mod 4.
28*181254a7Smrg * We have
29*181254a7Smrg *
30*181254a7Smrg * n sin(x) cos(x) tan(x)
31*181254a7Smrg * ----------------------------------------------------------
32*181254a7Smrg * 0 S C T
33*181254a7Smrg * 1 C -S -1/T
34*181254a7Smrg * 2 -S -C T
35*181254a7Smrg * 3 -C S -1/T
36*181254a7Smrg * ----------------------------------------------------------
37*181254a7Smrg *
38*181254a7Smrg * Special cases:
39*181254a7Smrg * Let trig be any of sin, cos, or tan.
40*181254a7Smrg * trig(+-INF) is NaN, with signals;
41*181254a7Smrg * trig(NaN) is that NaN;
42*181254a7Smrg *
43*181254a7Smrg * Accuracy:
44*181254a7Smrg * TRIG(x) returns trig(x) nearly rounded
45*181254a7Smrg */
46*181254a7Smrg
47*181254a7Smrg #include "quadmath-imp.h"
48*181254a7Smrg
tanq(__float128 x)49*181254a7Smrg __float128 tanq(__float128 x)
50*181254a7Smrg {
51*181254a7Smrg __float128 y[2],z=0;
52*181254a7Smrg int64_t n, ix;
53*181254a7Smrg
54*181254a7Smrg /* High word of x. */
55*181254a7Smrg GET_FLT128_MSW64(ix,x);
56*181254a7Smrg
57*181254a7Smrg /* |x| ~< pi/4 */
58*181254a7Smrg ix &= 0x7fffffffffffffffLL;
59*181254a7Smrg if(ix <= 0x3ffe921fb54442d1LL) return __quadmath_kernel_tanq(x,z,1);
60*181254a7Smrg
61*181254a7Smrg /* tanq(Inf or NaN) is NaN */
62*181254a7Smrg else if (ix>=0x7fff000000000000LL) {
63*181254a7Smrg if (ix == 0x7fff000000000000LL) {
64*181254a7Smrg GET_FLT128_LSW64(n,x);
65*181254a7Smrg if (n == 0)
66*181254a7Smrg errno = EDOM;
67*181254a7Smrg }
68*181254a7Smrg return x-x; /* NaN */
69*181254a7Smrg }
70*181254a7Smrg
71*181254a7Smrg /* argument reduction needed */
72*181254a7Smrg else {
73*181254a7Smrg n = __quadmath_rem_pio2q(x,y);
74*181254a7Smrg return __quadmath_kernel_tanq(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
75*181254a7Smrg -1 -- n odd */
76*181254a7Smrg }
77*181254a7Smrg }
78