dlngam.f 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. *DECK DLNGAM
  2. DOUBLE PRECISION FUNCTION DLNGAM (X)
  3. C***BEGIN PROLOGUE DLNGAM
  4. C***PURPOSE Compute the logarithm of the absolute value of the Gamma
  5. C function.
  6. C***LIBRARY SLATEC (FNLIB)
  7. C***CATEGORY C7A
  8. C***TYPE DOUBLE PRECISION (ALNGAM-S, DLNGAM-D, CLNGAM-C)
  9. C***KEYWORDS ABSOLUTE VALUE, COMPLETE GAMMA FUNCTION, FNLIB, LOGARITHM,
  10. C SPECIAL FUNCTIONS
  11. C***AUTHOR Fullerton, W., (LANL)
  12. C***DESCRIPTION
  13. C
  14. C DLNGAM(X) calculates the double precision logarithm of the
  15. C absolute value of the Gamma function for double precision
  16. C argument X.
  17. C
  18. C***REFERENCES (NONE)
  19. C***ROUTINES CALLED D1MACH, D9LGMC, DGAMMA, XERMSG
  20. C***REVISION HISTORY (YYMMDD)
  21. C 770601 DATE WRITTEN
  22. C 890531 Changed all specific intrinsics to generic. (WRB)
  23. C 890531 REVISION DATE from Version 3.2
  24. C 891214 Prologue converted to Version 4.0 format. (BAB)
  25. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  26. C 900727 Added EXTERNAL statement. (WRB)
  27. C***END PROLOGUE DLNGAM
  28. DOUBLE PRECISION X, DXREL, PI, SINPIY, SQPI2L, SQ2PIL, XMAX,
  29. 1 Y, DGAMMA, D9LGMC, D1MACH, TEMP
  30. LOGICAL FIRST
  31. EXTERNAL DGAMMA
  32. SAVE SQ2PIL, SQPI2L, PI, XMAX, DXREL, FIRST
  33. DATA SQ2PIL / 0.9189385332 0467274178 0329736405 62 D0 /
  34. DATA SQPI2L / +.2257913526 4472743236 3097614947 441 D+0 /
  35. DATA PI / 3.1415926535 8979323846 2643383279 50 D0 /
  36. DATA FIRST /.TRUE./
  37. C***FIRST EXECUTABLE STATEMENT DLNGAM
  38. IF (FIRST) THEN
  39. TEMP = 1.D0/LOG(D1MACH(2))
  40. XMAX = TEMP*D1MACH(2)
  41. DXREL = SQRT(D1MACH(4))
  42. ENDIF
  43. FIRST = .FALSE.
  44. C
  45. Y = ABS (X)
  46. IF (Y.GT.10.D0) GO TO 20
  47. C
  48. C LOG (ABS (DGAMMA(X)) ) FOR ABS(X) .LE. 10.0
  49. C
  50. DLNGAM = LOG (ABS (DGAMMA(X)) )
  51. RETURN
  52. C
  53. C LOG ( ABS (DGAMMA(X)) ) FOR ABS(X) .GT. 10.0
  54. C
  55. 20 IF (Y .GT. XMAX) CALL XERMSG ('SLATEC', 'DLNGAM',
  56. + 'ABS(X) SO BIG DLNGAM OVERFLOWS', 2, 2)
  57. C
  58. IF (X.GT.0.D0) DLNGAM = SQ2PIL + (X-0.5D0)*LOG(X) - X + D9LGMC(Y)
  59. IF (X.GT.0.D0) RETURN
  60. C
  61. SINPIY = ABS (SIN(PI*Y))
  62. IF (SINPIY .EQ. 0.D0) CALL XERMSG ('SLATEC', 'DLNGAM',
  63. + 'X IS A NEGATIVE INTEGER', 3, 2)
  64. C
  65. IF (ABS((X-AINT(X-0.5D0))/X) .LT. DXREL) CALL XERMSG ('SLATEC',
  66. + 'DLNGAM',
  67. + 'ANSWER LT HALF PRECISION BECAUSE X TOO NEAR NEGATIVE INTEGER',
  68. + 1, 1)
  69. C
  70. DLNGAM = SQPI2L + (X-0.5D0)*LOG(Y) - X - LOG(SINPIY) - D9LGMC(Y)
  71. RETURN
  72. C
  73. END