Skip to content

Commit

Permalink
Consistent return type from lstirling_asym(x::Float32) (#141)
Browse files Browse the repository at this point in the history
* Consistent return type from `lstirling_asym(x::Float32)`

As described in #140

* Avoid broadcasting

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>

* Add tests

* Add newline

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
  • Loading branch information
dmbates and devmotion authored Apr 3, 2022
1 parent 7185ee5 commit 958d48a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit 958d48a

Please sign in to comment.