Print this page
5261 libm should stop using synonyms.h
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/Q/atanl.c
+++ new/usr/src/lib/libm/common/Q/atanl.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 */
21 21
22 22 /*
23 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25 /*
26 26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 27 * Use is subject to license terms.
28 28 */
29 29
30 -#pragma weak atanl = __atanl
30 +#pragma weak __atanl = atanl
31 31
32 32 /*
33 33 * atanl(x)
34 34 * Table look-up algorithm
35 35 * By K.C. Ng, March 9, 1989
36 36 *
37 37 * Algorithm.
38 38 *
39 39 * The algorithm is based on atan(x)=atan(y)+atan((x-y)/(1+x*y)).
40 40 * We use poly1(x) to approximate atan(x) for x in [0,1/8] with
41 41 * error (relative)
42 42 * |(atan(x)-poly1(x))/x|<= 2^-115.94 long double
43 43 * |(atan(x)-poly1(x))/x|<= 2^-58.85 double
44 44 * |(atan(x)-poly1(x))/x|<= 2^-25.53 float
45 45 * and use poly2(x) to approximate atan(x) for x in [0,1/65] with
46 46 * error (absolute)
47 47 * |atan(x)-poly2(x)|<= 2^-122.15 long double
48 48 * |atan(x)-poly2(x)|<= 2^-64.79 double
49 49 * |atan(x)-poly2(x)|<= 2^-35.36 float
50 50 * Here poly1 and poly2 are odd polynomial with the following form:
51 51 * x + x^3*(a1+x^2*(a2+...))
52 52 *
53 53 * (0). Purge off Inf and NaN and 0
54 54 * (1). Reduce x to positive by atan(x) = -atan(-x).
55 55 * (2). For x <= 1/8, use
56 56 * (2.1) if x < 2^(-prec/2-2), atan(x) = x with inexact
57 57 * (2.2) Otherwise
58 58 * atan(x) = poly1(x)
59 59 * (3). For x >= 8 then
60 60 * (3.1) if x >= 2^(prec+2), atan(x) = atan(inf) - pio2lo
61 61 * (3.2) if x >= 2^(prec/3+2), atan(x) = atan(inf) - 1/x
62 62 * (3.3) if x > 65, atan(x) = atan(inf) - poly2(1/x)
63 63 * (3.4) Otherwise, atan(x) = atan(inf) - poly1(1/x)
64 64 *
65 65 * (4). Now x is in (0.125, 8)
66 66 * Find y that match x to 4.5 bit after binary (easy).
67 67 * If iy is the high word of y, then
68 68 * single : j = (iy - 0x3e000000) >> 19
69 69 * double : j = (iy - 0x3fc00000) >> 16
70 70 * quad : j = (iy - 0x3ffc0000) >> 12
71 71 *
72 72 * Let s = (x-y)/(1+x*y). Then
73 73 * atan(x) = atan(y) + poly1(s)
74 74 * = _TBL_atanl_hi[j] + (_TBL_atanl_lo[j] + poly2(s) )
75 75 *
76 76 * Note. |s| <= 1.5384615385e-02 = 1/65. Maxium occurs at x = 1.03125
77 77 *
78 78 */
79 79
80 80 #include "libm.h"
81 81
82 82 extern const long double _TBL_atanl_hi[], _TBL_atanl_lo[];
83 83 static const long double
84 84 one = 1.0L,
85 85 p1 = -3.333333333333333333333333333331344526118e-0001L,
86 86 p2 = 1.999999999999999999999999989931277668570e-0001L,
87 87 p3 = -1.428571428571428571428553606221309530901e-0001L,
88 88 p4 = 1.111111111111111111095219842737139747418e-0001L,
89 89 p5 = -9.090909090909090825503603835248061123323e-0002L,
90 90 p6 = 7.692307692307664052130743214708925258904e-0002L,
91 91 p7 = -6.666666666660213835187713228363717388266e-0002L,
92 92 p8 = 5.882352940152439399097283359608661949504e-0002L,
93 93 p9 = -5.263157780447533993046614040509529668487e-0002L,
94 94 p10 = 4.761895816878184933175855990886788439447e-0002L,
95 95 p11 = -4.347345005832274022681019724553538135922e-0002L,
96 96 p12 = 3.983031914579635037502589204647752042736e-0002L,
97 97 p13 = -3.348206704469830575196657749413894897554e-0002L,
98 98 q1 = -3.333333333333333333333333333195273650186e-0001L,
99 99 q2 = 1.999999999999999999999988146114392615808e-0001L,
100 100 q3 = -1.428571428571428571057630319435467111253e-0001L,
101 101 q4 = 1.111111111111105373263048208994541544098e-0001L,
102 102 q5 = -9.090909090421834209167373258681021816441e-0002L,
103 103 q6 = 7.692305377813692706850171767150701644539e-0002L,
104 104 q7 = -6.660896644393861499914731734305717901330e-0002L,
105 105 pio2hi = 1.570796326794896619231321691639751398740e+0000L,
106 106 pio2lo = 4.335905065061890512398522013021675984381e-0035L;
107 107
108 108 #define i0 0
109 109 #define i1 3
110 110
111 111 long double
112 112 atanl(long double x) {
113 113 long double y, z, r, p, s;
114 114 int *px = (int *) &x, *py = (int *) &y;
115 115 int ix, iy, sign, j;
116 116
117 117 ix = px[i0];
118 118 sign = ix & 0x80000000;
119 119 ix ^= sign;
120 120
121 121 /* for |x| < 1/8 */
122 122 if (ix < 0x3ffc0000) {
123 123 if (ix < 0x3feb0000) { /* when |x| < 2**(-prec/6-2) */
124 124 if (ix < 0x3fc50000) { /* if |x| < 2**(-prec/2-2) */
125 125 s = one;
126 126 *(3 - i0 + (int *) &s) = -1; /* s = 1-ulp */
127 127 *(1 + (int *) &s) = -1;
128 128 *(2 + (int *) &s) = -1;
129 129 *(i0 + (int *) &s) -= 1;
130 130 if ((int) (s * x) < 1)
131 131 return (x); /* raise inexact */
132 132 }
133 133 z = x * x;
134 134 if (ix < 0x3fe20000) { /* if |x| < 2**(-prec/4-1) */
135 135 return (x + (x * z) * p1);
136 136 } else { /* if |x| < 2**(-prec/6-2) */
137 137 return (x + (x * z) * (p1 + z * p2));
138 138 }
139 139 }
140 140 z = x * x;
141 141 return (x + (x * z) * (p1 + z * (p2 + z * (p3 + z * (p4 +
142 142 z * (p5 + z * (p6 + z * (p7 + z * (p8 + z * (p9 +
143 143 z * (p10 + z * (p11 + z * (p12 + z * p13)))))))))))));
144 144 }
145 145
146 146 /* for |x| >= 8.0 */
147 147 if (ix >= 0x40020000) {
148 148 px[i0] = ix;
149 149 if (ix < 0x40050400) { /* x < 65 */
150 150 r = one / x;
151 151 z = r * r;
152 152 /*
153 153 * poly1
154 154 */
155 155 y = r * (one + z * (p1 + z * (p2 + z * (p3 +
156 156 z * (p4 + z * (p5 + z * (p6 + z * (p7 +
157 157 z * (p8 + z * (p9 + z * (p10 + z * (p11 +
158 158 z * (p12 + z * p13)))))))))))));
159 159 y -= pio2lo;
160 160 } else if (ix < 0x40260000) { /* x < 2**(prec/3+2) */
161 161 r = one / x;
162 162 z = r * r;
163 163 /*
164 164 * poly2
165 165 */
166 166 y = r * (one + z * (q1 + z * (q2 + z * (q3 + z * (q4 +
167 167 z * (q5 + z * (q6 + z * q7)))))));
168 168 y -= pio2lo;
169 169 } else if (ix < 0x40720000) { /* x < 2**(prec+2) */
170 170 y = one / x - pio2lo;
171 171 } else if (ix < 0x7fff0000) { /* x < inf */
172 172 y = -pio2lo;
173 173 } else { /* x is inf or NaN */
174 174 if (((ix - 0x7fff0000) | px[1] | px[2] | px[i1]) != 0)
175 175 return (x - x);
176 176 y = -pio2lo;
177 177 }
178 178
179 179 if (sign == 0)
180 180 return (pio2hi - y);
181 181 else
182 182 return (y - pio2hi);
183 183 }
184 184
185 185 /* now x is between 1/8 and 8 */
186 186 px[i0] = ix;
187 187 iy = (ix + 0x00000800) & 0x7ffff000;
188 188 py[i0] = iy;
189 189 py[1] = py[2] = py[i1] = 0;
190 190 j = (iy - 0x3ffc0000) >> 12;
191 191
192 192 if (sign == 0)
193 193 s = (x - y) / (one + x * y);
194 194 else
195 195 s = (y - x) / (one + x * y);
196 196 z = s * s;
197 197 if (ix == iy)
198 198 p = s * (one + z * (q1 + z * (q2 + z * (q3 + z * q4))));
199 199 else
200 200 p = s * (one + z * (q1 + z * (q2 + z * (q3 + z * (q4 +
201 201 z * (q5 + z * (q6 + z * q7)))))));
202 202 if (sign == 0) {
203 203 r = p + _TBL_atanl_lo[j];
204 204 return (r + _TBL_atanl_hi[j]);
205 205 } else {
206 206 r = p - _TBL_atanl_lo[j];
207 207 return (r - _TBL_atanl_hi[j]);
208 208 }
209 209 }
↓ open down ↓ |
169 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX