diff --git a/src/Factorial.jl b/src/Factorial.jl index 883d0cd..68851f7 100644 --- a/src/Factorial.jl +++ b/src/Factorial.jl @@ -124,11 +124,11 @@ const INVERSE_FACTORIALS = ( function fac(n::Integer, T) if n < 0 throw(DomainError(n, "fac not implemented for n < 0")) - elseif T == Float64 + elseif issimplefloat(T) if n + 1 <= length(FACTORIALS) - FACTORIALS[n + 1] + convert(T, FACTORIALS[n + 1]) else - Inf + convert(T, Inf) end else BigFloat(factorial(big(n))) @@ -139,11 +139,11 @@ end function inv_fac(n::Integer, T) if n < 0 throw(DomainError(n, "inv_fac not implemented for n < 0")) - elseif T == Float64 + elseif issimplefloat(T) if n + 1 <= length(INVERSE_FACTORIALS) - INVERSE_FACTORIALS[n + 1] + convert(T, INVERSE_FACTORIALS[n + 1]) else - 0.0 + zero(T) end else BigFloat(inv(factorial(big(n)))) diff --git a/test/Factorial.jl b/test/Factorial.jl index 4217612..5235d03 100644 --- a/test/Factorial.jl +++ b/test/Factorial.jl @@ -2,6 +2,11 @@ @test_throws DomainError PolyLog.fac(-1, Float64) @test_throws DomainError PolyLog.fac(-1, BigFloat) + @test typeof(PolyLog.fac(1, Float16)) == Float16 + @test typeof(PolyLog.fac(1, Float32)) == Float32 + @test typeof(PolyLog.fac(1, Float64)) == Float64 + @test typeof(PolyLog.fac(1, BigFloat)) == BigFloat + @test PolyLog.fac( 0, Float64) == 1.0 @test PolyLog.fac( 1, Float64) == 1.0 @test PolyLog.fac( 2, Float64) == 2.0 @@ -22,6 +27,11 @@ end @test_throws DomainError PolyLog.inv_fac(-1, Float64) @test_throws DomainError PolyLog.inv_fac(-1, BigFloat) + @test typeof(PolyLog.inv_fac(1, Float16)) == Float16 + @test typeof(PolyLog.inv_fac(1, Float32)) == Float32 + @test typeof(PolyLog.inv_fac(1, Float64)) == Float64 + @test typeof(PolyLog.inv_fac(1, BigFloat)) == BigFloat + @test PolyLog.inv_fac( 0, Float64) == 1.0 @test PolyLog.inv_fac( 1, Float64) == 1.0 @test PolyLog.inv_fac( 2, Float64) == 1/2