@@ -426,25 +426,24 @@ See also: [`gamma_inc(a,x,ind)`](@ref SpecialFunctions.gamma_inc)
426426"""
427427function gamma_inc_taylor (a:: Float64 , x:: Float64 , ind:: Integer )
428428 acc = acc0[ind + 1 ]
429+ tolerance = 0.5 acc
429430
430431 # compute first 21 terms
431432 ts = cumprod (ntuple (i -> x / (a + i), Val (21 )))
432- last_t = findfirst (< (1.0e-3 ), ts)
433- last_t = last_t === nothing ? 20 : last_t - 1
434- next_t = last_t + 1
435-
433+
436434 # sum the smaller terms directly
437- sm = t = ts[next_t]
438- apn = a + next_t
439- tolerance = 0.5 acc
435+ first_small_t = something ( findfirst ( < ( 1.0e-3 ), ts), 21 )
436+ sm = t = ts[first_small_t]
437+ apn = a + first_small_t
440438 while t > tolerance
441439 apn += 1.0
442440 t *= x / apn
443441 sm += t
444442 end
445443
446444 # sum terms from small to large
447- for j ∈ last_t: (- 1 ): 1
445+ last_large_t = first_small_t - 1
446+ for j ∈ last_large_t: (- 1 ): 1
448447 sm += ts[j]
449448 end
450449
@@ -471,21 +470,20 @@ function gamma_inc_asym(a::Float64, x::Float64, ind::Integer)
471470
472471 # compute first 21 terms
473472 ts = cumprod (ntuple (i -> (a - i) / x, Val (21 )))
474- last_t = findfirst (x -> abs (x) < 1.0e-3 , ts)
475- last_t = last_t === nothing ? 20 : last_t - 1
476- next_t = last_t + 1
477473
478474 # sum the smaller terms directly
479- sm = t = ts[next_t]
480- amn = a - next_t
481- while abs (t) >= acc
475+ first_small_t = something (findfirst (x -> abs (x) < 1.0e-3 , ts), 21 )
476+ sm = t = ts[first_small_t]
477+ amn = a - first_small_t
478+ while abs (t) ≥ acc
482479 amn -= 1.0
483480 t *= amn / x
484481 sm += t
485482 end
486483
487484 # sum terms from small to large
488- for j in last_t: (- 1 ): 1
485+ last_large_t = first_small_t - 1
486+ for j in last_large_t: (- 1 ): 1
489487 sm += ts[j]
490488 end
491489
0 commit comments