_CRTIMP2 short __cdecl _Exp(double *px, double y, short eoff) { /* compute y*e^(*px), (*px) finite, |y| not huge */ if (*px < -hugexp || y == 0) { /* certain underflow */ *px = 0; return (0); } else if (hugexp < *px) { /* certain overflow */ *px = _Inf._D; return (INF); } else { /* xexp won't overflow */ double g = *px * invln2; short xexp = g + (g < 0 ? - 0.5 : + 0.5); g = xexp; g = (*px - g * c1) - g * c2; if (-_Eps._D < g && g < _Eps._D) *px = y; else { /* g*g worth computing */ const double z = g * g; const double w = (q[0] * z + q[1]) * z + q[2]; g *= (z + p[1]) * z + p[2]; *px = (w + g) / (w - g) * 2 * y; --xexp; } return (_Dscale(px, (long)xexp + eoff)); } }
_C_STD_BEGIN #if _DLONG == 0 short _LDscale(long double *px, long lexp) { /* scale *px by 2^lexp with checking -- 64-bit */ return (_Dscale((double *)px, lexp)); }
_C_STD_BEGIN #if _DLONG == 0 _MRTIMP2_NCEEPURE short __CLRCALL_PURE_OR_CDECL _LDscale(long double *px, long lexp) { /* scale *px by 2^lexp with checking -- 64-bit */ return (_Dscale((double *)px, lexp)); }
_STD_BEGIN #if !_DLONG _CRTIMP2 short _LDscale(long double *px, long lexp) { /* scale *px by 2^lexp with checking */ return (_Dscale((double *)px, lexp)); }
_MRTIMP2_NCEEPURE short __CLRCALL_PURE_OR_CDECL _Exp(double *px, double y, short eoff) { /* compute y*e^(*px), (*px) finite, |y| not huge */ if (*px < -hugexp || y == 0.0) { /* certain underflow */ *px = 0.0; return (0); } else if (hugexp < *px) { /* certain overflow */ *px = _Inf._Double; return (_INFCODE); } else { /* xexp won't overflow */ double g = *px * invln2; short xexp = (short)(g + (g < 0.0 ? - 0.5 : + 0.5)); g = xexp; g = (*px - g * c1) - g * c2; if (-_Eps._Double < g && g < _Eps._Double) *px = y; else { /* g*g worth computing */ const double z = g * g; const double w = (q[0] * z + q[1]) * z + q[2]; g *= (z + p[1]) * z + p[2]; *px = (w + g) / (w - g) * 2.0 * y; --xexp; } return (_Dscale(px, (long)xexp + eoff)); } }
double (fmod)(double x, double y) { /* compute fmod(x, y) */ const short errx = _Dtest(&x); const short erry = _Dtest(&y); if (errx == NAN || erry == NAN || errx == INF || erry == 0) { /* fmod undefined */ errno = EDOM; return (errx == NAN ? x : erry == NAN ? y : _Nan._D); } else if (errx == 0 || erry == INF) return (x); /* fmod(0,nonzero) or fmod(finite,INF) */ else { /* fmod(finite,finite) */ double t; short n, neg, ychar; if (y < 0.0) y = -y; if (x < 0.0) x = -x, neg = 1; else neg = 0; for (t = y, _Dunscale(&ychar, &t), n = 0; ; ) { /* subtract |y| until |x|<|y| */ short xchar; t = x; if (n < 0 || _Dunscale(&xchar, &t) == 0 || (n = xchar - ychar) < 0) return (neg ? -x : x); for (; 0 <= n; --n) { /* try to subtract |y|*2^n */ t = y, _Dscale(&t, n); if (t <= x) { x -= t; break; } } } } }