Skip to content
17 changes: 9 additions & 8 deletions src/gamma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -748,14 +748,15 @@ if Base.MPFR.version() >= v"4.0.0"
end
end

## from base/combinatorics.jl'

function gamma(n::Union{Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64})
n < 0 && throw(DomainError(n, "`n` must not be negative."))
n == 0 && return Inf
n <= 2 && return 1.0
n > 20 && return gamma(Float64(n))
@inbounds return Float64(Base._fact_table64[n-1])
const _shifted_gamma_fact_table = [Inf; gamma.(collect(1.0:171.0))]

function gamma(n::Union{Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64,Int128,UInt128})
if !(0 <= n <= 171)
0 <= n && return Inf
else
return @inbounds _shifted_gamma_fact_table[(n+1)]
end
throw(DomainError(n, "`n` must not be negative."))
end

## from base/math.jl
Expand Down