Skip to content

Commit fe3a5d5

Browse files
committed
Restructure _gamma_inc_inv to only compute polynomial coefficients
when they are needed.
1 parent 73528c1 commit fe3a5d5

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/gamma_inc.jl

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -977,25 +977,31 @@ function _gamma_inc_inv(a::Float64, p::Float64, q::Float64)
977977
end
978978

979979
px, qx = gamma_inc(a, x, 0)
980-
ck1 = pcase ? -r*(px - p) : r*(qx - q)
981-
ck2 = (x - a + 1.0)/(2.0*x)
982-
ck3 = (@horner(x, @horner(a, 1, -3, 2), @horner(a, 4, -4), 2))/(6*x²)
983-
r = ck1
984-
985-
# This check is not in the invincgam subroutine from IncgamFI but it probably
986-
# should be since the routine fails to compute a finite value for very small p
987-
if !isfinite(ck3)
988-
break
989-
end
990980

991-
if a > 0.1
992-
x0 = @horner(r, x, 1.0, ck2, ck3)
993-
else
994-
if a > 0.05
995-
x0 = @horner(r, x, 1.0, ck2)
981+
ck1 = pcase ? -r*(px - p) : r*(qx - q)
982+
if a > 0.05
983+
ck2 = (x - a + 1.0)/(2.0*x)
984+
985+
# This check is not in the invincgam subroutine from IncgamFI but it probably
986+
# should be since the routine fails to compute a finite value for very small p
987+
if !isfinite(ck2)
988+
break
989+
end
990+
991+
if a > 0.1
992+
ck3 = (@horner(x, @horner(a, 1, -3, 2), @horner(a, 4, -4), 2))/(6*x²)
993+
994+
# This check is not in the invincgam subroutine from IncgamFI but it probably
995+
# should be since the routine fails to compute a finite value for very small p
996+
if !isfinite(ck3)
997+
break
998+
end
999+
x0 = @horner(ck1, x, 1.0, ck2, ck3)
9961000
else
997-
x0 = x + r
1001+
x0 = @horner(ck1, x, 1.0, ck2)
9981002
end
1003+
else
1004+
x0 = x + ck1
9991005
end
10001006

10011007
t = abs(x/x0 - 1.0)

0 commit comments

Comments
 (0)