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