Leaked source code of windows server 2003
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.

62 lines
1.5 KiB

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