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
15 changes: 12 additions & 3 deletions src/Li.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function li_series_unity_pos(n::Integer, z::ComplexOrReal{T}) where T

l2 = l*l

for j in (n + 3):2:typemax(promote_type(typeof(n), Int64))
for j in (n + 3):2:max_n(typeof(n))
p *= l2/((j - 1)*j)
old_sum = sum
sum += zeta(n - j, T)*p
Expand Down Expand Up @@ -279,7 +279,7 @@ function li_series_unity_neg(n::Integer, z::Complex{T})::Complex{T} where T
sum += zeta(n, T)
end

for k in kmin:2:typemax(promote_type(typeof(n), Int64))
for k in kmin:2:max_n(typeof(n))
term = zeta(n - k, T)*inv_fac(k, T)*lk
!isfinite(term) && break
sum_old = sum
Expand All @@ -299,7 +299,7 @@ function li_series_taylor(n::Integer, z::ComplexOrReal)
sum = z
zn = z*z

for k in 2:typemax(promote_type(typeof(n), Int64))
for k in 2:max_n(typeof(n))
term = zn/oftype(real(z), k)^n
!isfinite(term) && break
old_sum = sum
Expand All @@ -310,3 +310,12 @@ function li_series_taylor(n::Integer, z::ComplexOrReal)

sum
end

# returns upper bound on iteration index
function max_n(::Type{T}) where T
if T in (Int8, Int16, Int32, Int64, Int128)
typemax(promote_type(T, Int64))
else
typemax(Int64)
end
end
2 changes: 2 additions & 0 deletions test/Li.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ end
(n > typemax(TN) || n < typemin(TN)) && continue
test_function_on_data(z -> PolyLog.reli(TN(n), z), map(T, real_data), ep, ep)
end
test_function_on_data(z -> PolyLog.reli(big(n), z), map(T, real_data), ep, ep)
end
end

Expand All @@ -52,6 +53,7 @@ end
(n > typemax(TN) || n < typemin(TN)) && continue
test_function_on_data(z -> PolyLog.li(TN(n), z), map(Complex{T}, complex_data), ep, ep)
end
test_function_on_data(z -> PolyLog.li(big(n), z), map(Complex{T}, complex_data), ep, ep)
end
end

Expand Down
Loading