From 42d5d932b4c83beeadc2a7325d6229a8eddc0444 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Sun, 22 Mar 2026 12:27:36 +0100 Subject: [PATCH 1/5] adding failing test, see issue #40 --- test/Dual.jl | 14 ++++++++++++++ test/runtests.jl | 1 + 2 files changed, 15 insertions(+) create mode 100644 test/Dual.jl diff --git a/test/Dual.jl b/test/Dual.jl new file mode 100644 index 0000000..5805226 --- /dev/null +++ b/test/Dual.jl @@ -0,0 +1,14 @@ +if isdefined(Base, :get_extension) + import ForwardDiff + + function li_dual(n::Integer, z::Complex) + z_dual = complex(ForwardDiff.Dual(real(z)), ForwardDiff.Dual(imag(z))) + PolyLog.li(n, z_dual) + end + + + @testset "Dual" begin + z = 0.5 + 0.8im + @test li_dual(2, z) == PolyLog.li(2, z) + 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") From bb9df0460b155990c5edb15aa748e9f51134b391 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Sun, 22 Mar 2026 13:10:03 +0100 Subject: [PATCH 2/5] test for approximate equality --- test/Dual.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Dual.jl b/test/Dual.jl index 5805226..f7a92c2 100644 --- a/test/Dual.jl +++ b/test/Dual.jl @@ -9,6 +9,6 @@ if isdefined(Base, :get_extension) @testset "Dual" begin z = 0.5 + 0.8im - @test li_dual(2, z) == PolyLog.li(2, z) + @test li_dual(2, z) ≈ PolyLog.li(2, z) rtol=1e-15 end end From 4d82c05b5da27350b3f6b0c078b2a5c70199e55d Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Sun, 22 Mar 2026 13:10:17 +0100 Subject: [PATCH 3/5] match complex types for _li2 and li2_approx --- src/Li2.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Li2.jl b/src/Li2.jl index bba31b6..9c3a3e9 100644 --- a/src/Li2.jl +++ b/src/Li2.jl @@ -237,7 +237,7 @@ li2(z::Real) = li2(Complex(z)) _li2(z::ComplexF16) = oftype(z, _li2(ComplexF32(z))) -function _li2(z::Complex{T})::Complex{T} where T +function _li2(z::Complex{T})::Complex{T} where {T<:Union{Float32, Float64}} rz, iz = reim(z) if iszero(iz) @@ -270,7 +270,7 @@ function _li2(z::Complex{T})::Complex{T} where T end end -function _li2(z::Complex{BigFloat})::Complex{BigFloat} +function _li2(z::Complex{T})::Complex{T} where T rz, iz = reim(z) if iszero(iz) From 36e3203cf5173b04924835734f1d026e641d2f8c Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Sun, 22 Mar 2026 13:27:30 +0100 Subject: [PATCH 4/5] adding comments --- src/Li2.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Li2.jl b/src/Li2.jl index 9c3a3e9..908e553 100644 --- a/src/Li2.jl +++ b/src/Li2.jl @@ -237,6 +237,7 @@ li2(z::Real) = li2(Complex(z)) _li2(z::ComplexF16) = oftype(z, _li2(ComplexF32(z))) +# 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) @@ -270,6 +271,7 @@ function _li2(z::Complex{T})::Complex{T} where {T<:Union{Float32, Float64}} end end +# overload for generic complex types function _li2(z::Complex{T})::Complex{T} where T rz, iz = reim(z) From a12822f0e5300c35f4f951d91e77e905a5add2f1 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 23 Mar 2026 07:26:28 +0100 Subject: [PATCH 5/5] extend test to more orders --- test/Dual.jl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/Dual.jl b/test/Dual.jl index f7a92c2..ab24ee4 100644 --- a/test/Dual.jl +++ b/test/Dual.jl @@ -1,14 +1,13 @@ if isdefined(Base, :get_extension) import ForwardDiff - function li_dual(n::Integer, z::Complex) - z_dual = complex(ForwardDiff.Dual(real(z)), ForwardDiff.Dual(imag(z))) - PolyLog.li(n, z_dual) - end - + to_dual(z::Complex) = Complex(ForwardDiff.Dual(real(z)), ForwardDiff.Dual(imag(z))) @testset "Dual" begin z = 0.5 + 0.8im - @test li_dual(2, z) ≈ PolyLog.li(2, z) rtol=1e-15 + + for n in -10:10 + @test PolyLog.li(n, to_dual(z)) ≈ PolyLog.li(n, z) rtol=1e-14 + end end end