dgamma.f

Go to the documentation of this file.
00001 *DECK DGAMMA
00002       DOUBLE PRECISION FUNCTION DGAMMA (X)
00003 C***BEGIN PROLOGUE  DGAMMA
00004 C***PURPOSE  Compute the complete Gamma function.
00005 C***LIBRARY   SLATEC (FNLIB)
00006 C***CATEGORY  C7A
00007 C***TYPE      DOUBLE PRECISION (GAMMA-S, DGAMMA-D, CGAMMA-C)
00008 C***KEYWORDS  COMPLETE GAMMA FUNCTION, FNLIB, SPECIAL FUNCTIONS
00009 C***AUTHOR  Fullerton, W., (LANL)
00010 C***DESCRIPTION
00011 C
00012 C DGAMMA(X) calculates the double precision complete Gamma function
00013 C for double precision argument X.
00014 C
00015 C Series for GAM        on the interval  0.          to  1.00000E+00
00016 C                                        with weighted error   5.79E-32
00017 C                                         log weighted error  31.24
00018 C                               significant figures required  30.00
00019 C                                    decimal places required  32.05
00020 C
00021 C***REFERENCES  (NONE)
00022 C***ROUTINES CALLED  D1MACH, D9LGMC, DCSEVL, DGAMLM, INITDS, XERMSG
00023 C***REVISION HISTORY  (YYMMDD)
00024 C   770601  DATE WRITTEN
00025 C   890531  Changed all specific intrinsics to generic.  (WRB)
00026 C   890911  Removed unnecessary intrinsics.  (WRB)
00027 C   890911  REVISION DATE from Version 3.2
00028 C   891214  Prologue converted to Version 4.0 format.  (BAB)
00029 C   900315  CALLs to XERROR changed to CALLs to XERMSG.  (THJ)
00030 C   920618  Removed space from variable name.  (RWC, WRB)
00031 C***END PROLOGUE  DGAMMA
00032       DOUBLE PRECISION X, GAMCS(42), DXREL, PI, SINPIY, SQ2PIL, XMAX,
00033      1  XMIN, Y, D9LGMC, DCSEVL, D1MACH
00034       LOGICAL FIRST
00035 C
00036       SAVE GAMCS, PI, SQ2PIL, NGAM, XMIN, XMAX, DXREL, FIRST
00037       DATA GAMCS(  1) / +.8571195590 9893314219 2006239994 2 D-2      /
00038       DATA GAMCS(  2) / +.4415381324 8410067571 9131577165 2 D-2      /
00039       DATA GAMCS(  3) / +.5685043681 5993633786 3266458878 9 D-1      /
00040       DATA GAMCS(  4) / -.4219835396 4185605010 1250018662 4 D-2      /
00041       DATA GAMCS(  5) / +.1326808181 2124602205 8400679635 2 D-2      /
00042       DATA GAMCS(  6) / -.1893024529 7988804325 2394702388 6 D-3      /
00043       DATA GAMCS(  7) / +.3606925327 4412452565 7808221722 5 D-4      /
00044       DATA GAMCS(  8) / -.6056761904 4608642184 8554829036 5 D-5      /
00045       DATA GAMCS(  9) / +.1055829546 3022833447 3182350909 3 D-5      /
00046       DATA GAMCS( 10) / -.1811967365 5423840482 9185589116 6 D-6      /
00047       DATA GAMCS( 11) / +.3117724964 7153222777 9025459316 9 D-7      /
00048       DATA GAMCS( 12) / -.5354219639 0196871408 7408102434 7 D-8      /
00049       DATA GAMCS( 13) / +.9193275519 8595889468 8778682594 0 D-9      /
00050       DATA GAMCS( 14) / -.1577941280 2883397617 6742327395 3 D-9      /
00051       DATA GAMCS( 15) / +.2707980622 9349545432 6654043308 9 D-10     /
00052       DATA GAMCS( 16) / -.4646818653 8257301440 8166105893 3 D-11     /
00053       DATA GAMCS( 17) / +.7973350192 0074196564 6076717535 9 D-12     /
00054       DATA GAMCS( 18) / -.1368078209 8309160257 9949917230 9 D-12     /
00055       DATA GAMCS( 19) / +.2347319486 5638006572 3347177168 8 D-13     /
00056       DATA GAMCS( 20) / -.4027432614 9490669327 6657053469 9 D-14     /
00057       DATA GAMCS( 21) / +.6910051747 3721009121 3833697525 7 D-15     /
00058       DATA GAMCS( 22) / -.1185584500 2219929070 5238712619 2 D-15     /
00059       DATA GAMCS( 23) / +.2034148542 4963739552 0102605193 2 D-16     /
00060       DATA GAMCS( 24) / -.3490054341 7174058492 7401294910 8 D-17     /
00061       DATA GAMCS( 25) / +.5987993856 4853055671 3505106602 6 D-18     /
00062       DATA GAMCS( 26) / -.1027378057 8722280744 9006977843 1 D-18     /
00063       DATA GAMCS( 27) / +.1762702816 0605298249 4275966074 8 D-19     /
00064       DATA GAMCS( 28) / -.3024320653 7353062609 5877211204 2 D-20     /
00065       DATA GAMCS( 29) / +.5188914660 2183978397 1783355050 6 D-21     /
00066       DATA GAMCS( 30) / -.8902770842 4565766924 4925160106 6 D-22     /
00067       DATA GAMCS( 31) / +.1527474068 4933426022 7459689130 6 D-22     /
00068       DATA GAMCS( 32) / -.2620731256 1873629002 5732833279 9 D-23     /
00069       DATA GAMCS( 33) / +.4496464047 8305386703 3104657066 6 D-24     /
00070       DATA GAMCS( 34) / -.7714712731 3368779117 0390152533 3 D-25     /
00071       DATA GAMCS( 35) / +.1323635453 1260440364 8657271466 6 D-25     /
00072       DATA GAMCS( 36) / -.2270999412 9429288167 0231381333 3 D-26     /
00073       DATA GAMCS( 37) / +.3896418998 0039914493 2081663999 9 D-27     /
00074       DATA GAMCS( 38) / -.6685198115 1259533277 9212799999 9 D-28     /
00075       DATA GAMCS( 39) / +.1146998663 1400243843 4761386666 6 D-28     /
00076       DATA GAMCS( 40) / -.1967938586 3451346772 9510399999 9 D-29     /
00077       DATA GAMCS( 41) / +.3376448816 5853380903 3489066666 6 D-30     /
00078       DATA GAMCS( 42) / -.5793070335 7821357846 2549333333 3 D-31     /
00079       DATA PI / 3.1415926535 8979323846 2643383279 50 D0 /
00080       DATA SQ2PIL / 0.9189385332 0467274178 0329736405 62 D0 /
00081       DATA FIRST /.TRUE./
00082 C***FIRST EXECUTABLE STATEMENT  DGAMMA
00083       IF (FIRST) THEN
00084          NGAM = INITDS (GAMCS, 42, 0.1*REAL(D1MACH(3)) )
00085 C
00086          CALL DGAMLM (XMIN, XMAX)
00087          DXREL = SQRT(D1MACH(4))
00088       ENDIF
00089       FIRST = .FALSE.
00090 C
00091       Y = ABS(X)
00092       IF (Y.GT.10.D0) GO TO 50
00093 C
00094 C COMPUTE GAMMA(X) FOR -XBND .LE. X .LE. XBND.  REDUCE INTERVAL AND FIND
00095 C GAMMA(1+Y) FOR 0.0 .LE. Y .LT. 1.0 FIRST OF ALL.
00096 C
00097       N = X
00098       IF (X.LT.0.D0) N = N - 1
00099       Y = X - N
00100       N = N - 1
00101       DGAMMA = 0.9375D0 + DCSEVL (2.D0*Y-1.D0, GAMCS, NGAM)
00102       IF (N.EQ.0) RETURN
00103 C
00104       IF (N.GT.0) GO TO 30
00105 C
00106 C COMPUTE GAMMA(X) FOR X .LT. 1.0
00107 C
00108       N = -N
00109       IF (X .EQ. 0.D0) CALL XERMSG ('SLATEC', 'DGAMMA', 'X IS 0', 4, 2)
00110       IF (X .LT. 0.0 .AND. X+N-2 .EQ. 0.D0) CALL XERMSG ('SLATEC',
00111      +   'DGAMMA', 'X IS A NEGATIVE INTEGER', 4, 2)
00112       IF (X .LT. (-0.5D0) .AND. ABS((X-AINT(X-0.5D0))/X) .LT. DXREL)
00113      +   CALL XERMSG ('SLATEC', 'DGAMMA',
00114      +   'ANSWER LT HALF PRECISION BECAUSE X TOO NEAR NEGATIVE INTEGER',
00115      +   1, 1)
00116 C
00117       DO 20 I=1,N
00118         DGAMMA = DGAMMA/(X+I-1 )
00119  20   CONTINUE
00120       RETURN
00121 C
00122 C GAMMA(X) FOR X .GE. 2.0 AND X .LE. 10.0
00123 C
00124  30   DO 40 I=1,N
00125         DGAMMA = (Y+I) * DGAMMA
00126  40   CONTINUE
00127       RETURN
00128 C
00129 C GAMMA(X) FOR ABS(X) .GT. 10.0.  RECALL Y = ABS(X).
00130 C
00131  50   IF (X .GT. XMAX) CALL XERMSG ('SLATEC', 'DGAMMA',
00132      +   'X SO BIG GAMMA OVERFLOWS', 3, 2)
00133 C
00134       DGAMMA = 0.D0
00135       IF (X .LT. XMIN) CALL XERMSG ('SLATEC', 'DGAMMA',
00136      +   'X SO SMALL GAMMA UNDERFLOWS', 2, 1)
00137       IF (X.LT.XMIN) RETURN
00138 C
00139       DGAMMA = EXP ((Y-0.5D0)*LOG(Y) - Y + SQ2PIL + D9LGMC(Y) )
00140       IF (X.GT.0.D0) RETURN
00141 C
00142       IF (ABS((X-AINT(X-0.5D0))/X) .LT. DXREL) CALL XERMSG ('SLATEC',
00143      +   'DGAMMA',
00144      +   'ANSWER LT HALF PRECISION, X TOO NEAR NEGATIVE INTEGER', 1, 1)
00145 C
00146       SINPIY = SIN (PI*Y)
00147       IF (SINPIY .EQ. 0.D0) CALL XERMSG ('SLATEC', 'DGAMMA',
00148      +   'X IS A NEGATIVE INTEGER', 4, 2)
00149 C
00150       DGAMMA = -PI/(Y*SINPIY*DGAMMA)
00151 C
00152       RETURN
00153       END
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines