Print this page
11210 libm should be cstyle(1ONBLD) clean
@@ -16,13 +16,15 @@
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
+
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/
+
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -241,53 +243,58 @@
pio2 = 1.5707963267948965580e+00,
negpi = -3.1415926535897931160e+00,
q1 = -3.3333333333296428046e-01,
q2 = 1.9999999186853752618e-01,
zero = 0.0;
-
static const float two24 = 16777216.0;
float
atan2f(float fy, float fx)
{
double a, t, s, dbase;
float x, y, base;
int i, k, hx, hy, ix, iy, sign;
+
#if defined(__i386) && !defined(__amd64)
int rp;
#endif
iy = *(int *)&fy;
ix = *(int *)&fx;
hy = iy & ~0x80000000;
hx = ix & ~0x80000000;
sign = 0;
+
if (hy > hx) {
x = fy;
y = fx;
i = hx;
hx = hy;
hy = i;
+
if (iy < 0) {
x = -x;
sign = 1;
}
+
if (ix < 0) {
y = -y;
a = pio2;
} else {
a = -pio2;
sign = 1 - sign;
}
} else {
y = fy;
x = fx;
+
if (iy < 0) {
y = -y;
sign = 1;
}
+
if (ix < 0) {
x = -x;
a = negpi;
sign = 1 - sign;
} else {
@@ -302,16 +309,18 @@
else if (hy >= 0x7f800000)
a += pio4;
} else if ((int)a == 0) {
a = (double)y / x;
}
- return ((float)((sign)? -a : a));
+
+ return ((float)((sign) ? -a : a));
}
if (hy < 0x00800000) {
if (hy == 0)
- return ((float)((sign)? -a : a));
+ return ((float)((sign) ? -a : a));
+
/* scale subnormal y */
y *= two24;
x *= two24;
hy = *(int *)&y;
hx = *(int *)&x;
@@ -319,10 +328,11 @@
#if defined(__i386) && !defined(__amd64)
rp = __swapRP(fp_extended);
#endif
k = (hy - hx + 0x3f800000) & 0xfff80000;
+
if (k >= 0x3c800000) { /* |y/x| >= 1/64 */
*(int *)&base = k;
k = (k - 0x3c800000) >> 19;
a += TBL[k];
} else {
@@ -330,15 +340,16 @@
* For some reason this is faster on USIII than just
* doing t = y/x in this case.
*/
*(int *)&base = 0;
}
+
dbase = (double)base;
t = (y - x * dbase) / (x + y * dbase);
s = t * t;
a = (a + t) + t * s * (q1 + s * q2);
#if defined(__i386) && !defined(__amd64)
if (rp != fp_extended)
(void) __swapRP(rp);
#endif
- return ((float)((sign)? -a : a));
+ return ((float)((sign) ? -a : a));
}