71#pragma warning disable 168
75 static partial class fdlibm
77 static readonly
double[] bp = { 1.0, 1.5, };
78 static readonly
double[] dp_h = { 0.0, 5.84962487220764160156e-01, };
79 static readonly
double[] dp_l = { 0.0, 1.35003920212974897128e-08, };
81 internal static double __ieee754_pow(
double x,
double y)
83 const double zero = 0.0,
86 two53 = 9007199254740992.0,
90 L1 = 5.99999999999994648725e-01,
91 L2 = 4.28571428578550184252e-01,
92 L3 = 3.33333329818377432918e-01,
93 L4 = 2.72728123808534006489e-01,
94 L5 = 2.30660745775561754067e-01,
95 L6 = 2.06975017800338417784e-01,
96 P1 = 1.66666666666666019037e-01,
97 P2 = -2.77777777770155933842e-03,
98 P3 = 6.61375632143793436117e-05,
99 P4 = -1.65339022054652515390e-06,
100 P5 = 4.13813679705723846039e-08,
101 lg2 = 6.93147180559945286227e-01,
102 lg2_h = 6.93147182464599609375e-01,
103 lg2_l = -1.90465429995776804525e-09,
104 ovt = 8.0085662595372944372e-0017,
105 cp = 9.61796693925975554329e-01,
106 cp_h = 9.61796700954437255859e-01,
107 cp_l = -7.02846165095275826516e-09,
108 ivln2 = 1.44269504088896338700e+00,
109 ivln2_h = 1.44269502162933349609e+00,
110 ivln2_l = 1.92596299112661746887e-08;
112 double z, ax, z_h, z_l, p_h, p_l;
113 double y1, t1, t2, r, s, t, u, v, w;
114 int i0, i1, i, j, k, yisint, n;
118 hx = __HI(x); lx = (uint)__LO(x);
119 hy = __HI(y); ly = (uint)__LO(y);
120 ix = hx & 0x7fffffff; iy = hy & 0x7fffffff;
123 if ((iy | (
int)ly) == 0)
return one;
126 if (ix > 0x7ff00000 || ((ix == 0x7ff00000) && (lx != 0)) ||
127 iy > 0x7ff00000 || ((iy == 0x7ff00000) && (ly != 0)))
138 if (iy >= 0x43400000) yisint = 2;
139 else if (iy >= 0x3ff00000)
141 k = (iy >> 20) - 0x3ff;
144 j = (int)(ly >> (52 - k));
145 if ((j << (52 - k)) == (
int)ly) yisint = 2 - (j & 1);
150 if ((j << (20 - k)) == iy) yisint = 2 - (j & 1);
158 if (iy == 0x7ff00000)
160 if (((ix - 0x3ff00000) | (
int)lx) == 0)
162 else if (ix >= 0x3ff00000)
163 return (hy >= 0) ? y : zero;
165 return (hy < 0) ? -y : zero;
167 if (iy == 0x3ff00000)
169 if (hy < 0)
return one / x;
else return x;
171 if (hy == 0x40000000)
return x * x;
172 if (hy == 0x3fe00000)
183 if (ix == 0x7ff00000 || ix == 0 || ix == 0x3ff00000)
186 if (hy < 0) z = one / z;
189 if (((ix - 0x3ff00000) | yisint) == 0)
191 z = (z - z) / (z - z);
193 else if (yisint == 1)
203 if ((n | yisint) == 0)
return (x - x) / (x - x);
206 if ((n | (yisint - 1)) == 0) s = -one;
213 if (ix <= 0x3fefffff)
return (hy < 0) ? huge * huge : tiny * tiny;
214 if (ix >= 0x3ff00000)
return (hy > 0) ? huge * huge : tiny * tiny;
217 if (ix < 0x3fefffff)
return (hy < 0) ? s * huge * huge : s * tiny * tiny;
218 if (ix > 0x3ff00000)
return (hy > 0) ? s * huge * huge : s * tiny * tiny;
222 w = (t * t) * (0.5 - t * (0.3333333333333333333333 - t * 0.25));
224 v = t * ivln2_l - w * ivln2;
231 double ss, s2, s_h, s_l, t_h, t_l;
235 { ax *= two53; n -= 53; ix = __HI(ax); }
236 n += ((ix) >> 20) - 0x3ff;
240 if (j <= 0x3988E) k = 0;
241 else if (j < 0xBB67A) k = 1;
242 else { k = 0; n += 1; ix -= 0x00100000; }
247 v = one / (ax + bp[k]);
253 t_h = __HI(t_h, ((ix >> 1) | 0x20000000) + 0x00080000 + (k << 18));
254 t_l = ax - (t_h - bp[k]);
255 s_l = v * ((u - s_h * t_h) - s_h * t_l);
258 r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6)))));
259 r += s_l * (s_h + ss);
263 t_l = r - ((t_h - 3.0) - s2);
266 v = s_l * t_h + t_l * ss;
272 z_l = cp_l * p_h + p_l * cp + dp_l[k];
275 t1 = (((z_h + z_l) + dp_h[k]) + t);
277 t2 = z_l - (((t1 - t) - dp_h[k]) - z_h);
283 p_l = (y - y1) * t1 + y * t2;
290 if (((j - 0x40900000) | i) != 0)
291 return s * huge * huge;
294 if (p_l + ovt > z - p_h)
return s * huge * huge;
297 else if ((j & 0x7fffffff) >= 0x4090cc00)
299 if (((
int)(j - 0xc090cc00) | i) != 0)
300 return s * tiny * tiny;
303 if (p_l <= z - p_h)
return s * tiny * tiny;
310 k = (i >> 20) - 0x3ff;
314 n = j + (0x00100000 >> (k + 1));
315 k = ((n & 0x7fffffff) >> 20) - 0x3ff;
317 t = __HI(t, (n & ~(0x000fffff >> k)));
318 n = ((n & 0x000fffff) | 0x00100000) >> (20 - k);
325 v = (p_l - (t - p_h)) * lg2 + t * lg2_l;
329 t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));
330 r = (z * t1) / (t1 - two) - (w + z * w);
334 if ((j >> 20) <= 0) z = scalbn(z, n);
335 else z = __HI(z, __HI(z) + (n << 20));