00001 subroutine xgammainc (a, x, result)
00002
00003
00004
00005
00006
00007 double precision a, x, result
00008 intrinsic exp, log, sqrt, sign, aint
00009 external dgami, dlngam, d9lgit, d9lgic, d9gmit
00010
00011
00012
00013
00014 DOUBLE PRECISION AEPS, AINTA, ALGAP1, ALNEPS, ALNG, ALX,
00015 $ BOT, H, SGA, SGNGAM, SQEPS, T, D1MACH, D9GMIT,
00016 $ D9LGIC, D9LGIT, DLNGAM, DGAMI
00017
00018 LOGICAL FIRST
00019
00020 SAVE ALNEPS, SQEPS, BOT, FIRST
00021
00022 DATA FIRST /.TRUE./
00023
00024 if (x .eq. 0.0d0) then
00025
00026 if (a .eq. 0.0d0) then
00027 result = 1.0d0
00028 else
00029 result = 0.0d0
00030 endif
00031
00032 else
00033
00034 IF (FIRST) THEN
00035 ALNEPS = -LOG (D1MACH(3))
00036 SQEPS = SQRT(D1MACH(4))
00037 BOT = LOG (D1MACH(1))
00038 ENDIF
00039 FIRST = .FALSE.
00040
00041 IF (X .LT. 0.D0) CALL XERMSG ('SLATEC', 'XGMAINC', 'X IS NEGATIVE'
00042 + , 2, 2)
00043
00044 IF (X.NE.0.D0) ALX = LOG (X)
00045 SGA = 1.0D0
00046 IF (A.NE.0.D0) SGA = SIGN (1.0D0, A)
00047 AINTA = AINT (A + 0.5D0*SGA)
00048 AEPS = A - AINTA
00049
00050
00051
00052
00053
00054
00055 20 IF (X.GT.1.D0) GO TO 30
00056 IF (A.GE.(-0.5D0) .OR. AEPS.NE.0.D0) CALL DLGAMS (A+1.0D0, ALGAP1,
00057 1 SGNGAM)
00058
00059 result = exp (a*alx + log (D9GMIT (A, X, ALGAP1, SGNGAM, ALX)))
00060 RETURN
00061
00062 30 IF (A.LT.X) GO TO 40
00063 T = D9LGIT (A, X, DLNGAM(A+1.0D0))
00064 IF (T.LT.BOT) CALL XERCLR
00065
00066 result = EXP (a*alx + T)
00067 RETURN
00068
00069 40 ALNG = D9LGIC (A, X, ALX)
00070
00071
00072
00073 H = 1.0D0
00074 IF (AEPS.EQ.0.D0 .AND. AINTA.LE.0.D0) GO TO 50
00075
00076 CALL DLGAMS (A+1.0D0, ALGAP1, SGNGAM)
00077 T = LOG (ABS(A)) + ALNG - ALGAP1
00078 IF (T.GT.ALNEPS) GO TO 60
00079
00080 IF (T.GT.(-ALNEPS)) H = 1.0D0 - SGA * SGNGAM * EXP(T)
00081 IF (ABS(H).GT.SQEPS) GO TO 50
00082
00083 CALL XERCLR
00084 CALL XERMSG ('SLATEC', 'XGMAINC', 'RESULT LT HALF PRECISION', 1,
00085 + 1)
00086
00087
00088
00089
00090 50 result = H
00091 RETURN
00092
00093
00094 60 IF (T.LT.BOT) CALL XERCLR
00095 result = -SGA * SGNGAM * EXP(T)
00096 RETURN
00097
00098 endif
00099 return
00100 end