Skip to content

Commit 443376d

Browse files
Update src/gamma.jl
Co-authored-by: David Widmann <[email protected]>
1 parent ec68aaa commit 443376d

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/beta_inc.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ function beta_inc_diff(a::Float64, b::Float64, x::Float64, y::Float64, n::Intege
630630
d = exp(-t)
631631
end
632632

633-
ans = beta_integrand(a,b,x,y,mu)/a
633+
ans = beta_integrand(a, b, x, y, mu)/a
634634
if n == 1 || ans == 0.0
635635
return ans
636636
end
@@ -820,53 +820,53 @@ function beta_inc(a::Float64, b::Float64, x::Float64, y::Float64)
820820
end
821821

822822
if b0 < min(epps, epps*a0)
823-
p = beta_inc_power_series2(a0,b0,x0,epps)
823+
p = beta_inc_power_series2(a0, b0, x0, epps)
824824
q = 1.0 - p
825825
elseif a0 < min(epps, epps*b0) && b0*x0 <= 1.0
826-
q = beta_inc_power_series1(a0,b0,x0,epps)
826+
q = beta_inc_power_series1(a0, b0, x0, epps)
827827
p = 1.0 - q
828828
elseif max(a0,b0) > 1.0
829829
if b0 <= 1.0
830-
p = beta_inc_power_series(a0,b0,x0,epps)
830+
p = beta_inc_power_series(a0, b0, x0, epps)
831831
q = 1.0 - p
832832
elseif x0 >= 0.3
833-
q = beta_inc_power_series(b0,a0,y0,epps)
833+
q = beta_inc_power_series(b0, a0, y0, epps)
834834
p = 1.0 - q
835835
elseif x0 >= 0.1
836836
if b0 > 15.0
837-
q = beta_inc_asymptotic_asymmetric(b0,a0,y0,x0,q,15.0*eps())
837+
q = beta_inc_asymptotic_asymmetric(b0, a0, y0, x0, q, 15.0*eps())
838838
p = 1.0 - q
839839
else
840840
n = 20
841-
q = beta_inc_diff(b0,a0,y0,x0,n,epps)
841+
q = beta_inc_diff(b0, a0, y0, x0, n, epps)
842842
b0 += n
843-
q = beta_inc_asymptotic_asymmetric(b0,a0,y0,x0,q,15.0*eps())
843+
q = beta_inc_asymptotic_asymmetric(b0, a0, y0, x0, q, 15.0*eps())
844844
p = 1.0 - q
845845
end
846846
elseif (x0*b0)^(a0) <= 0.7
847-
p = beta_inc_power_series(a0,b0,x0,epps)
847+
p = beta_inc_power_series(a0, b0, x0, epps)
848848
q = 1.0 - p
849849
else
850850
n = 20
851-
q = beta_inc_diff(b0,a0,y0,x0,n,epps)
851+
q = beta_inc_diff(b0, a0, y0, x0, n, epps)
852852
b0 += n
853-
q = beta_inc_asymptotic_asymmetric(b0,a0,y0,x0,q,15.0*eps())
853+
q = beta_inc_asymptotic_asymmetric(b0, a0, y0, x0, q, 15.0*eps())
854854
p = 1.0 - q
855855
end
856856
elseif a0 >= min(0.2, b0)
857-
p = beta_inc_power_series(a0,b0,x0,epps)
857+
p = beta_inc_power_series(a0, b0, x0, epps)
858858
q = 1.0 - p
859859
elseif x0^a0 <= 0.9
860-
p = beta_inc_power_series(a0,b0,x0,epps)
860+
p = beta_inc_power_series(a0, b0, x0, epps)
861861
q = 1.0 - p
862862
elseif x0 >= 0.3
863-
q = beta_inc_power_series(b0,a0,y0,epps)
863+
q = beta_inc_power_series(b0, a0, y0, epps)
864864
p = 1.0 - q
865865
else
866866
n = 20
867-
q = beta_inc_diff(b0,a0,y0,x0,n,epps)
867+
q = beta_inc_diff(b0, a0, y0, x0, n, epps)
868868
b0 += n
869-
q = beta_inc_asymptotic_asymmetric(b0,a0,y0,x0,q,15.0*eps())
869+
q = beta_inc_asymptotic_asymmetric(b0, a0, y0, x0, q, 15.0*eps())
870870
p = 1.0 - q
871871
end
872872

src/gamma.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,12 +806,12 @@ function logabsbeta(a::T, b::T) where T<:Real
806806
end
807807

808808
if a <= 0 && isinteger(a)
809-
if a + b <= 0
809+
if a + b <= 0 && isinteger(b)
810810
r = logbeta(1 - a - b, b)
811-
sgn = isinteger(b/2) ? 1 : -1
811+
sgn = iseven(Int(b)) ? 1 : -1
812812
return r, sgn
813813
else
814-
return -log(zero(first(promote(a, b)))), 1
814+
return -log(zero(a)), 1
815815
end
816816
end
817817

test/gamma.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,14 @@ end
255255
@test beta(5, 4) beta(4,5)
256256

257257
@testset "negative integer argument" begin
258-
@test beta(-2.0, 2.0) 1/2 rtol=1e-14
259-
@test beta(-5.0, 2.0) 1/20 rtol=1e-14
258+
@test beta(-2.0, 1.0) -1/2 rtol=1e-14
259+
@test beta(-2.0, 2.0) 1/2 rtol=1e-14
260+
@test beta(-5.0, 2.0) 1/20 rtol=1e-14
260261
@test logabsbeta(-2.0, 2.0)[1] -log(2) rtol=1e-14
261262
@test beta(-2.0, -2.0) == Inf
262263
@test logbeta(-2.0, -2.0) == Inf
264+
@test beta(-2.0, 1.9) == Inf
265+
@test logbeta(-2.0, 1.9) == Inf
263266
@test beta(-2.0, 2.1) == Inf
264267
@test logbeta(-2.0, 2.1) == Inf
265268
end

0 commit comments

Comments
 (0)