Skip to content

Commit

Permalink
Merge pull request #63 from JuliaMath/test
Browse files Browse the repository at this point in the history
Small dispatch fix for gamma
  • Loading branch information
heltonmc authored Nov 2, 2022
2 parents dc22b7e + 5ae131e commit a1dc369
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/gamma.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Adapted from Cephes Mathematical Library (MIT license https://en.smath.com/view/CephesMathLibrary/license) by Stephen L. Moshier
gamma(z::Number) = _gamma(float(z))
_gamma(x::Float32) = Float32(_gamma(Float64(x)))
gamma(x::Float64) = _gamma(x)
gamma(x::Float32) = Float32(_gamma(Float64(x)))

function _gamma(x::Float64)
T = Float64
Expand Down Expand Up @@ -50,10 +50,9 @@ function _gamma(x::Float64)
return z * p / q
end


function gamma(n::Integer)
n < 0 && throw(DomainError(n, "`n` must not be negative."))
n == 0 && return Inf*float(n)
n == 0 && return Inf*one(n)
n > 20 && return gamma(float(n))
@inbounds return Float64(factorial(n-1))
end
3 changes: 3 additions & 0 deletions test/gamma_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ x = rand(10000)*170
@test SpecialFunctions.gamma.(BigFloat.(-x)) Bessels.gamma.(-x)
@test isnan(Bessels.gamma(NaN))
@test isinf(Bessels.gamma(Inf))

x = [0, 1, 2, 3, 8, 15, 20, 30]
@test SpecialFunctions.gamma.(x) Bessels.gamma.(x)

0 comments on commit a1dc369

Please sign in to comment.