Skip to content

Commit e8f78ef

Browse files
committed
dispatch int gamma
1 parent 325cb5b commit e8f78ef

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/besselj.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ In general, this is most accurate for small arguments and when nu > x.
348348
function besselj_power_series(v, x::T) where T
349349
MaxIter = 3000
350350
S = promote_type(T, Float64)
351-
v, x = S(v), S(x)
351+
x = S(x)
352352

353353
out = zero(S)
354-
a = (x/2)^v / gamma(v + one(S))
354+
a = (x/2)^v / gamma(v + 1)
355355
t2 = (x/2)^2
356356
for i in 0:MaxIter
357357
out += a

src/gamma.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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))
2+
gamma(x::Float64) = _gamma(x)
33
_gamma(x::Float32) = Float32(_gamma(Float64(x)))
44

55
function _gamma(x::Float64)
@@ -50,7 +50,6 @@ 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."))
5655
n == 0 && return Inf*float(n)

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)