Skip to content

Commit a4f54e8

Browse files
giordanotkelman
authored andcommitted
Fix complex exp2 and exp10 with boolean and irrational argument (#21874)
Fix #21200. (cherry picked from commit 03639b9)
1 parent da81858 commit a4f54e8

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

base/complex.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,17 +594,19 @@ function ^(z::Complex{T}, p::Complex{T})::Complex{T} where T<:AbstractFloat
594594
end
595595
end
596596

597-
function exp2(z::Complex{T}) where T
597+
function exp2(z::Complex{T}) where T<:AbstractFloat
598598
er = exp2(real(z))
599599
theta = imag(z) * log(convert(T, 2))
600600
Complex(er*cos(theta), er*sin(theta))
601601
end
602+
exp2(z::Complex) = exp2(float(z))
602603

603-
function exp10(z::Complex{T}) where T
604+
function exp10(z::Complex{T}) where T<:AbstractFloat
604605
er = exp10(real(z))
605606
theta = imag(z) * log(convert(T, 10))
606607
Complex(er*cos(theta), er*sin(theta))
607608
end
609+
exp10(z::Complex) = exp10(float(z))
608610

609611
function ^(z::T, p::T) where T<:Complex
610612
if isinteger(p)

test/complex.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,13 +883,15 @@ end
883883
@test exp2(1.0+0.0im) == 2.0+0.0im
884884
#wolframalpha
885885
@test exp2(1.0+3.0im) -0.9739888359315627962096198412+1.74681016354974281701922im
886+
@test exp2(im) 0.7692389013639721 + 0.6389612763136348im
886887
end
887888

888889
@testset "exp10" begin
889890
@test exp10(0.0+0.0im) == 1.0+0.0im
890891
@test exp10(1.0+0.0im) == 10.0+0.0im
891892
#wolframalpha
892893
@test exp10(1.0+2.0im) -1.0701348355877020772086517528518239460495529361-9.9425756941378968736161937190915602112878340717im
894+
@test exp10(im) -0.6682015101903132 + 0.7439803369574931im
893895
end
894896

895897
@testset "round and float, PR #8291" begin
@@ -946,8 +948,11 @@ end
946948

947949
@testset "Complex Irrationals, issue #21204" begin
948950
for x in (pi, e, catalan) # No need to test all of them
949-
@test typeof(Complex(x, x)) == Complex{typeof(x)}
950-
@test exp(complex(x, x)) exp(x) * cis(x)
951+
z = Complex(x, x)
952+
@test typeof(z) == Complex{typeof(x)}
953+
@test exp(z) exp(x) * cis(x)
954+
@test exp2(z) exp(z * log(2))
955+
@test exp10(z) exp(z * log(10))
951956
end
952957
end
953958

0 commit comments

Comments
 (0)