Skip to content

Commit 8e0564c

Browse files
fredrikekreararslan
authored andcommitted
avoid overwrite warning while the deprecation in Base is still active (#100)
1 parent f56296a commit 8e0564c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/gamma.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,13 @@ end
754754
@inline lgamma(x::Real) = lgamma(float(x))
755755

756756
## from base/numbers.jl
757-
# TODO: deprecate instead of doing this type-piracy here?
758-
Base.factorial(x::Number) = gamma(x + 1) # fallback for x not Integer
757+
758+
# this trickery is needed while the deprecated method in Base exists
759+
@static if !hasmethod(Base.factorial, Tuple{Number})
760+
import Base: factorial
761+
end
762+
factorial(x) = Base.factorial(x) # to make SpecialFunctions.factorial work unconditionally
763+
factorial(x::Number) = gamma(x + 1) # fallback for x not Integer
759764

760765
else # @static if
761766

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,9 @@ end
576576
@test lgamma(1.4+3.7im) -3.7094025330996841898 + 2.4568090502768651184im
577577
@test lgamma(1.4+3.7im) log(gamma(1.4+3.7im))
578578
@test lgamma(-4.2+0im) lgamma(-4.2)-5pi*im
579-
@test factorial(3.0) == gamma(4.0) == factorial(3)
579+
@test SpecialFunctions.factorial(3.0) == gamma(4.0) == factorial(3)
580580
for x in (3.2, 2+1im, 3//2, 3.2+0.1im)
581-
@test factorial(x) == gamma(1+x)
581+
@test SpecialFunctions.factorial(x) == gamma(1+x)
582582
end
583583
@test lfactorial(0) == lfactorial(1) == 0
584584
@test lfactorial(2) == lgamma(3)

0 commit comments

Comments
 (0)