Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent return type from lstirling_asym(x::Float32) #141

Merged
merged 4 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ lstirling_asym(x::BigFloat) = loggamma(x) + x - log(x)*(x - big(0.5)) - log2π/b
lstirling_asym(x::Integer) = lstirling_asym(float(x))

const lstirlingF64 = Float64[lstirling_asym(k) for k in big(1):big(64)]
const lstirlingF32 = Float64[lstirling_asym(k) for k in big(1):big(40)]
const lstirlingF32 = [Float32(lstirlingF64[i]) for i in 1:40]

function lstirling_asym(x::Float64)
isinteger(x) && (0 < x ≤ length(lstirlingF64)) && return lstirlingF64[Int(x)]
Expand Down
7 changes: 7 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ end
@test isone(binompdf(n, p, k))
end
end

@testset "lstirling_asym" begin
# can test for equality here because the lhs is the way the value is created
@test Float32(lstirling_asym(1.0)) == @inferred lstirling_asym(1.0f0)
# for 64.0f0 the expansion is used but for 64.0 the BigFloat value is rounded
@test Float32(lstirling_asym(64.0)) ≈ @inferred lstirling_asym(64.0f0)
end