Skip to content

Commit

Permalink
test value that might overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Expander committed Oct 6, 2023
1 parent 8697110 commit 92a5771
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/Li2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ li2(z::Real) = li2(Complex(z))
_li2(z::ComplexF16) = oftype(z, _li2(ComplexF32(z)))

function _li2(z::Complex{T})::Complex{T} where T
clog(z) = T == Float64 ? complex(0.5*log(abs2(z)), angle(z)) : complex(log(abs(z)), angle(z))

rz, iz = reim(z)

if iszero(iz)
Expand Down
2 changes: 1 addition & 1 deletion src/Log.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# handles case when imag(z) == -0.0
function clog(z::Complex)
ang = angle(z)
Complex(one(typeof(real(z)))/2*log(abs2(z)), imag(z) == zero(z.re) && ang < zero(z.re) ? -ang : ang)
Complex(log(abs(z)), iszero(imag(z)) && ang < zero(z.re) ? -ang : ang)
end

# returns logarithm of x
Expand Down
3 changes: 3 additions & 0 deletions test/Li2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@

@test real(PolyLog.li2(-1.08371e-08 + 1.32716e-24*im)) == -1.0837099970639316e-08
@test imag(PolyLog.li2(-1.08371e-08 + 1.32716e-24*im)) == 1.3271599928087172e-24

# test value that causes overflow if squared
@test real(PolyLog.li2(1e300 + 1im)) real(-238582.12510339421 - 2170.13532372464im) rtol=eps(Float64)
end

0 comments on commit 92a5771

Please sign in to comment.