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.

64 lines
1.6 KiB

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