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.

59 lines
1.3 KiB

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