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