Skip to content

Commit ace5c8b

Browse files
authored
Fix /(::Real,::Complex) (#19279)
Fixes issue #19240.
1 parent 80770e9 commit ace5c8b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

base/complex.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ muladd(z::Complex, w::Complex, x::Real) =
236236
Complex(muladd(real(z), real(w), x) - imag(z)*imag(w), # TODO: use mulsub given #15985
237237
muladd(real(z), imag(w), imag(z) * real(w)))
238238

239-
/(a::Real, z::Complex) = a*inv(z)
239+
/{R<:Real,S<:Complex}(a::R, z::S) = (T = promote_type(R,S); a*inv(T(z)))
240240
/(z::Complex, x::Real) = Complex(real(z)/x, imag(z)/x)
241241

242242
function /{T<:Real}(a::Complex{T}, b::Complex{T})

test/complex.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ end
5555
@test isequal(im * T(+1.0), Complex(T(+0.0), T(+1.0)))
5656
@test isequal(im * T(-1.0), Complex(T(-0.0), T(-1.0)))
5757
end
58+
59+
@testset "divide" begin
60+
@test isequal(T(+0.0) / im, Complex(T(+0.0), T(-0.0)))
61+
@test isequal(T(-0.0) / im, Complex(T(-0.0), T(+0.0)))
62+
@test isequal(T(+1.0) / im, Complex(T(+0.0), T(-1.0)))
63+
@test isequal(T(-1.0) / im, Complex(T(-0.0), T(+1.0)))
64+
end
5865
end
5966
@test isequal(true + complex(true,false), complex(true,false) + complex(true,false))
6067
@test isequal(complex(true,false) + true, complex(true,false) + complex(true,false))
@@ -925,7 +932,7 @@ end
925932
@test Float16(1)+Float16(1)im === Complex32(1, 1)
926933
@test Float16(1)-Float16(1)im === Float16(1)+Float16(-1)im === Complex32(1, -1)
927934
@test Float16(1)*im === Complex32(im)
928-
@test Float16(1)/im === 1.0f0/im === Complex(0.0, -1.0)
935+
@test Float16(1)/im === Complex32(0,-1)
929936
@test Float16(1)^im === Complex32(1) === Float16(1)+Float16(0)im
930937
end
931938

@@ -959,3 +966,6 @@ end
959966
@inferred expm1(x)
960967
end
961968
end
969+
970+
# issue #19240
971+
@test big(1)/(10+10im) (5-5im)/big(100) big"0.05" - big"0.05"*im

0 commit comments

Comments
 (0)