@@ -575,9 +575,9 @@ contains
575575 ! Fortran 90 program by Jim-215-Fisher
576576 !
577577 ${t1}$, intent(in) :: p, x
578- integer :: n, m
578+ integer :: n
579579
580- ${t2}$ :: res, p_lim, a, b, g, c, d, y, ss
580+ ${t2}$ :: res, p_lim, a, b, g, c, d, y
581581 ${t2}$, parameter :: zero = 0.0_${k2}$, one = 1.0_${k2}$
582582 ${t2}$, parameter :: dm = tiny(1.0_${k2}$) * 10 ** 6
583583 ${t1}$, parameter :: zero_k1 = 0.0_${k1}$
@@ -603,6 +603,9 @@ contains
603603 call error_stop("Error(gpx): Incomplete gamma function with " &
604604 //"negative x must come with a whole number p not too small")
605605
606+ if(x < zero_k1) call error_stop("Error(gpx): Incomplete gamma" &
607+ // " function with negative x must have an integer parameter p")
608+
606609 if(p >= p_lim) then !use modified Lentz method of continued fraction
607610 !for eq. (15) in the above reference.
608611 a = one
@@ -670,7 +673,6 @@ contains
670673
671674 else !Algorithm 2 in the reference
672675
673- m = nint(ss)
674676 a = - x
675677 c = one / a
676678 d = p - one
@@ -689,9 +691,9 @@ contains
689691
690692 end do
691693
692- if(y >= b * tol_${k2}$ .and. mod(m , 2) /= 0) b = b + d * c / a
694+ if(y >= b * tol_${k2}$ .and. mod(int(p) , 2) /= 0) b = b + d * c / a
693695
694- g = ((-1) ** m * exp(-a + log_gamma(p) - (p - 1) * log(a)) + b) / a
696+ g = ((-1) ** p * exp(-a + log_gamma(p) - (p - 1) * log(a)) + b) / a
695697 end if
696698
697699 res = g
0 commit comments