diff --git a/src/Li2.jl b/src/Li2.jl index bba31b6..908e553 100644 --- a/src/Li2.jl +++ b/src/Li2.jl @@ -237,7 +237,8 @@ li2(z::Real) = li2(Complex(z)) _li2(z::ComplexF16) = oftype(z, _li2(ComplexF32(z))) -function _li2(z::Complex{T})::Complex{T} where T +# overload for complex types for which li2_approx uses pre-computed Bernoulli numbers +function _li2(z::Complex{T})::Complex{T} where {T<:Union{Float32, Float64}} rz, iz = reim(z) if iszero(iz) @@ -270,7 +271,8 @@ function _li2(z::Complex{T})::Complex{T} where T end end -function _li2(z::Complex{BigFloat})::Complex{BigFloat} +# overload for generic complex types +function _li2(z::Complex{T})::Complex{T} where T rz, iz = reim(z) if iszero(iz) diff --git a/test/Dual.jl b/test/Dual.jl new file mode 100644 index 0000000..ab24ee4 --- /dev/null +++ b/test/Dual.jl @@ -0,0 +1,13 @@ +if isdefined(Base, :get_extension) + import ForwardDiff + + to_dual(z::Complex) = Complex(ForwardDiff.Dual(real(z)), ForwardDiff.Dual(imag(z))) + + @testset "Dual" begin + z = 0.5 + 0.8im + + for n in -10:10 + @test PolyLog.li(n, to_dual(z)) ≈ PolyLog.li(n, z) rtol=1e-14 + end + end +end diff --git a/test/runtests.jl b/test/runtests.jl index 3740ffd..b9d414f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,6 +9,7 @@ include("TestPrecision.jl") include("DataReader.jl") include("DataTester.jl") include("Digamma.jl") +include("Dual.jl") include("Eta.jl") include("Factorial.jl") include("Harmonic.jl")