@@ -864,16 +864,13 @@ function _gamma_inc(a::Float64, x::Float64, ind::Integer)
864
864
throw (DomainError ((a, x, ind), " `a` and `x` must be greater than 0 ---- Domain : (0, Inf)" ))
865
865
elseif a == 0.0 && x == 0.0
866
866
throw (DomainError ((a, x, ind), " `a` and `x` must be greater than 0 ---- Domain : (0, Inf)" ))
867
- elseif a* x == 0.0
868
- if x <= a
869
- return (0.0 , 1.0 )
870
- else
871
- return (1.0 , 0.0 )
872
- end
873
867
elseif isnan (a) || isnan (x)
874
- return (a* x, a* x)
875
- elseif isinf (x)
868
+ ax = a* x
869
+ return (ax, ax)
870
+ elseif a == 0.0 || isinf (x)
876
871
return (1.0 , 0.0 )
872
+ elseif x == 0.0
873
+ return (0.0 , 1.0 )
877
874
end
878
875
879
876
if a >= 1.0
@@ -1042,8 +1039,6 @@ function __gamma_inc_inv(a::Float64, minpq::Float64, pcase::Bool)
1042
1039
logabsgam = logabsgamma (a)[1 ]
1043
1040
# Newton-like higher order iteration with upper limit as 15.
1044
1041
while t > 1.0e-15 && n < 15
1045
- x = x0
1046
- x² = x* x
1047
1042
if ! haseta
1048
1043
dlnr = (1.0 - a)* log (x) + x + logabsgam
1049
1044
if dlnr > log (floatmax (Float64)/ 1000.0 )
@@ -1068,22 +1063,23 @@ function __gamma_inc_inv(a::Float64, minpq::Float64, pcase::Bool)
1068
1063
end
1069
1064
1070
1065
if a > 0.1
1071
- ck3 = (@horner (x, @horner (a, 1 , - 3 , 2 ), @horner (a, 4 , - 4 ), 2 ))/ (6 * x² )
1066
+ ck3 = (@horner (x, @horner (a, 1 , - 3 , 2 ), @horner (a, 4 , - 4 ), 2 ))/ (6 * x^ 2 )
1072
1067
1073
1068
# This check is not in the invincgam subroutine from IncgamFI but it probably
1074
1069
# should be since the routine fails to compute a finite value for very small p
1075
1070
if ! isfinite (ck3)
1076
1071
break
1077
1072
end
1078
- x0 = @horner (ck1, x , 1.0 , ck2, ck3)
1073
+ Δx = ck1 * @horner (ck1, 1.0 , ck2, ck3)
1079
1074
else
1080
- x0 = @horner (ck1, x , 1.0 , ck2)
1075
+ Δx = ck1 * @horner (ck1, 1.0 , ck2)
1081
1076
end
1082
1077
else
1083
- x0 = x + ck1
1078
+ Δx = ck1
1084
1079
end
1085
1080
1086
- t = abs (x/ x0 - 1.0 )
1081
+ x0 = x + Δx
1082
+ t = abs (Δx/ x0)
1087
1083
n += 1
1088
1084
x = x0
1089
1085
end
0 commit comments