GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dlngam.f
Go to the documentation of this file.
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