Skip to content

Commit 12eec81

Browse files
authored
Add cispi(x) (#732)
Added to Base in JuliaLang/julia#38449 I added tests that cover both methods in Base: ```julia julia> methods(cispi) [1] cispi(theta::Real) in Base at complex.jl:544 [2] cispi(z::Complex) in Base at complex.jl:563 ``` (both of the doc tests and then a couple more examples of real inputs).
1 parent c93f3dc commit 12eec81

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Compat"
22
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
3-
version = "3.24.0"
3+
version = "3.25.0"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ without incrementing the major version of Compat.jl if necessary to match
5454
changes in `julia`.
5555

5656
## Supported features
57+
58+
* `cispi(x)` for accurately calculating `cis(pi * x)` ([#38449]) (since Compat 3.25)
59+
5760
* `startswith(s, r::Regex)` and `endswith(s, r::Regex)` ([#29790]) (since Compat 3.24)
5861

5962
* `sincospi(x)` for calculating the tuple `(sinpi(x), cospi(x))` ([#35816]) (since Compat 3.23)
@@ -232,3 +235,4 @@ Note that you should specify the correct minimum version for `Compat` in the
232235
[#37391]: https://github.com/JuliaLang/julia/pull/37391
233236
[#35816]: https://github.com/JuliaLang/julia/pull/35816
234237
[#29790]: https://github.com/JuliaLang/julia/pull/29790
238+
[#38449]: https://github.com/JuliaLang/julia/pull/38449

src/Compat.jl

+10
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,16 @@ if VERSION < v"1.6.0-DEV.292" # 6cd329c371c1db3d9876bc337e82e274e50420e8
820820
sincospi(x) = (sinpi(x), cospi(x))
821821
end
822822

823+
# https://github.com/JuliaLang/julia/pull/38449
824+
if VERSION < v"1.6.0-DEV.1591" # 96d59f957e4c0413e2876592072c0f08a7482cf2
825+
export cispi
826+
cispi(theta::Real) = Complex(reverse(sincospi(theta))...)
827+
function cispi(z::Complex)
828+
sipi, copi = sincospi(z)
829+
return complex(real(copi) - imag(sipi), imag(copi) + real(sipi))
830+
end
831+
end
832+
823833
# https://github.com/JuliaLang/julia/pull/29790
824834
if VERSION < v"1.2.0-DEV.246"
825835
using Base.PCRE

test/runtests.jl

+8
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,14 @@ end
774774
@test sincospi(0.13im) == (sinpi(0.13im), cospi(0.13im))
775775
end
776776

777+
# https://github.com/JuliaLang/julia/pull/38449
778+
@testset "cispi(x)" begin
779+
@test cispi(true) == -1 + 0im
780+
@test cispi(1) == -1.0 + 0.0im
781+
@test cispi(2.0) == 1.0 + 0.0im
782+
@test cispi(0.25 + 1im) cis/4 + π*im)
783+
end
784+
777785
include("iterators.jl")
778786

779787
# Import renaming, https://github.com/JuliaLang/julia/pull/37396,

0 commit comments

Comments
 (0)