dlngam.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* dlngam.f -- translated by f2c (version 20100827).
  2. This file no longer depends on f2c.
  3. */
  4. #include "slatec-internal.hpp"
  5. /* Table of constant values */
  6. static integer const c__2 = 2;
  7. static integer const c__4 = 4;
  8. static integer const c__3 = 3;
  9. static integer const c__1 = 1;
  10. static double const sq2pil = .91893853320467274178032973640562;
  11. static double const sqpi2l = .225791352644727432363097614947441;
  12. static double const pi = 3.1415926535897932384626433832795;
  13. static double const temp = 1. / log(d1mach_(2));
  14. static double const xmax = temp * d1mach_(2);
  15. static double const dxrel = sqrt(d1mach_(4));
  16. double dlngam_(double const *x)
  17. {
  18. /* Initialized data */
  19. /* System generated locals */
  20. double d__1, d__2;
  21. /* Local variables */
  22. double y;
  23. double sinpiy;
  24. /* ***BEGIN PROLOGUE DLNGAM */
  25. /* ***PURPOSE Compute the logarithm of the absolute value of the Gamma */
  26. /* function. */
  27. /* ***LIBRARY SLATEC (FNLIB) */
  28. /* ***CATEGORY C7A */
  29. /* ***TYPE DOUBLE PRECISION (ALNGAM-S, DLNGAM-D, CLNGAM-C) */
  30. /* ***KEYWORDS ABSOLUTE VALUE, COMPLETE GAMMA FUNCTION, FNLIB, LOGARITHM, */
  31. /* SPECIAL FUNCTIONS */
  32. /* ***AUTHOR Fullerton, W., (LANL) */
  33. /* ***DESCRIPTION */
  34. /* DLNGAM(X) calculates the double precision logarithm of the */
  35. /* absolute value of the Gamma function for double precision */
  36. /* argument X. */
  37. /* ***REFERENCES (NONE) */
  38. /* ***ROUTINES CALLED D1MACH, D9LGMC, DGAMMA, XERMSG */
  39. /* ***REVISION HISTORY (YYMMDD) */
  40. /* 770601 DATE WRITTEN */
  41. /* 890531 Changed all specific intrinsics to generic. (WRB) */
  42. /* 890531 REVISION DATE from Version 3.2 */
  43. /* 891214 Prologue converted to Version 4.0 format. (BAB) */
  44. /* 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) */
  45. /* 900727 Added EXTERNAL statement. (WRB) */
  46. /* ***END PROLOGUE DLNGAM */
  47. /* ***FIRST EXECUTABLE STATEMENT DLNGAM */
  48. y = abs(*x);
  49. if (y > 10.) {
  50. goto L20;
  51. }
  52. /* LOG (ABS (DGAMMA(X)) ) FOR ABS(X) .LE. 10.0 */
  53. return log(abs(dgamma_(x)));
  54. /* LOG ( ABS (DGAMMA(X)) ) FOR ABS(X) .GT. 10.0 */
  55. L20:
  56. if (y > xmax) {
  57. xermsg_("SLATEC", "DLNGAM", "ABS(X) SO BIG DLNGAM OVERFLOWS", &c__2, &
  58. c__2, (ftnlen)6, (ftnlen)6, (ftnlen)30);
  59. }
  60. if (*x > 0.) {
  61. return sq2pil + (*x - .5) * log(*x) - *x + d9lgmc_(&y);
  62. }
  63. sinpiy = (d__1 = sin(pi * y), abs(d__1));
  64. if (sinpiy == 0.) {
  65. xermsg_("SLATEC", "DLNGAM", "X IS A NEGATIVE INTEGER", &c__3, &c__2, (
  66. ftnlen)6, (ftnlen)6, (ftnlen)23);
  67. }
  68. d__2 = *x - .5;
  69. if ((d__1 = (*x - f2c::d_int(&d__2)) / *x, abs(d__1)) < dxrel) {
  70. xermsg_("SLATEC", "DLNGAM", "ANSWER LT HALF PRECISION BECAUSE X TOO \
  71. NEAR NEGATIVE INTEGER", &c__1, &c__1, (ftnlen)6, (ftnlen)6, (ftnlen)60);
  72. }
  73. return sqpi2l + (*x - .5) * log(y) - *x - log(sinpiy) - d9lgmc_(&y);
  74. } /* dlngam_ */