dgamrn.f 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. *DECK DGAMRN
  2. DOUBLE PRECISION FUNCTION DGAMRN (X)
  3. C***BEGIN PROLOGUE DGAMRN
  4. C***SUBSIDIARY
  5. C***PURPOSE Subsidiary to DBSKIN
  6. C***LIBRARY SLATEC
  7. C***TYPE DOUBLE PRECISION (GAMRN-S, DGAMRN-D)
  8. C***AUTHOR Amos, D. E., (SNLA)
  9. C***DESCRIPTION
  10. C
  11. C Abstract * A Double Precision Routine *
  12. C DGAMRN computes the GAMMA function ratio GAMMA(X)/GAMMA(X+0.5)
  13. C for real X.gt.0. If X.ge.XMIN, an asymptotic expansion is
  14. C evaluated. If X.lt.XMIN, an integer is added to X to form a
  15. C new value of X.ge.XMIN and the asymptotic expansion is eval-
  16. C uated for this new value of X. Successive application of the
  17. C recurrence relation
  18. C
  19. C W(X)=W(X+1)*(1+0.5/X)
  20. C
  21. C reduces the argument to its original value. XMIN and comp-
  22. C utational tolerances are computed as a function of the number
  23. C of digits carried in a word by calls to I1MACH and D1MACH.
  24. C However, the computational accuracy is limited to the max-
  25. C imum of unit roundoff (=D1MACH(4)) and 1.0D-18 since critical
  26. C constants are given to only 18 digits.
  27. C
  28. C Input X is Double Precision
  29. C X - Argument, X.gt.0.0D0
  30. C
  31. C Output DGAMRN is DOUBLE PRECISION
  32. C DGAMRN - Ratio GAMMA(X)/GAMMA(X+0.5)
  33. C
  34. C***SEE ALSO DBSKIN
  35. C***REFERENCES Y. L. Luke, The Special Functions and Their
  36. C Approximations, Vol. 1, Math In Sci. And
  37. C Eng. Series 53, Academic Press, New York, 1969,
  38. C pp. 34-35.
  39. C***ROUTINES CALLED D1MACH, I1MACH
  40. C***REVISION HISTORY (YYMMDD)
  41. C 820601 DATE WRITTEN
  42. C 890531 Changed all specific intrinsics to generic. (WRB)
  43. C 890911 Removed unnecessary intrinsics. (WRB)
  44. C 891214 Prologue converted to Version 4.0 format. (BAB)
  45. C 900328 Added TYPE section. (WRB)
  46. C 910722 Updated AUTHOR section. (ALS)
  47. C 920520 Added REFERENCES section. (WRB)
  48. C***END PROLOGUE DGAMRN
  49. INTEGER I, I1M11, K, MX, NX
  50. INTEGER I1MACH
  51. DOUBLE PRECISION FLN, GR, RLN, S, TOL, TRM, X, XDMY, XINC, XM,
  52. * XMIN, XP, XSQ
  53. DOUBLE PRECISION D1MACH
  54. DIMENSION GR(12)
  55. SAVE GR
  56. C
  57. DATA GR(1), GR(2), GR(3), GR(4), GR(5), GR(6), GR(7), GR(8),
  58. * GR(9), GR(10), GR(11), GR(12) /1.00000000000000000D+00,
  59. * -1.56250000000000000D-02,2.56347656250000000D-03,
  60. * -1.27983093261718750D-03,1.34351104497909546D-03,
  61. * -2.43289663922041655D-03,6.75423753364157164D-03,
  62. * -2.66369606131178216D-02,1.41527455519564332D-01,
  63. * -9.74384543032201613D-01,8.43686251229783675D+00,
  64. * -8.97258321640552515D+01/
  65. C
  66. C***FIRST EXECUTABLE STATEMENT DGAMRN
  67. NX = INT(X)
  68. TOL = MAX(D1MACH(4),1.0D-18)
  69. I1M11 = I1MACH(14)
  70. RLN = D1MACH(5)*I1M11
  71. FLN = MIN(RLN,20.0D0)
  72. FLN = MAX(FLN,3.0D0)
  73. FLN = FLN - 3.0D0
  74. XM = 2.0D0 + FLN*(0.2366D0+0.01723D0*FLN)
  75. MX = INT(XM) + 1
  76. XMIN = MX
  77. XDMY = X - 0.25D0
  78. XINC = 0.0D0
  79. IF (X.GE.XMIN) GO TO 10
  80. XINC = XMIN - NX
  81. XDMY = XDMY + XINC
  82. 10 CONTINUE
  83. S = 1.0D0
  84. IF (XDMY*TOL.GT.1.0D0) GO TO 30
  85. XSQ = 1.0D0/(XDMY*XDMY)
  86. XP = XSQ
  87. DO 20 K=2,12
  88. TRM = GR(K)*XP
  89. IF (ABS(TRM).LT.TOL) GO TO 30
  90. S = S + TRM
  91. XP = XP*XSQ
  92. 20 CONTINUE
  93. 30 CONTINUE
  94. S = S/SQRT(XDMY)
  95. IF (XINC.NE.0.0D0) GO TO 40
  96. DGAMRN = S
  97. RETURN
  98. 40 CONTINUE
  99. NX = INT(XINC)
  100. XP = 0.0D0
  101. DO 50 I=1,NX
  102. S = S*(1.0D0+0.5D0/(X+XP))
  103. XP = XP + 1.0D0
  104. 50 CONTINUE
  105. DGAMRN = S
  106. RETURN
  107. END