Skip to content

Commit

Permalink
catch case n <= 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Expander committed Sep 30, 2023
1 parent c5d6adf commit 9fda0d0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Harmonic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ function harmonic_f64(n::Integer)
end

function harmonic_big(n::Integer)
sum = one(BigFloat)
for k in 2:n
sum += inv(big(k))
if n <= 0
throw(DomainError(n, "harmonic not implemented for n <= 0"))
else
sum = one(BigFloat)
for k in 2:n
sum += inv(big(k))
end
sum
end
sum
end

0 comments on commit 9fda0d0

Please sign in to comment.