SpecialFunctions.jl icon indicating copy to clipboard operation
SpecialFunctions.jl copied to clipboard

Add logabsgamma(::Complex)

Open dlfivefifty opened this issue 2 years ago • 3 comments

This was a bit surprising:

julia> logabsgamma(1+im)
ERROR: MethodError: no method matching logabsgamma(::Complex{Int64})
Closest candidates are:
  logabsgamma(::Real) at ~/.julia/packages/SpecialFunctions/gXPNz/src/gamma.jl:599
Stacktrace:
 [1] top-level scope
   @ REPL[1]:1

dlfivefifty avatar Mar 24 '23 20:03 dlfivefifty

Could be added temporarily as a fallback through the real part of loggamma

julia> log(gamma(1+im))
-0.650923199301859 - 0.3016403204675329im

julia> log(abs(gamma(1+im)))
-0.650923199301859

julia> loggamma(1+im)
-0.6509231993018592 - 0.30164032046753286im

julia> real(loggamma(1+im))
-0.6509231993018592

MikaelSlevinsky avatar Mar 29 '23 20:03 MikaelSlevinsky

Oh and it would need sign(gamma(z))

MikaelSlevinsky avatar Mar 29 '23 20:03 MikaelSlevinsky

Basically the fallback is

function logabsgamma(z::Complex)
    g = loggamma(z)
    real(g), cis(imag(g))
end

MikaelSlevinsky avatar Mar 29 '23 21:03 MikaelSlevinsky