Skip to content

Commit

Permalink
Handle the case when alpha and beta are zero in the betacdf
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Feb 10, 2022
1 parent af14aba commit cb1f325
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/distrs/beta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end

function betacdf::Real, β::Real, x::Real)
# Handle a degenerate case
if iszero(α)
if iszero(α) && β > 0
return float(last(promote(α, β, x, x >= 0)))
end

Expand All @@ -37,7 +37,7 @@ end

function betaccdf::Real, β::Real, x::Real)
# Handle a degenerate case
if iszero(α)
if iszero(α) && β > 0
return float(last(promote(α, β, x, x < 0)))
end

Expand All @@ -48,7 +48,7 @@ end
# to an implementation based on the hypergeometric function ₂F₁ to avoid underflow.
function betalogcdf::T, β::T, x::T) where {T<:Real}
# Handle a degenerate case
if iszero(α)
if iszero(α) && β > 0
return log(last(promote(x, x >= 0)))
end

Expand All @@ -67,7 +67,7 @@ betalogcdf(α::Real, β::Real, x::Real) = betalogcdf(promote(α, β, x)...)

function betalogccdf::Real, β::Real, x::Real)
# Handle a degenerate case
if iszero(α)
if iszero(α) && β > 0
return log(last(promote(α, β, x, x < 0)))
end

Expand Down
4 changes: 4 additions & 0 deletions test/rmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ end
# Test p=0.48 separately since R fails. (It's pretty slow, though, caused by the cdf being 9.0797754e-317)
@test betainvcdf(1000, 2, betacdf(1000, 2, 0.48)) 0.48
end
@testset "$(f)(0, 0, $x) should error" for f in (betacdf, betaccdf, betalogcdf, betalogccdf),
x in (0.0, 0.5, 1.0)
@test_throws DomainError f(0.0, 0.0, x)
end

rmathcomp_tests("binom", [
((1, 0.5), 0.0:1.0),
Expand Down

0 comments on commit cb1f325

Please sign in to comment.