Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeof(π/Complex64(2)) == Complex128 #26324

Closed
ettersi opened this issue Mar 5, 2018 · 1 comment
Closed

typeof(π/Complex64(2)) == Complex128 #26324

ettersi opened this issue Mar 5, 2018 · 1 comment
Labels
complex Complex numbers

Comments

@ettersi
Copy link
Contributor

ettersi commented Mar 5, 2018

We currently have

julia> typeof(π/Complex64(2))
Complex{Float64}

This looks like a bug to me. Compare with

julia> typeof(π*Complex64(2))
Complex{Float32}

julia> typeof(π/Float32(2))
Float32
@stevengj stevengj changed the title typeof(\pi/Complex64(2,0)) == Complex128 typeof(π/Complex64(2)) == Complex128 Mar 5, 2018
@stevengj
Copy link
Member

stevengj commented Mar 5, 2018

It's due to this promotion rule.

We could add a promotion rule for Complex, or we could add a more generic rule. Something like:

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)

so that non-Real number types use real to promote based on the real part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complex Complex numbers
Projects
None yet
Development

No branches or pull requests

2 participants