00001 subroutine xsgammainc (a, x, result)
00002
00003
00004
00005
00006
00007 real a, x, result
00008 intrinsic exp, log, sqrt, sign, aint
00009 external gami, alngam, r9lgit, r9lgic, r9gmit
00010
00011
00012
00013
00014 REAL AEPS, AINTA, ALGAP1, ALNEPS, ALNG, ALX,
00015 $ BOT, H, SGA, SGNGAM, SQEPS, T, R1MACH, R9GMIT,
00016 $ R9LGIC, R9LGIT, ALNGAM, GAMI
00017
00018 LOGICAL FIRST
00019
00020 SAVE ALNEPS, SQEPS, BOT, FIRST
00021
00022 DATA FIRST /.TRUE./
00023
00024 if (x .eq. 0.0e0) then
00025
00026 if (a .eq. 0.0e0) then
00027 result = 1.0e0
00028 else
00029 result = 0.0e0
00030 endif
00031
00032 else
00033
00034 IF (FIRST) THEN
00035 ALNEPS = -LOG (R1MACH(3))
00036 SQEPS = SQRT(R1MACH(4))
00037 BOT = LOG (R1MACH(1))
00038 ENDIF
00039 FIRST = .FALSE.
00040
00041 IF (X .LT. 0.E0) CALL XERMSG ('SLATEC', 'XGMAINC', 'X IS NEGATIVE'
00042 + , 2, 2)
00043
00044 IF (X.NE.0.E0) ALX = LOG (X)
00045 SGA = 1.0E0
00046 IF (A.NE.0.E0) SGA = SIGN (1.0E0, A)
00047 AINTA = AINT (A + 0.5E0*SGA)
00048 AEPS = A - AINTA
00049
00050
00051
00052
00053
00054
00055 20 IF (X.GT.1.E0) GO TO 30
00056 IF (A.GE.(-0.5E0) .OR. AEPS.NE.0.E0) CALL ALGAMS (A+1.0E0, ALGAP1,
00057 1 SGNGAM)
00058
00059 result = exp (a*alx + log (R9GMIT (A, X, ALGAP1, SGNGAM, ALX)))
00060 RETURN
00061
00062 30 IF (A.LT.X) GO TO 40
00063 T = R9LGIT (A, X, ALNGAM(A+1.0E0))
00064 IF (T.LT.BOT) CALL XERCLR
00065
00066 result = EXP (a*alx + T)
00067 RETURN
00068
00069 40 ALNG = R9LGIC (A, X, ALX)
00070
00071
00072
00073 H = 1.0E0
00074 IF (AEPS.EQ.0.E0 .AND. AINTA.LE.0.E0) GO TO 50
00075
00076 CALL ALGAMS (A+1.0E0, 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.0E0 - 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