1
DOUBLE PRECISION FUNCTION alngam(x)
2
C**********************************************************************
4
C DOUBLE PRECISION FUNCTION ALNGAM(X)
5
C double precision LN of the GAMma function
11
C Returns the natural logarithm of GAMMA(X).
17
C X --> value at which scaled log gamma is to be returned
18
C X is DOUBLE PRECISION
24
C If X .le. 6.0, then use recursion to get X below 3
25
C then apply rational approximation number 5236 of
26
C Hart et al, Computer Approximations, John Wiley and
29
C If X .gt. 6.0, then use recursion to get X to at least 12 and
30
C then use formula 5423 of the same source.
32
C**********************************************************************
35
DOUBLE PRECISION hln2pi
36
PARAMETER (hln2pi=0.91893853320467274178D0)
38
C .. Scalar Arguments ..
42
DOUBLE PRECISION offset,prod,xx
46
DOUBLE PRECISION coef(5),scoefd(4),scoefn(9)
48
C .. External Functions ..
49
DOUBLE PRECISION devlpl
52
C .. Intrinsic Functions ..
53
INTRINSIC log,dble,int
55
C .. Data statements ..
56
DATA scoefn(1)/0.62003838007127258804D2/,
57
+ scoefn(2)/0.36036772530024836321D2/,
58
+ scoefn(3)/0.20782472531792126786D2/,
59
+ scoefn(4)/0.6338067999387272343D1/,
60
+ scoefn(5)/0.215994312846059073D1/,
61
+ scoefn(6)/0.3980671310203570498D0/,
62
+ scoefn(7)/0.1093115956710439502D0/,
63
+ scoefn(8)/0.92381945590275995D-2/,
64
+ scoefn(9)/0.29737866448101651D-2/
65
DATA scoefd(1)/0.62003838007126989331D2/,
66
+ scoefd(2)/0.9822521104713994894D1/,
67
+ scoefd(3)/-0.8906016659497461257D1/,
68
+ scoefd(4)/0.1000000000000000000D1/
69
DATA coef(1)/0.83333333333333023564D-1/,
70
+ coef(2)/-0.27777777768818808D-2/,
71
+ coef(3)/0.79365006754279D-3/,coef(4)/-0.594997310889D-3/,
72
+ coef(5)/0.8065880899D-3/
74
C .. Executable Statements ..
75
IF (.NOT. (x.LE.6.0D0)) GO TO 70
78
IF (.NOT. (x.GT.3.0D0)) GO TO 30
79
10 IF (.NOT. (xx.GT.3.0D0)) GO TO 20
85
30 IF (.NOT. (x.LT.2.0D0)) GO TO 60
86
40 IF (.NOT. (xx.LT.2.0D0)) GO TO 50
92
60 alngam = devlpl(scoefn,9,xx-2.0D0)/devlpl(scoefd,4,xx-2.0D0)
95
C COMPUTE RATIONAL APPROXIMATION TO GAMMA(X)
105
C IF NECESSARY MAKE X AT LEAST 12 AND CARRY CORRECTION IN OFFSET
109
IF (.NOT. (n.GT.0)) GO TO 90
112
prod = prod* (x+dble(i-1))
114
offset = offset - log(prod)
121
C COMPUTE POWER SERIES
124
100 alngam = devlpl(coef,5,1.0D0/ (xx**2))/xx
125
alngam = alngam + offset + (xx-0.5D0)*log(xx) - xx