enormp.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <math.h>
  2. double Cdhc_enormp(double x)
  3. {
  4. double x1, x2, x3, x4, ret_val;
  5. static double xp[5] = { 7.7105849500132e-5, -0.00133733772997339,
  6. 0.0323076579225834, 0.0479137145607681, 0.128379167095513
  7. };
  8. static double xq[3] = { 0.00301048631703895, 0.0538971687740286,
  9. 0.375795757275549
  10. };
  11. static double xr[8] = { -1.36864857382717e-7, 0.564195517478974,
  12. 7.21175825088309, 43.1622272220567, 152.98928504694,
  13. 339.320816734344, 451.918953711873, 300.459261020162
  14. };
  15. static double xs[8] = { 1.0, 12.7827273196294, 77.0001529352295,
  16. 277.585444743988, 638.980264465631, 931.35409485061,
  17. 790.950925327898, 300.459260956983
  18. };
  19. static double xt[5] = { 2.10144126479064, 26.2370141675169,
  20. 21.3688200555087, 4.6580782871847, 0.282094791773523
  21. };
  22. static double xu[4] = { 94.153775055546, 187.11481179959,
  23. 99.0191814623914, 18.0124575948747
  24. };
  25. double yy1, yy2;
  26. x3 = (double)0.564189583547756;
  27. x1 = fabs(x);
  28. if (x1 <= .5) {
  29. x4 = x * x;
  30. yy1 =
  31. (((xp[0] * x4 + xp[1]) * x4 + xp[2]) * x4 + xp[3]) * x4 + xp[4] +
  32. 1.;
  33. yy2 = ((xq[0] * x4 + xq[1]) * x4 + xq[2]) * x4 + 1.;
  34. ret_val = x * (yy1 / yy2);
  35. }
  36. else if (x1 <= 4.) {
  37. yy1 = ((((((xr[0] * x1 + xr[1]) * x1 + xr[2]) * x1 + xr[3])
  38. * x1 + xr[4]) * x1 + xr[5]) * x1 + xr[6]) * x1 + xr[7];
  39. yy2 = ((((((xs[0] * x1 + xs[1]) * x1 + xs[2]) * x1 + xs[3])
  40. * x1 + xs[4]) * x1 + xs[5]) * x1 + xs[6]) * x1 + xs[7];
  41. ret_val = 1. - exp(-x * x) * yy1 / yy2;
  42. if (x < 0.)
  43. ret_val *= -1.0;
  44. }
  45. else {
  46. x2 = x * x;
  47. x4 *= 1.; /* huh, what? See original FORTRAN */
  48. x4 = 0.5;
  49. yy1 = (((xt[0] * x4 + xt[1]) * x4 + xt[2]) * x4 + xt[3]) * x4 + xt[4];
  50. yy2 = (((xu[0] * x4 + xu[1]) * x4 + xu[2]) * x4 + xu[3]) * x4 + 1.;
  51. ret_val = x3 / x1 - yy1 * x1 / (x2 * yy2);
  52. ret_val = 1. - exp(-x2) * ret_val;
  53. if (x < 0.)
  54. ret_val = -ret_val;
  55. }
  56. return ret_val;
  57. }