// This file contains copies of the fdlibm routines used by // StrictMath. It turns out that it is almost always required to use // these runtime routines; the Intel CPU doesn't meet the Java // specification for sin/cos outside a certain limited argument range, // and the SPARC CPU doesn't appear to have sin/cos instructions. It // also turns out that avoiding the indirect call through function // pointer out to libjava.so in SharedRuntime speeds these routines up // by roughly 15% on both Win32/x86 and Solaris/SPARC.
// Enabling optimizations in this file causes incorrect code to be // generated; can not figure out how to turn down optimization for one // file in the IDE on Windows #ifdef WIN32 # pragma warning( disable: 4748 ) // /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function # pragma optimize ( "", off ) #endif
staticdouble __ieee754_log10(double x) { double y,z; int i,k,hx; unsigned lx;
hx = high(x); /* high word of x */
lx = low(x); /* low word of x */
k=0; if (hx < 0x00100000) { /* x < 2**-1022 */ if (((hx&0x7fffffff)|lx)==0) return -two54/zero; /* log(+-0)=-inf */ if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
k -= 54; x *= two54; /* subnormal number, scale up x */
hx = high(x); /* high word of x */
} if (hx >= 0x7ff00000) return x+x;
k += (hx>>20)-1023;
i = ((unsigned)k&0x80000000)>>31;
hx = (hx&0x000fffff)|((0x3ff-i)<<20);
y = (double)(k+i);
set_high(&x, hx);
z = y*log10_2lo + ivln10*__ieee754_log(x); return z+y*log10_2hi;
}
/* argument reduction */ if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
} else {
k = (int)(invln2*x+halF[xsb]);
t = k;
hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */
lo = t*ln2LO[0];
}
x = hi - lo;
} elseif(hx < 0x3e300000) { /* when |x|<2**-28 */ if(hugeX+x>one) return one+x;/* trigger inexact */
} else k = 0;
/* x is now in primary range */
t = x*x;
c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); if(k==0) return one-((x*c)/(c-2.0)-x); else y = one-((lo-(x*c)/(2.0-c))-hi); if(k >= -1021) {
set_high(&y, high(y) + (k<<20)); /* add k to y's exponent */ return y;
} else {
set_high(&y, high(y) + ((k+1000)<<20)); /* add k to y's exponent */ return y*twom1000;
}
}
/* determine if y is an odd int when x < 0 *yisint=0...yisnotaninteger *yisint=1...yisanoddint *yisint=2...yisanevenint
*/
yisint = 0; if(hx<0) { if(iy>=0x43400000) yisint = 2; /* even integer y */ elseif(iy>=0x3ff00000) {
k = (iy>>20)-0x3ff; /* exponent */ if(k>20) {
j = ly>>(52-k); if((unsigned)(j<<(52-k))==ly) yisint = 2-(j&1);
} elseif(ly==0) {
j = iy>>(20-k); if((j<<(20-k))==iy) yisint = 2-(j&1);
}
}
}
/* special value of y */ if(ly==0) { if (iy==0x7ff00000) { /* y is +-inf */ if(((ix-0x3ff00000)|lx)==0) return y - y; /* inf**+-1 is NaN */ elseif (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */ return (hy>=0)? y: zeroX; else/* (|x|<1)**-,+inf = inf,0 */ return (hy<0)?-y: zeroX;
} if(iy==0x3ff00000) { /* y is +-1 */ if(hy<0) return one/x; elsereturn x;
} if(hy==0x40000000) return x*x; /* y is 2 */ if(hy==0x3fe00000) { /* y is 0.5 */ if(hx>=0) /* x >= +0 */ return sqrt(x);
}
}
ax = fabsd(x); /* special value of x */ if(lx==0) { if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
z = ax; /*x is +-0,+-inf,+-1*/ if(hy<0) z = one/z; /* z = (1/|x|) */ if(hx<0) { if(((ix-0x3ff00000)|yisint)==0) { #ifdef CAN_USE_NAN_DEFINE
z = NAN; #else
z = (z-z)/(z-z); /* (-1)**non-int is NaN */ #endif
} elseif(yisint==1)
z = -1.0*z; /* (x<0)**odd = -(|x|**odd) */
} return z;
}
}
n = (hx>>31)+1;
/* (x<0)**(non-int) is NaN */ if((n|yisint)==0) #ifdef CAN_USE_NAN_DEFINE return NAN; #else return (x-x)/(x-x); #endif
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ if((n|(yisint-1))==0) s = -one;/* (-ve)**(odd int) */
/* |y| is huge */ if(iy>0x41e00000) { /* if |y| > 2**31 */ if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */ if(ix<=0x3fefffff) return (hy<0)? hugeX*hugeX:tiny*tiny; if(ix>=0x3ff00000) return (hy>0)? hugeX*hugeX:tiny*tiny;
} /* over/underflow if x is not close to one */ if(ix<0x3fefffff) return (hy<0)? s*hugeX*hugeX:s*tiny*tiny; if(ix>0x3ff00000) return (hy>0)? s*hugeX*hugeX:s*tiny*tiny; /* now |1-x| is tiny <= 2**-20, suffice to compute
log(x) by x-x^2/2+x^3/3-x^4/4 */
t = ax-one; /* t has 20 trailing zeros */
w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
v = t*ivln2_l-w*ivln2;
t1 = u+v;
set_low(&t1, 0);
t2 = v-(t1-u);
} else { double ss,s2,s_h,s_l,t_h,t_l;
n = 0; /* take care subnormal number */ if(ix<0x00100000)
{ax *= two53; n -= 53; ix = high(ax); }
n += ((ix)>>20)-0x3ff;
j = ix&0x000fffff; /* determine interval */
ix = j|0x3ff00000; /* normalize ix */ if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */ elseif(j<0xBB67A) k=1; /* |x|<sqrt(3) */ else {k=0;n+=1;ix -= 0x00100000;}
set_high(&ax, ix);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.