Skip to content

Commit 0ab0915

Browse files
authored
Allow calling stirlings1 and stirlings2 with Integer arguments (#193)
* Allow calling `stirlings1` and `stirlings2` with `Integer` arguments This allows to call them with `BigInt` arguments to avoid overflow. Closes #104. * Add tests for `stirlings1` and `stirlings2` with large arguments
1 parent e005ee0 commit 0ab0915

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/numbers.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ function lucasnum(n::Integer)
125125
return z[]
126126
end
127127

128-
function stirlings1(n::Int, k::Int, signed::Bool=false)
128+
"""
129+
stirlings1(n::Integer, k::Integer)
130+
131+
Compute the Stirling number of the first kind, `s(n,k)`.
132+
"""
133+
function stirlings1(n::Integer, k::Integer, signed::Bool=false)
129134
if signed == true
130135
return (-1)^(n - k) * stirlings1(n, k)
131136
end
@@ -152,11 +157,11 @@ function stirlings1(n::Int, k::Int, signed::Bool=false)
152157
end
153158

154159
"""
155-
stirlings2(n::Int, k::Int)
160+
stirlings2(n::Integer, k::Integer)
156161
157162
Compute the Stirling number of the second kind, `S(n,k)`.
158163
"""
159-
function stirlings2(n::Int, k::Int)
164+
function stirlings2(n::Integer, k::Integer)
160165
if n < 0
161166
throw(DomainError(n, "n must be nonnegative"))
162167
elseif n == k == 0

test/numbers.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
@test stirlings1(6, 6) == 1
5252
@test stirlings1(6, 6, true) == 1
5353
@test sum([abs(stirlings1(8, i, true)) for i = 0:8]) == factorial(8)
54+
@test stirlings1(big"26", 10) == 196928100451110820242880
5455

5556
# stirlings2
5657
@test_throws DomainError stirlings2(-1, 1)
@@ -65,6 +66,7 @@
6566
@test stirlings2(6, 4) == 65
6667
@test stirlings2(6, 5) == 15
6768
@test stirlings2(6, 6) == 1
69+
@test stirlings2(big"26", 10) == 13199555372846848005
6870

6971
# bell
7072
@test bellnum.(0:10) == [

0 commit comments

Comments
 (0)