Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

  1. /* _Exp function */
  2. #include "xmath.h"
  3. _STD_BEGIN
  4. /* coefficients */
  5. static const double p[] = { /* courtesy Dr. Tim Prince */
  6. 1.0,
  7. 420.30235984910635,
  8. 15132.70094680474802};
  9. static const double q[] = { /* courtesy Dr. Tim Prince */
  10. 30.01511290683317,
  11. 3362.72154416553028,
  12. 30265.40189360949691};
  13. static const double c1 = 22713.0 / 32768.0;
  14. static const double c2 = 1.4286068203094172321214581765680755e-6;
  15. static const double hugexp = HUGE_EXP;
  16. static const double invln2 = 1.4426950408889634073599246810018921;
  17. _CRTIMP2 short __cdecl _Exp(double *px, double y, short eoff)
  18. { /* compute y*e^(*px), (*px) finite, |y| not huge */
  19. if (*px < -hugexp || y == 0.0)
  20. { /* certain underflow */
  21. *px = 0.0;
  22. return (0);
  23. }
  24. else if (hugexp < *px)
  25. { /* certain overflow */
  26. *px = _Inf._Double;
  27. return (_INFCODE);
  28. }
  29. else
  30. { /* xexp won't overflow */
  31. double g = *px * invln2;
  32. short xexp = (short)(g + (g < 0.0 ? - 0.5 : + 0.5));
  33. g = xexp;
  34. g = (*px - g * c1) - g * c2;
  35. if (-_Eps._Double < g && g < _Eps._Double)
  36. *px = y;
  37. else
  38. { /* g*g worth computing */
  39. const double z = g * g;
  40. const double w = (q[0] * z + q[1]) * z + q[2];
  41. g *= (z + p[1]) * z + p[2];
  42. *px = (w + g) / (w - g) * 2.0 * y;
  43. --xexp;
  44. }
  45. return (_Dscale(px, (long)xexp + eoff));
  46. }
  47. }
  48. _STD_END
  49. /*
  50. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  51. * Consult your license regarding permissions and restrictions.
  52. V3.10:0009 */