124 static partial class fdlibm
126 internal static double expm1(
double x)
132 o_threshold = 7.09782712893383973096e+02,
133 ln2_hi = 6.93147180369123816490e-01,
134 ln2_lo = 1.90821492927058770002e-10,
135 invln2 = 1.44269504088896338700e+00,
137 Q1 = -3.33333333333331316428e-02,
138 Q2 = 1.58730158725481460165e-03,
139 Q3 = -7.93650757867487942473e-05,
140 Q4 = 4.00821782732936239552e-06,
141 Q5 = -2.01099218183624371326e-07;
143 double y, hi, lo, c = 0, t, e, hxs, hfx, r1;
148 xsb = (int)(hx & 0x80000000);
149 if (xsb == 0) y = x;
else y = -x;
153 if (hx >= 0x4043687A)
155 if (hx >= 0x40862E42)
157 if (hx >= 0x7ff00000)
159 if (((
int)(hx & 0xfffff) | __LO(x)) != 0)
161 else return (xsb == 0) ? x : -1.0;
163 if (x > o_threshold)
return huge * huge;
178 { hi = x - ln2_hi; lo = ln2_lo; k = 1; }
180 { hi = x + ln2_hi; lo = -ln2_lo; k = -1; }
184 k = (int)(invln2 * x + ((xsb == 0) ? 0.5 : -0.5));
192 else if (hx < 0x3c900000)
195 return x - (t - (huge + x));
202 r1 = one + hxs * (Q1 + hxs * (Q2 + hxs * (Q3 + hxs * (Q4 + hxs * Q5))));
204 e = hxs * ((r1 - t) / (6.0 - x * t));
205 if (k == 0)
return x - (x * e - hxs);
208 e = (x * (e - c) - c);
210 if (k == -1)
return 0.5 * (x - e) - 0.5;
213 if (x < -0.25)
return -2.0 * (e - (x + 0.5));
214 else return one + 2.0 * (x - e);
216 if (k <= -2 || k > 56)
219 y = __HI(y, __HI(y) + (k << 20));
225 t = __HI(t, 0x3ff00000 - (0x200000 >> k));
227 y = __HI(y, __HI(y) + (k << 20));
231 t = __HI(t, ((0x3ff - k) << 20));
234 y = __HI(y, __HI(y) + (k << 20));