Skip to content

Commit 66eb6c7

Browse files
authored
Merge pull request #325 from devmotion/dw/logabsbeta
Fix `logabsbeta` for BigFloat
2 parents 734f242 + 9e7461f commit 66eb6c7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/beta_inc.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ const exparg_p = log(prevfloat(floatmax(Float64)))
99
1010
Computes ``log(\\Gamma(b)/\\Gamma(a+b))`` when b >= 8
1111
"""
12-
loggammadiv(a::Number, b::Number) = _loggammadiv(float(a), float(b))
12+
loggammadiv(a::Number, b::Number) = _loggammadiv(promote(float(a), float(b))...)
1313

14+
# TODO: Add a proper implementation
15+
_loggammadiv(a::Number, b::Number) = loggamma(b) - loggamma(a + b) # handle e.g. BigFloat (used by `logabsbeta`)
1416
_loggammadiv(a::T, b::T) where {T<:Base.IEEEFloat} = T(_loggammadiv(Float64(a), Float64(b))) # handle Float16, Float32
1517
function _loggammadiv(a::Float64, b::Float64)
1618
@assert b >= 8

test/beta_inc.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
@test beta_inc(a, b, x, 1 - x) == beta_inc(a, Float64(b), Float64(x), 1 - x)
228228

229229
@test SpecialFunctions.loggammadiv(13.89, 21.0001) log(gamma(big(21.0001))/gamma(big(21.0001)+big(13.89)))
230+
@test SpecialFunctions.loggammadiv(big(13.89), big(21.0001)) log(gamma(big(21.0001))/gamma(big(21.0001)+big(13.89)))
230231
@test SpecialFunctions.stirling_corr(11.99, 100.1) SpecialFunctions.stirling_error(11.99) + SpecialFunctions.stirling_error(100.1) - SpecialFunctions.stirling_error(11.99 + 100.1)
231232
end
232233

test/gamma.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,24 @@ end
274274
@test logabsbeta(1e8, 0.5)[1] log(0.00017724538531210809) rtol=1e-14
275275
end
276276

277+
@testset "BigFloat" begin
278+
@test beta(big(3), big(5)) inv(big(105))
279+
@test beta(big(3//2), big(7//2)) 5 * big(π) / 128
280+
@test beta(big(1e4), big(3//2)) 8.86193693673874630607029e-7 rtol=1e-14
281+
@test beta(big(1e8), big(1//2)) 0.00017724538531210809 rtol=1e-14
282+
283+
@test logbeta(big(5), big(4)) log(beta(big(5), big(4)))
284+
@test logbeta(big(5.0), big(4)) log(beta(big(5), big(4)))
285+
@test logbeta(big(1e4), big(3//2)) log(8.86193693673874630607029e-7) rtol=1e-14
286+
@test logbeta(big(1e8), big(1//2)) log(0.00017724538531210809) rtol=1e-14
287+
288+
@test logabsbeta(-big(2), big(2))[1] -log(big(2))
289+
@test logabsbeta(-big(2.0), big(2))[1] -log(big(2))
290+
@test logabsbeta(-big(2), big(2//1))[1] -log(big(2))
291+
@test logabsbeta(big(1e4), big(3//2))[1] log(8.86193693673874630607029e-7) rtol=1e-14
292+
@test logabsbeta(big(1e8), big(1//2))[1] log(0.00017724538531210809) rtol=1e-14
293+
end
294+
277295
@test beta(-1/2, 3) beta(-1/2 + 0im, 3 + 0im) -16/3
278296
@test logabsbeta(-1/2, 3)[1] log(16/3)
279297
@test beta(Float32(5), Float32(4)) == beta(Float32(4), Float32(5))

0 commit comments

Comments
 (0)