Skip to content

Commit

Permalink
tighten promotion rule for Irrational and non-Real numbers (#26325)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored and JeffBezanson committed Mar 6, 2018
1 parent 60f2f77 commit 2f826b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2544,6 +2544,13 @@ end
end
end

# issue #26324
@testset "irrational promotion" begin
@test π*ComplexF32(2) isa ComplexF32
@test π/ComplexF32(2) isa ComplexF32
@test log(π,ComplexF32(2)) isa ComplexF32
end

@testset "printing non finite floats" begin
let float_types = Set()
allsubtypes!(Base, AbstractFloat, float_types)
Expand Down

0 comments on commit 2f826b5

Please sign in to comment.