Skip to content

Commit a1dc369

Browse files
authored
Merge pull request #63 from JuliaMath/test
Small dispatch fix for gamma
2 parents dc22b7e + 5ae131e commit a1dc369

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/gamma.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Adapted from Cephes Mathematical Library (MIT license https://en.smath.com/view/CephesMathLibrary/license) by Stephen L. Moshier
2-
gamma(z::Number) = _gamma(float(z))
3-
_gamma(x::Float32) = Float32(_gamma(Float64(x)))
2+
gamma(x::Float64) = _gamma(x)
3+
gamma(x::Float32) = Float32(_gamma(Float64(x)))
44

55
function _gamma(x::Float64)
66
T = Float64
@@ -50,10 +50,9 @@ function _gamma(x::Float64)
5050
return z * p / q
5151
end
5252

53-
5453
function gamma(n::Integer)
5554
n < 0 && throw(DomainError(n, "`n` must not be negative."))
56-
n == 0 && return Inf*float(n)
55+
n == 0 && return Inf*one(n)
5756
n > 20 && return gamma(float(n))
5857
@inbounds return Float64(factorial(n-1))
5958
end

test/gamma_test.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ x = rand(10000)*170
33
@test SpecialFunctions.gamma.(BigFloat.(-x)) Bessels.gamma.(-x)
44
@test isnan(Bessels.gamma(NaN))
55
@test isinf(Bessels.gamma(Inf))
6+
7+
x = [0, 1, 2, 3, 8, 15, 20, 30]
8+
@test SpecialFunctions.gamma.(x) Bessels.gamma.(x)

0 commit comments

Comments
 (0)