From 88821a2e13d70b88d4a0630045b5de071f4a76cd Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Mon, 5 Mar 2018 10:54:31 -0500 Subject: [PATCH 1/2] tighten promotion rule for Irrational and non-Real numbers --- base/irrationals.jl | 3 ++- test/numbers.jl | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/base/irrationals.jl b/base/irrationals.jl index 2d9795b438b6b..986bd9e575344 100644 --- a/base/irrationals.jl +++ b/base/irrationals.jl @@ -22,7 +22,8 @@ show(io::IO, x::Irrational{sym}) where {sym} = print(io, "$sym = $(string(float( promote_rule(::Type{<:AbstractIrrational}, ::Type{Float16}) = Float16 promote_rule(::Type{<:AbstractIrrational}, ::Type{Float32}) = Float32 promote_rule(::Type{<:AbstractIrrational}, ::Type{<:AbstractIrrational}) = Float64 -promote_rule(::Type{<:AbstractIrrational}, ::Type{T}) where {T<:Number} = promote_type(Float64, T) +promote_rule(::Type{<:AbstractIrrational}, ::Type{T}) where {T<:Real} = promote_type(Float64, T) +promote_rule(::Type{S}, ::Type{T}) where {S<:AbstractIrrational,T<:Number} = promote_type(promote_type(S, real(T)), T) AbstractFloat(x::AbstractIrrational) = Float64(x) Float16(x::AbstractIrrational) = Float16(Float32(x)) diff --git a/test/numbers.jl b/test/numbers.jl index fbff83d03c501..be459ed998148 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2544,6 +2544,13 @@ end end end +# issue #26324 +@testset "irrational promotion" begin + @test π*ComplexF32(2) isa ComplexF32 + @test π/ComplexF32(2) isa ComplexF32 + @test atan2(π,ComplexF32(2)) isa ComplexF32 +end + @testset "printing non finite floats" begin let float_types = Set() allsubtypes!(Base, AbstractFloat, float_types) From e96186c7912dbcfe4716e3921cef68d9bcd2f66f Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Mon, 5 Mar 2018 10:57:57 -0500 Subject: [PATCH 2/2] use log instead of atan2 test case (no complex-arg version of atan2) --- test/numbers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/numbers.jl b/test/numbers.jl index be459ed998148..76fdb399b756d 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2548,7 +2548,7 @@ end @testset "irrational promotion" begin @test π*ComplexF32(2) isa ComplexF32 @test π/ComplexF32(2) isa ComplexF32 - @test atan2(π,ComplexF32(2)) isa ComplexF32 + @test log(π,ComplexF32(2)) isa ComplexF32 end @testset "printing non finite floats" begin