Go to the documentation of this file.00001
00002 FUNCTION GAMMA (X)
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 DIMENSION GCS(23)
00025 LOGICAL FIRST
00026 SAVE GCS, PI, SQ2PIL, NGCS, XMIN, XMAX, DXREL, FIRST
00027 DATA GCS ( 1) / .0085711955 90989331E0/
00028 DATA GCS ( 2) / .0044153813 24841007E0/
00029 DATA GCS ( 3) / .0568504368 1599363E0/
00030 DATA GCS ( 4) /-.0042198353 96418561E0/
00031 DATA GCS ( 5) / .0013268081 81212460E0/
00032 DATA GCS ( 6) /-.0001893024 529798880E0/
00033 DATA GCS ( 7) / .0000360692 532744124E0/
00034 DATA GCS ( 8) /-.0000060567 619044608E0/
00035 DATA GCS ( 9) / .0000010558 295463022E0/
00036 DATA GCS (10) /-.0000001811 967365542E0/
00037 DATA GCS (11) / .0000000311 772496471E0/
00038 DATA GCS (12) /-.0000000053 542196390E0/
00039 DATA GCS (13) / .0000000009 193275519E0/
00040 DATA GCS (14) /-.0000000001 577941280E0/
00041 DATA GCS (15) / .0000000000 270798062E0/
00042 DATA GCS (16) /-.0000000000 046468186E0/
00043 DATA GCS (17) / .0000000000 007973350E0/
00044 DATA GCS (18) /-.0000000000 001368078E0/
00045 DATA GCS (19) / .0000000000 000234731E0/
00046 DATA GCS (20) /-.0000000000 000040274E0/
00047 DATA GCS (21) / .0000000000 000006910E0/
00048 DATA GCS (22) /-.0000000000 000001185E0/
00049 DATA GCS (23) / .0000000000 000000203E0/
00050 DATA PI /3.14159 26535 89793 24E0/
00051
00052 DATA SQ2PIL /0.91893 85332 04672 74E0/
00053 DATA FIRST /.TRUE./
00054
00055
00056
00057
00058 IF (FIRST) THEN
00059
00060
00061
00062
00063
00064
00065 NGCS = INITS (GCS, 23, 0.1*R1MACH(3))
00066
00067 CALL GAMLIM (XMIN, XMAX)
00068 DXREL = SQRT (R1MACH(4))
00069
00070
00071
00072
00073 ENDIF
00074 FIRST = .FALSE.
00075
00076 Y = ABS(X)
00077 IF (Y.GT.10.0) GO TO 50
00078
00079
00080
00081
00082 N = X
00083 IF (X.LT.0.) N = N - 1
00084 Y = X - N
00085 N = N - 1
00086 GAMMA = 0.9375 + CSEVL(2.*Y-1., GCS, NGCS)
00087 IF (N.EQ.0) RETURN
00088
00089 IF (N.GT.0) GO TO 30
00090
00091
00092
00093 N = -N
00094 IF (X .EQ. 0.) CALL XERMSG ('SLATEC', 'GAMMA', 'X IS 0', 4, 2)
00095 IF (X .LT. 0. .AND. X+N-2 .EQ. 0.) CALL XERMSG ('SLATEC', 'GAMMA'
00096 1, 'X IS A NEGATIVE INTEGER', 4, 2)
00097 IF (X .LT. (-0.5) .AND. ABS((X-AINT(X-0.5))/X) .LT. DXREL) CALL
00098 1XERMSG ( 'SLATEC', 'GAMMA',
00099 2'ANSWER LT HALF PRECISION BECAUSE X TOO NEAR NEGATIVE INTEGER'
00100 3, 1, 1)
00101
00102 DO 20 I=1,N
00103 GAMMA = GAMMA / (X+I-1)
00104 20 CONTINUE
00105 RETURN
00106
00107
00108
00109 30 DO 40 I=1,N
00110 GAMMA = (Y+I)*GAMMA
00111 40 CONTINUE
00112 RETURN
00113
00114
00115
00116 50 IF (X .GT. XMAX) CALL XERMSG ('SLATEC', 'GAMMA',
00117 + 'X SO BIG GAMMA OVERFLOWS', 3, 2)
00118
00119 GAMMA = 0.
00120 IF (X .LT. XMIN) CALL XERMSG ('SLATEC', 'GAMMA',
00121 + 'X SO SMALL GAMMA UNDERFLOWS', 2, 1)
00122 IF (X.LT.XMIN) RETURN
00123
00124 GAMMA = EXP((Y-0.5)*LOG(Y) - Y + SQ2PIL + R9LGMC(Y) )
00125 IF (X.GT.0.) RETURN
00126
00127 IF (ABS((X-AINT(X-0.5))/X) .LT. DXREL) CALL XERMSG ('SLATEC',
00128 + 'GAMMA',
00129 + 'ANSWER LT HALF PRECISION, X TOO NEAR NEGATIVE INTEGER', 1, 1)
00130
00131 SINPIY = SIN (PI*Y)
00132 IF (SINPIY .EQ. 0.) CALL XERMSG ('SLATEC', 'GAMMA',
00133 + 'X IS A NEGATIVE INTEGER', 4, 2)
00134
00135 GAMMA = -PI / (Y*SINPIY*GAMMA)
00136
00137 RETURN
00138 END