Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ function lucasnum(n::Integer)
return z[]
end

function stirlings1(n::Int, k::Int, signed::Bool=false)
"""
stirlings1(n::Integer, k::Integer)

Compute the Stirling number of the first kind, `s(n,k)`.
"""
function stirlings1(n::Integer, k::Integer, signed::Bool=false)
if signed == true
return (-1)^(n - k) * stirlings1(n, k)
end
Expand All @@ -152,11 +157,11 @@ function stirlings1(n::Int, k::Int, signed::Bool=false)
end

"""
stirlings2(n::Int, k::Int)
stirlings2(n::Integer, k::Integer)

Compute the Stirling number of the second kind, `S(n,k)`.
"""
function stirlings2(n::Int, k::Int)
function stirlings2(n::Integer, k::Integer)
if n < 0
throw(DomainError(n, "n must be nonnegative"))
elseif n == k == 0
Expand Down
2 changes: 2 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
@test stirlings1(6, 6) == 1
@test stirlings1(6, 6, true) == 1
@test sum([abs(stirlings1(8, i, true)) for i = 0:8]) == factorial(8)
@test stirlings1(big"26", 10) == 196928100451110820242880

# stirlings2
@test_throws DomainError stirlings2(-1, 1)
Expand All @@ -65,6 +66,7 @@
@test stirlings2(6, 4) == 65
@test stirlings2(6, 5) == 15
@test stirlings2(6, 6) == 1
@test stirlings2(big"26", 10) == 13199555372846848005

# bell
@test bellnum.(0:10) == [
Expand Down
Loading