-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
Description
Current definition of tanpi produces NaN for large complex argument. For example,
julia> tanpi(500 * exp(im * 3pi/4))
NaN + NaN*im
The reason is that sinpi and cospi produce Inf with this argument,
julia> sinpi(500 * exp(im * 3pi/4))
Inf + Inf*im
julia> cospi(500 * exp(im * 3pi/4))
Inf - Inf*im
while tanpi is defined as
Line 943 in 0163991
| tanpi(x::Complex) = sinpi(x) / cospi(x) # Is there a better way to do this? |
This NaN causes NaN in some special functions. For example,
julia> using SpecialFunctions
julia> digamma(500 * exp(im * 3pi/4))
NaN + NaN*im
See the related issue in SpecialFunctions.jl repo for details.
Inspired by how cotpi is defined in mpmath:
https://github.com/mpmath/mpmath/blob/5e57cb8039a3a4c9f222901a5eb2e08c53b2b2f8/mpmath/libfp.py#L153-L161
I suggest defining tanpi as
tanpi(x::Complex) = imag(x) > 10 ? 1.0im : imag(x) < 10 ? -1.0im : sinpi(x) / cospi(x)
This issue is copied from #28943 (comment).