Skip to content

Commit

Permalink
Improve performance of complex logarithm (#26)
Browse files Browse the repository at this point in the history
by using real functions when possible

---------

Co-authored-by: Alexander Voigt <[email protected]>
  • Loading branch information
Expander and Expander authored Feb 21, 2024
1 parent ab3a8b0 commit fad19d6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Log.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ end
# returns complex logarithm of z;
# handles case when imag(z) == -0.0
function clog(z::Complex)
log(convert_minus_0(z))
if iszero(imag(z)) && real(z) > zero(real(z))
Complex(log(real(z)), zero(real(z)))
elseif iszero(imag(z))
Complex(log(real(-z)), convert(typeof(real(z)),pi))
else
log(z)
end
end

# returns logarithm of x
Expand All @@ -20,7 +26,11 @@ end
# returns complex logarithm of 1+z;
# handles case when imag(z) == -0.0
function clog1p(z::Complex)
log1p(convert_minus_0(z))
if iszero(imag(z)) && real(z) > -one(real(z))
Complex(log1p(real(z)), zero(real(z)))
else
log1p(convert_minus_0(z))
end
end

# returns |ln(x)|^2 for all x
Expand Down

0 comments on commit fad19d6

Please sign in to comment.