Skip to content

Commit 036ee69

Browse files
Comparative tests
1 parent 8d57c32 commit 036ee69

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/e_lgamma_r.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,36 @@ for (T, lgamma) in ((Float64, _lgamma_r), (Float32, _lgammaf_r))
5757
@test signgam == 1
5858
end
5959
end
60+
61+
# Comparison against the "gold standard" (in context of SpecialFunctions.jl)
62+
using OpenLibm_jll
63+
64+
function openlibm_logabsgamma(x::Float64)
65+
signp = Ref{Int32}()
66+
y = ccall((:lgamma_r,libopenlibm), Float64, (Float64, Ptr{Int32}), x, signp)
67+
return y, Int(signp[])
68+
end
69+
function openlibm_logabsgamma(x::Float32)
70+
signp = Ref{Int32}()
71+
y = ccall((:lgammaf_r,libopenlibm), Float32, (Float32, Ptr{Int32}), x, signp)
72+
return y, Int(signp[])
73+
end
74+
75+
meetstol(x::Float64, atol) = isapprox(openlibm_logabsgamma(x)[1], _lgamma_r(x)[1], atol=atol)
76+
meetstol(x::Float32, atol) = isapprox(openlibm_logabsgamma(x)[1], _lgammaf_r(x)[1], atol=atol)
77+
78+
79+
@testset "logabsgamma validation against OpenLibm, Float64" begin
80+
@test all(x -> meetstol(x, 1e-13), -50:1e-4:50)
81+
@test all(x -> meetstol(x, 1e-12), 50:1e-4:500)
82+
@test all(x -> meetstol(x, 1e-11), 500:1e-3:1000)
83+
@test all(x -> meetstol(x, 1e-10), 1000:1e-1:10000)
84+
end
85+
86+
@testset "logabsgamma validation against OpenLibm, Float64" begin
87+
@test all(x -> meetstol(x, 1f-5), -0.0f0:1f-4:25.0f0)
88+
@test all(x -> meetstol(x, 1f-4), -25.0f0:1f-4:0.0f0)
89+
@test all(x -> meetstol(x, 1f-4), 25.0f0:1f-4:100.0f0)
90+
@test all(x -> meetstol(x, 1f-3), 100.0f0:1f-4:1000.0f0)
91+
@test all(x -> meetstol(x, 1f-1), 1000.0f0:1f-1:10000.0f0)
92+
end

0 commit comments

Comments
 (0)