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

RFC: Implement complex(::Type) #13445

Merged
merged 1 commit into from Oct 26, 2015
Merged

RFC: Implement complex(::Type) #13445

merged 1 commit into from Oct 26, 2015

Conversation

garrison
Copy link
Sponsor Member

@garrison garrison commented Oct 4, 2015

Currently there is a method real(::Type) that converts a type to its "real" part:

julia> real(Float64)
Float64

julia> real(Complex128)
Float64

This pull request adds a similar method complex(::Type) that behaves as follows:

julia> complex(Float64)
Complex{Float64}

julia> complex(Complex128)
Complex{Float64}

This is much more clear than writing Complex{real(T)}, which was necessary to get this behavior before.

@garrison garrison added the domain:complex Complex numbers label Oct 4, 2015
@johnmyleswhite
Copy link
Member

This is very reasonable, but I worry that it puts us down the path of lowercase int and lowercase float again.

@ScottPJones
Copy link
Contributor

I don't think so (that these are like the lowercase constructors int and float),
these seem to me to be more like trait functions such as eltype.

@garrison
Copy link
Sponsor Member Author

I will plan to merge this in a few days unless anybody objects more strongly. I do think this is distinct from lowercase int and float.

@nalimilan
Copy link
Member

Why not add a method to the uppercase Complex constructor? AFAICT there should be no ambiguities.

@garrison
Copy link
Sponsor Member Author

This function mirrors lowercase real(::Type), so having it use uppercase Complex seems like a needless inconsistency to me.

@johnmyleswhite
Copy link
Member

Yes, the distinction is real and important. I was not thinking clearly when I made that comment earlier.

@andreasnoack
Copy link
Member

I'm using real(::Type{T}) all the time so I understand the usefulness of this PR. However, real predates the posibility of using constructors for abstract types so I'm wondering if we should start using Real, AbstractFloat etc. instead of the small letter versions. One problem is, that the float conversion actually represents an abstract type we don't have, i.e. Union{AbstractFloat,Complex{T<:AbstractFloat}}.

These changes can easily be made later though, so as long as we have real, I think is fine to have complex(::Type).

@nalimilan
Copy link
Member

My suggestion was actually similar to what @andreasnoack said (somewhat more convincingly). So +1 to that.

garrison added a commit that referenced this pull request Oct 26, 2015
@garrison garrison merged commit d0b97f3 into master Oct 26, 2015
@garrison garrison deleted the jrg/complextype branch October 26, 2015 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:complex Complex numbers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants