Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaN in digamma caused by _cotpi #480

Open
Youjack opened this issue Nov 9, 2024 · 2 comments
Open

NaN in digamma caused by _cotpi #480

Youjack opened this issue Nov 9, 2024 · 2 comments

Comments

@Youjack
Copy link

Youjack commented Nov 9, 2024

The definition of _digamma(z::ComplexOrReal{Float64}) contains the formula

ψ = -π * _cotpi(z)

in which _cotpi is defined as
_cotpi(x) = @static VERSION >= v"1.10.0-DEV.525" ? inv(tanpi(x)) : cospi(x) / sinpi(x)

For large complex arguments, _cotpi produces NaN since cospi and sinpi produce Inf. For example,

julia> cospi(500 * exp(im * 3pi/4))
Inf - Inf*im

julia> sinpi(500 * exp(im * 3pi/4))
Inf + Inf*im

julia> cospi(500 * exp(im * 3pi/4)) / sinpi(500 * exp(im * 3pi/4))
NaN + NaN*im

Nevertheless, the ordinary cot gives the correct answer

julia> cot(pi * 500 * exp(im * 3pi/4))
0.0 - 1.0im

A way to avoid NaN is to define cotpi as in mpmath
https://github.com/mpmath/mpmath/blob/b600dbcabf4b7406a61e82b9e607f754a9f12ff9/mpmath/libfp.py#L153-L161

@stevengj
Copy link
Member

stevengj commented Nov 9, 2024

Wouldn't it be better to fix tanpi in base?

@Youjack
Copy link
Author

Youjack commented Nov 11, 2024

I have added a comment under a tanpi issue in the Julia repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants