2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
9 * ====================================================
13 Long double expansions contributed by
14 Stephen L. Moshier <moshier@na-net.ornl.gov>
17 /* __kernel_tanl( x, y, k )
18 * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854
19 * Input x is assumed to be bounded by ~pi/4 in magnitude.
20 * Input y is the tail of x.
21 * Input k indicates whether tan (if k=1) or
22 * -1/tan (if k= -1) is returned.
25 * 1. Since tan(-x) = -tan(x), we need only to consider positive x.
26 * 2. if x < 2^-57, return x with inexact if x!=0.
27 * 3. tan(x) is approximated by a rational form x + x^3 / 3 + x^5 R(x^2)
30 * Note: tan(x+y) = tan(x) + tan'(x)*y
31 * ~ tan(x) + (1+x*x)*y
32 * Therefore, for better accuracy in computing tan(x+y), let
35 * tan(x+y) = x + (x^3 / 3 + (x^2 *(r+y)+y))
37 * 4. For x in [0.67433,pi/4], let y = pi/4 - x, then
38 * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
39 * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
43 #include "math_private.h"
45 static const long double
50 pio4hi
= 7.8539816339744830961566084581987569936977E-1L,
51 pio4lo
= 2.1679525325309452561992610065108379921906E-35L,
53 /* tan x = x + x^3 / 3 + x^5 T(x^2)/U(x^2)
54 0 <= x <= 0.6743316650390625
55 Peak relative error 8.0e-36 */
56 TH
= 3.333333333333333333333333333333333333333E-1L,
57 T0
= -1.813014711743583437742363284336855889393E7L
,
58 T1
= 1.320767960008972224312740075083259247618E6L
,
59 T2
= -2.626775478255838182468651821863299023956E4L
,
60 T3
= 1.764573356488504935415411383687150199315E2L
,
61 T4
= -3.333267763822178690794678978979803526092E-1L,
63 U0
= -1.359761033807687578306772463253710042010E8L
,
64 U1
= 6.494370630656893175666729313065113194784E7L
,
65 U2
= -4.180787672237927475505536849168729386782E6L
,
66 U3
= 8.031643765106170040139966622980914621521E4L
,
67 U4
= -5.323131271912475695157127875560667378597E2L
;
68 /* 1.000000000000000000000000000000000000000E0 */
73 __kernel_tanl (long double x
, long double y
, int iy
)
76 __kernel_tanl (x
, y
, iy
)
81 long double z
, r
, v
, w
, s
;
83 ieee854_long_double_shape_type u
, u1
;
86 ix
= u
.parts32
.w0
& 0x7fffffff;
87 if (ix
< 0x3fc60000) /* x < 2**-57 */
90 { /* generate inexact */
91 if ((ix
| u
.parts32
.w1
| u
.parts32
.w2
| u
.parts32
.w3
93 return one
/ fabs (x
);
95 return (iy
== 1) ? x
: -one
/ x
;
98 if (ix
>= 0x3ffe5942) /* |x| >= 0.6743316650390625 */
100 if ((u
.parts32
.w0
& 0x80000000) != 0)
114 r
= T0
+ z
* (T1
+ z
* (T2
+ z
* (T3
+ z
* T4
)));
115 v
= U0
+ z
* (U1
+ z
* (U2
+ z
* (U3
+ z
* (U4
+ z
))));
119 r
= y
+ z
* (s
* r
+ y
);
122 if (ix
>= 0x3ffe5942)
124 v
= (long double) iy
;
125 w
= (v
- 2.0 * (x
- (w
* w
/ (w
+ v
) - r
)));
133 { /* if allow error up to 2 ulp,
134 simply return -1.0/(x+r) here */
135 /* compute -1.0/(x+r) accurately */
139 v
= r
- (u1
.value
- x
); /* u1+v = r+x */
144 s
= 1.0 + u
.value
* u1
.value
;
145 return u
.value
+ z
* (s
+ u
.value
* v
);