From ecdbd8692799a8c958ac9e011f35cbafda1d0f93 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Wed, 30 Sep 2026 14:55:09 +0200 Subject: [PATCH] fix type stability of li1 --- src/Log.jl | 4 ++-- test/TypeStability.jl | 34 ++++++++++++++++++++++++++++++++++ test/runtests.jl | 1 + 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/TypeStability.jl diff --git a/src/Log.jl b/src/Log.jl index a3f1367..9e8a4a7 100644 --- a/src/Log.jl +++ b/src/Log.jl @@ -1,8 +1,8 @@ # converts -0.0 to 0.0 function convert_minus_0(z) Complex( - real(z) == -0.0 ? 0.0 : real(z), - imag(z) == -0.0 ? 0.0 : imag(z) + real(z) == -0.0 ? zero(real(z)) : real(z), + imag(z) == -0.0 ? zero(imag(z)) : imag(z) ) end diff --git a/test/TypeStability.jl b/test/TypeStability.jl new file mode 100644 index 0000000..352bddf --- /dev/null +++ b/test/TypeStability.jl @@ -0,0 +1,34 @@ +@testset "TypeStability ($T)" for T in (Float16, Float32, Float64, BigFloat) + @test @inferred(PolyLog.li0(T(1))) isa T + @test @inferred(PolyLog.li0(Complex{T}(1))) isa Complex{T} + + @test @inferred(PolyLog.li1(T(1))) isa Complex{T} + @test @inferred(PolyLog.li1(Complex{T}(1))) isa Complex{T} + @test @inferred(PolyLog.reli1(T(1))) isa T + + @test @inferred(PolyLog.li2(T(1))) isa Complex{T} + @test @inferred(PolyLog.li2(Complex{T}(1))) isa Complex{T} + @test @inferred(PolyLog.reli2(T(1))) isa T + + if T != BigFloat + @test @inferred(PolyLog.li3(T(1))) isa Complex{T} + @test @inferred(PolyLog.li3(Complex{T}(1))) isa Complex{T} + @test @inferred(PolyLog.reli3(T(1))) isa T + + @test @inferred(PolyLog.li4(T(1))) isa Complex{T} + @test @inferred(PolyLog.li4(Complex{T}(1))) isa Complex{T} + @test @inferred(PolyLog.reli4(T(1))) isa T + + @test @inferred(PolyLog.li5(T(1))) isa Complex{T} + @test @inferred(PolyLog.li5(Complex{T}(1))) isa Complex{T} + + @test @inferred(PolyLog.li6(T(1))) isa Complex{T} + @test @inferred(PolyLog.li6(Complex{T}(1))) isa Complex{T} + end + + for n in -10:10 + @test @inferred(PolyLog.li(n,T(1))) isa Complex{T} + @test @inferred(PolyLog.li(n,Complex{T}(1))) isa Complex{T} + @test @inferred(PolyLog.reli(n,T(1))) isa T + end +end diff --git a/test/runtests.jl b/test/runtests.jl index 65a1de8..6239000 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -20,4 +20,5 @@ include("Li6.jl") include("Li.jl") include("Log.jl") include("Missing.jl") +include("TypeStability.jl") include("Zeta.jl")