Print this page
5261 libm should stop using synonyms.h
5298 fabs is 0-sized, confuses dis(1) and others
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Approved by: Gordon Ross <gwr@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/R/atan2f.c
+++ new/usr/src/lib/libm/common/R/atan2f.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 *
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
23 23 */
24 24 /*
25 25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 26 * Use is subject to license terms.
27 27 */
28 28
29 -#pragma weak atan2f = __atan2f
29 +#pragma weak __atan2f = atan2f
30 30
31 31 #include "libm.h"
32 32
33 33 #if defined(__i386) && !defined(__amd64)
34 34 extern int __swapRP(int);
35 35 #endif
36 36
37 37 /*
38 38 * For i = 0, ..., 192, let x[i] be the double precision number whose
39 39 * high order 32 bits are 0x3f900000 + (i << 16) and whose low order
40 40 * 32 bits are zero. Then TBL[i] := atan(x[i]) to double precision.
41 41 */
42 42
43 43 static const double TBL[] = {
44 44 1.56237286204768313e-02,
45 45 1.66000375562312640e-02,
46 46 1.75763148444955872e-02,
47 47 1.85525586258889763e-02,
48 48 1.95287670414137082e-02,
49 49 2.05049382324763683e-02,
50 50 2.14810703409090559e-02,
51 51 2.24571615089905717e-02,
52 52 2.34332098794675855e-02,
53 53 2.44092135955758099e-02,
54 54 2.53851708010611396e-02,
55 55 2.63610796402007873e-02,
56 56 2.73369382578244127e-02,
57 57 2.83127447993351995e-02,
58 58 2.92884974107309737e-02,
59 59 3.02641942386252458e-02,
60 60 3.12398334302682774e-02,
61 61 3.31909314971115949e-02,
62 62 3.51417768027967800e-02,
63 63 3.70923545503918164e-02,
64 64 3.90426499551669928e-02,
65 65 4.09926482452637811e-02,
66 66 4.29423346623621707e-02,
67 67 4.48916944623464972e-02,
68 68 4.68407129159696539e-02,
69 69 4.87893753095156174e-02,
70 70 5.07376669454602178e-02,
71 71 5.26855731431300420e-02,
72 72 5.46330792393594777e-02,
73 73 5.65801705891457105e-02,
74 74 5.85268325663017702e-02,
75 75 6.04730505641073168e-02,
76 76 6.24188099959573500e-02,
77 77 6.63088949198234884e-02,
78 78 7.01969710718705203e-02,
79 79 7.40829225490337306e-02,
80 80 7.79666338315423008e-02,
81 81 8.18479898030765457e-02,
82 82 8.57268757707448092e-02,
83 83 8.96031774848717461e-02,
84 84 9.34767811585894698e-02,
85 85 9.73475734872236709e-02,
86 86 1.01215441667466668e-01,
87 87 1.05080273416329528e-01,
88 88 1.08941956989865793e-01,
89 89 1.12800381201659389e-01,
90 90 1.16655435441069349e-01,
91 91 1.20507009691224562e-01,
92 92 1.24354994546761438e-01,
93 93 1.32039761614638762e-01,
94 94 1.39708874289163648e-01,
95 95 1.47361481088651630e-01,
96 96 1.54996741923940973e-01,
97 97 1.62613828597948568e-01,
98 98 1.70211925285474408e-01,
99 99 1.77790228992676075e-01,
100 100 1.85347949995694761e-01,
101 101 1.92884312257974672e-01,
102 102 2.00398553825878512e-01,
103 103 2.07889927202262986e-01,
104 104 2.15357699697738048e-01,
105 105 2.22801153759394521e-01,
106 106 2.30219587276843718e-01,
107 107 2.37612313865471242e-01,
108 108 2.44978663126864143e-01,
109 109 2.59629629408257512e-01,
110 110 2.74167451119658789e-01,
111 111 2.88587361894077410e-01,
112 112 3.02884868374971417e-01,
113 113 3.17055753209147029e-01,
114 114 3.31096076704132103e-01,
115 115 3.45002177207105132e-01,
116 116 3.58770670270572245e-01,
117 117 3.72398446676754202e-01,
118 118 3.85882669398073752e-01,
119 119 3.99220769575252543e-01,
120 120 4.12410441597387323e-01,
121 121 4.25449637370042266e-01,
122 122 4.38336559857957830e-01,
123 123 4.51069655988523499e-01,
124 124 4.63647609000806094e-01,
125 125 4.88333951056405535e-01,
126 126 5.12389460310737732e-01,
127 127 5.35811237960463704e-01,
128 128 5.58599315343562441e-01,
129 129 5.80756353567670414e-01,
130 130 6.02287346134964152e-01,
131 131 6.23199329934065904e-01,
132 132 6.43501108793284371e-01,
133 133 6.63202992706093286e-01,
134 134 6.82316554874748071e-01,
135 135 7.00854407884450192e-01,
136 136 7.18829999621624527e-01,
137 137 7.36257428981428097e-01,
138 138 7.53151280962194414e-01,
139 139 7.69526480405658297e-01,
140 140 7.85398163397448279e-01,
141 141 8.15691923316223422e-01,
142 142 8.44153986113171051e-01,
143 143 8.70903457075652976e-01,
144 144 8.96055384571343927e-01,
145 145 9.19719605350416858e-01,
146 146 9.42000040379463610e-01,
147 147 9.62994330680936206e-01,
148 148 9.82793723247329054e-01,
149 149 1.00148313569423464e+00,
150 150 1.01914134426634972e+00,
151 151 1.03584125300880014e+00,
152 152 1.05165021254837376e+00,
153 153 1.06663036531574362e+00,
154 154 1.08083900054116833e+00,
155 155 1.09432890732118993e+00,
156 156 1.10714871779409041e+00,
157 157 1.13095374397916038e+00,
158 158 1.15257199721566761e+00,
159 159 1.17227388112847630e+00,
160 160 1.19028994968253166e+00,
161 161 1.20681737028525249e+00,
162 162 1.22202532321098967e+00,
163 163 1.23605948947808186e+00,
164 164 1.24904577239825443e+00,
165 165 1.26109338225244039e+00,
166 166 1.27229739520871732e+00,
167 167 1.28274087974427076e+00,
168 168 1.29249666778978534e+00,
169 169 1.30162883400919616e+00,
170 170 1.31019393504755555e+00,
171 171 1.31824205101683711e+00,
172 172 1.32581766366803255e+00,
173 173 1.33970565959899957e+00,
174 174 1.35212738092095464e+00,
175 175 1.36330010035969384e+00,
176 176 1.37340076694501589e+00,
177 177 1.38257482149012589e+00,
178 178 1.39094282700241845e+00,
179 179 1.39860551227195762e+00,
180 180 1.40564764938026987e+00,
181 181 1.41214106460849531e+00,
182 182 1.41814699839963154e+00,
183 183 1.42371797140649403e+00,
184 184 1.42889927219073276e+00,
185 185 1.43373015248470903e+00,
186 186 1.43824479449822262e+00,
187 187 1.44247309910910193e+00,
188 188 1.44644133224813509e+00,
189 189 1.45368758222803240e+00,
190 190 1.46013910562100091e+00,
191 191 1.46591938806466282e+00,
192 192 1.47112767430373470e+00,
193 193 1.47584462045214027e+00,
194 194 1.48013643959415142e+00,
195 195 1.48405798811891154e+00,
196 196 1.48765509490645531e+00,
197 197 1.49096634108265924e+00,
198 198 1.49402443552511865e+00,
199 199 1.49685728913695626e+00,
200 200 1.49948886200960629e+00,
201 201 1.50193983749385196e+00,
202 202 1.50422816301907281e+00,
203 203 1.50636948736934317e+00,
204 204 1.50837751679893928e+00,
205 205 1.51204050407917401e+00,
206 206 1.51529782154917969e+00,
207 207 1.51821326518395483e+00,
208 208 1.52083793107295384e+00,
209 209 1.52321322351791322e+00,
210 210 1.52537304737331958e+00,
211 211 1.52734543140336587e+00,
212 212 1.52915374769630819e+00,
213 213 1.53081763967160667e+00,
214 214 1.53235373677370856e+00,
215 215 1.53377621092096650e+00,
216 216 1.53509721411557254e+00,
217 217 1.53632722579538861e+00,
218 218 1.53747533091664934e+00,
219 219 1.53854944435964280e+00,
220 220 1.53955649336462841e+00,
221 221 1.54139303859089161e+00,
222 222 1.54302569020147562e+00,
223 223 1.54448660954197448e+00,
224 224 1.54580153317597646e+00,
225 225 1.54699130060982659e+00,
226 226 1.54807296595325550e+00,
227 227 1.54906061995310385e+00,
228 228 1.54996600675867957e+00,
229 229 1.55079899282174605e+00,
230 230 1.55156792769518947e+00,
231 231 1.55227992472688747e+00,
232 232 1.55294108165534417e+00,
233 233 1.55355665560036682e+00,
234 234 1.55413120308095598e+00,
235 235 1.55466869295126031e+00,
236 236 1.55517259817441977e+00,
237 237 };
238 238
239 239 static const double
240 240 pio4 = 7.8539816339744827900e-01,
241 241 pio2 = 1.5707963267948965580e+00,
242 242 negpi = -3.1415926535897931160e+00,
243 243 q1 = -3.3333333333296428046e-01,
244 244 q2 = 1.9999999186853752618e-01,
245 245 zero = 0.0;
246 246
247 247 static const float two24 = 16777216.0;
248 248
249 249 float
250 250 atan2f(float fy, float fx)
251 251 {
252 252 double a, t, s, dbase;
253 253 float x, y, base;
254 254 int i, k, hx, hy, ix, iy, sign;
255 255 #if defined(__i386) && !defined(__amd64)
256 256 int rp;
257 257 #endif
258 258
259 259 iy = *(int *)&fy;
260 260 ix = *(int *)&fx;
261 261 hy = iy & ~0x80000000;
262 262 hx = ix & ~0x80000000;
263 263
264 264 sign = 0;
265 265 if (hy > hx) {
266 266 x = fy;
267 267 y = fx;
268 268 i = hx;
269 269 hx = hy;
270 270 hy = i;
271 271 if (iy < 0) {
272 272 x = -x;
273 273 sign = 1;
274 274 }
275 275 if (ix < 0) {
276 276 y = -y;
277 277 a = pio2;
278 278 } else {
279 279 a = -pio2;
280 280 sign = 1 - sign;
281 281 }
282 282 } else {
283 283 y = fy;
284 284 x = fx;
285 285 if (iy < 0) {
286 286 y = -y;
287 287 sign = 1;
288 288 }
289 289 if (ix < 0) {
290 290 x = -x;
291 291 a = negpi;
292 292 sign = 1 - sign;
293 293 } else {
294 294 a = zero;
295 295 }
296 296 }
297 297
298 298 if (hx >= 0x7f800000 || hx - hy >= 0x0c800000) {
299 299 if (hx >= 0x7f800000) {
300 300 if (hx > 0x7f800000) /* nan */
301 301 return (x * y);
302 302 else if (hy >= 0x7f800000)
303 303 a += pio4;
304 304 } else if ((int)a == 0) {
305 305 a = (double)y / x;
306 306 }
307 307 return ((float)((sign)? -a : a));
308 308 }
309 309
310 310 if (hy < 0x00800000) {
311 311 if (hy == 0)
312 312 return ((float)((sign)? -a : a));
313 313 /* scale subnormal y */
314 314 y *= two24;
315 315 x *= two24;
316 316 hy = *(int *)&y;
317 317 hx = *(int *)&x;
318 318 }
319 319
320 320 #if defined(__i386) && !defined(__amd64)
321 321 rp = __swapRP(fp_extended);
322 322 #endif
323 323 k = (hy - hx + 0x3f800000) & 0xfff80000;
324 324 if (k >= 0x3c800000) { /* |y/x| >= 1/64 */
325 325 *(int *)&base = k;
326 326 k = (k - 0x3c800000) >> 19;
327 327 a += TBL[k];
328 328 } else {
329 329 /*
330 330 * For some reason this is faster on USIII than just
331 331 * doing t = y/x in this case.
332 332 */
333 333 *(int *)&base = 0;
334 334 }
335 335 dbase = (double)base;
336 336 t = (y - x * dbase) / (x + y * dbase);
337 337 s = t * t;
338 338 a = (a + t) + t * s * (q1 + s * q2);
339 339 #if defined(__i386) && !defined(__amd64)
340 340 if (rp != fp_extended)
341 341 (void) __swapRP(rp);
342 342 #endif
343 343 return ((float)((sign)? -a : a));
344 344 }
↓ open down ↓ |
305 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX