Skip to content

Commit 1397469

Browse files
committed
Extend the Temme (P,Q) combine helper to all 5 call sites
Fixes the docstring being pushed off gamma_inc_temme_1 by the helper's insertion point; also folds in gamma_inc_minimax and gamma_inc_temme, which had the same duplicated block.
1 parent 2b880b8 commit 1397469

1 file changed

Lines changed: 16 additions & 34 deletions

File tree

src/gamma_inc.jl

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,19 @@ function gamma_inc_taylor_x(a::Float64, x::Float64, ind::Integer)
542542
end
543543
end
544544

545+
# Combine the Temme series value `t` with the Gaussian-tail term `c*w` into (P, Q);
546+
# shared by gamma_inc_minimax, gamma_inc_temme, gamma_inc_temme_1's three branches,
547+
# and the ind=2 wide-band case in _gamma_inc.
548+
function _gamma_inc_temme_combine(c::Float64, w::Float64, t::Float64, rta::Float64, l::Float64)
549+
if l < 1.0
550+
p = c*(w - rt2pin*t/rta)
551+
return (p, 1.0 - p)
552+
else
553+
q = c*(w + rt2pin*t/rta)
554+
return (1.0 - q, q)
555+
end
556+
end
557+
545558
@doc raw"""
546559
gamma_inc_minimax(a,x,z)
547560
@@ -580,13 +593,7 @@ function gamma_inc_minimax(a::Float64, x::Float64, z::Float64)
580593
c6 = @evalpoly(z, d60, d6)
581594

582595
t = @evalpoly(1.0/a, c0, c1, c2, c3, c4, c5, c6, d70, d80)
583-
if l < 1.0
584-
p = c*(w - rt2pin*t/sqrt(a))
585-
return (p, 1.0 - p)
586-
else
587-
q = c*(w + rt2pin*t/sqrt(a))
588-
return (1.0 - q, q)
589-
end
596+
return _gamma_inc_temme_combine(c, w, t, sqrt(a), l)
590597
end
591598
#---USING THE MINIMAX APPROXIMATIONS---
592599
c0 = @evalpoly(z, -.333333333333333E+00, -.159840143443990E+00, -.335378520024220E-01, -.231272501940775E-02)/(@evalpoly(z, 1.0, .729520430331981E+00, .238549219145773E+00, .376245718289389E-01, .239521354917408E-02, -.939001940478355E-05, .633763414209504E-06))
@@ -600,13 +607,7 @@ function gamma_inc_minimax(a::Float64, x::Float64, z::Float64)
600607
c8 = @evalpoly(z, -.686013280418038E-03, .878371203603888E-03)
601608

602609
t = @evalpoly(1.0/a, c0, c1, c2, c3, c4, c5, c6, c7, c8)
603-
if l < 1.0
604-
p = c*(w - rt2pin*t/sqrt(a))
605-
return (p, 1.0 - p)
606-
else
607-
q = c*(w + rt2pin*t/sqrt(a))
608-
return (1.0 - q, q)
609-
end
610+
return _gamma_inc_temme_combine(c, w, t, sqrt(a), l)
610611
end
611612

612613
@doc raw"""
@@ -635,13 +636,7 @@ function gamma_inc_temme(a::Float64, x::Float64, z::Float64)
635636
c1 = @evalpoly(z, d10, d1[1], d1[2], d1[3], d1[4])
636637
c2 = @evalpoly(z, d20, d2[1])
637638
t = @evalpoly(1.0/a, c0, c1, c2)
638-
if l < 1.0
639-
p = c*(w - rt2pin*t/sqrt(a))
640-
return (p, 1.0 - p)
641-
else
642-
q = c*(w + rt2pin*t/sqrt(a))
643-
return (1.0 - q, q)
644-
end
639+
return _gamma_inc_temme_combine(c, w, t, sqrt(a), l)
645640
end
646641

647642
@doc raw"""
@@ -659,19 +654,6 @@ Used instead of it's previous function when ``\sigma \leq e_{0}/\sqrt{a}``.
659654
660655
External links: [DLMF 8.12.8](https://dlmf.nist.gov/8.12.8)
661656
"""
662-
# Combine the Temme series value `t` with the Gaussian-tail term `c*w` into (P, Q);
663-
# shared by gamma_inc_temme_1's three branches and the ind=2 wide-band case in
664-
# _gamma_inc, which recomputes c/w/t itself instead of calling gamma_inc_temme_1.
665-
function _gamma_inc_temme_combine(c::Float64, w::Float64, t::Float64, rta::Float64, l::Float64)
666-
if l < 1.0
667-
p = c*(w - rt2pin*t/rta)
668-
return (p, 1.0 - p)
669-
else
670-
q = c*(w + rt2pin*t/rta)
671-
return (1.0 - q, q)
672-
end
673-
end
674-
675657
function gamma_inc_temme_1(a::Float64, x::Float64, z::Float64, ind::Integer)
676658
iop = ind + 1
677659
l = x/a

0 commit comments

Comments
 (0)