Skip to content

Commit

Permalink
Better precision for cispi(::Complex) (JuliaLang#45945)
Browse files Browse the repository at this point in the history
* Better precision for cispi(::Complex)
* Fix bug, add test
* Update doctest
  • Loading branch information
antoine-levitt authored and pcjentsch committed Aug 18, 2022
1 parent 15e0152 commit 728c3a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ julia> cispi(10000)
1.0 + 0.0im
julia> cispi(0.25 + 1im)
0.030556854645952924 + 0.030556854645952924im
0.030556854645954562 + 0.030556854645954562im
```
!!! compat "Julia 1.6"
Expand All @@ -601,8 +601,9 @@ function cispi end
cispi(theta::Real) = Complex(reverse(sincospi(theta))...)

function cispi(z::Complex)
sipi, copi = sincospi(z)
return complex(real(copi) - imag(sipi), imag(copi) + real(sipi))
v = exp(-(pi*imag(z)))
s, c = sincospi(real(z))
Complex(v * c, v * s)
end

"""
Expand Down
1 change: 1 addition & 0 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ end
@test cispi(0.0+0.0im) == cispi(0)
@test cispi(1.0+0.0im) == cispi(1)
@test cispi(2.0+0.0im) == cispi(2)
@test cispi(5im) exp(-5pi) rtol=1e-10 # https://github.com/JuliaLang/julia/pull/45945
end

@testset "exp2" begin
Expand Down

0 comments on commit 728c3a1

Please sign in to comment.