Commit 9adcb02d authored by Raymond Toy's avatar Raymond Toy
Browse files

Use unions to access the high and low parts of a double.

parent 359d84fb
......@@ -66,10 +66,13 @@ qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
{
double z,p,q,r,w,s,c,df;
int hx,ix;
hx = __HI(x);
union { int i[2]; double d; } ux;
ux.d = x;
hx = ux.i[HIWORD];
ix = hx&0x7fffffff;
if(ix>=0x3ff00000) { /* |x| >= 1 */
if(((ix-0x3ff00000)|__LO(x))==0) { /* |x|==1 */
if(((ix-0x3ff00000)|ux.i[LOWORD])==0) { /* |x|==1 */
if(hx>0) return 0.0; /* acos(1) = 0 */
else return pi+2.0*pio2_lo; /* acos(-1)= pi */
}
......@@ -94,7 +97,9 @@ qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
z = (one-x)*0.5;
s = sqrt(z);
df = s;
__LO(df) = 0;
ux.d = df;
ux.i[LOWORD] = 0;
df = ux.d;
c = (z-df*df)/(s+df);
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
......
......@@ -75,10 +75,13 @@ qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
{
double t,w,p,q,c,r,s;
int hx,ix;
hx = __HI(x);
union { int i[2]; double d; } ux;
ux.d = x;
hx = ux.i[HIWORD];
ix = hx&0x7fffffff;
if(ix>= 0x3ff00000) { /* |x|>= 1 */
if(((ix-0x3ff00000)|__LO(x))==0)
if(((ix-0x3ff00000)|ux.i[LOWORD])==0)
/* asin(1)=+-pi/2 with inexact */
return x*pio2_hi+x*pio2_lo;
return (x-x)/(x-x); /* asin(|x|>1) is NaN */
......@@ -103,7 +106,9 @@ qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
} else {
w = s;
__LO(w) = 0;
ux.d = w;
ux.i[LOWORD] = 0;
w = ux.d;
c = (t-w*w)/(s+w);
r = p/q;
p = 2.0*s*r-(pio2_lo-2.0*c);
......
......@@ -83,20 +83,22 @@ one = 1.0,
huge = 1.0e300;
#ifdef __STDC__
double atan(double x)
double fdlibm_atan(double x)
#else
double atan(x)
double fdlibm_atan(x)
double x;
#endif
{
double w,s1,s2,z;
int ix,hx,id;
union { int i[2]; double d; } ux;
hx = __HI(x);
ux.d = x;
hx = ux.i[HIWORD];
ix = hx&0x7fffffff;
if(ix>=0x44100000) { /* if |x| >= 2^66 */
if(ix>0x7ff00000||
(ix==0x7ff00000&&(__LO(x)!=0)))
(ix==0x7ff00000&&(ux.i[LOWORD]!=0)))
return x+x; /* NaN */
if(hx>0) return atanhi[3]+atanlo[3];
else return -atanhi[3]-atanlo[3];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment