Skip to content

Commit

Permalink
Merge pull request #13445 from JuliaLang/jrg/complextype
Browse files Browse the repository at this point in the history
Implement complex(::Type)
  • Loading branch information
garrison committed Oct 26, 2015
2 parents df6105d + b3a2e82 commit d0b97f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/complex.jl
Expand Up @@ -37,6 +37,9 @@ reim(z) = (real(z), imag(z))
real{T<:Real}(::Type{T}) = T
real{T<:Real}(::Type{Complex{T}}) = T

complex{T<:Real}(::Type{T}) = Complex{T}
complex{T<:Real}(::Type{Complex{T}}) = Complex{T}

isreal(x::Real) = true
isreal(z::Complex) = imag(z) == 0
isimag(z::Number) = real(z) == 0
Expand Down
7 changes: 7 additions & 0 deletions test/complex.jl
Expand Up @@ -2,6 +2,13 @@

@test reim(2 + 3im) == (2, 3)

for T in (Int64, Float64)
@test real(T) == T
@test real(Complex{T}) == T
@test complex(T) == Complex{T}
@test complex(Complex{T}) == Complex{T}
end

# Basic arithmetic
for T in (Float16, Float32, Float64, BigFloat)
t = true
Expand Down

0 comments on commit d0b97f3

Please sign in to comment.