Skip to content

Commit

Permalink
Merge pull request #11490 from stevengj/bigcomplex
Browse files Browse the repository at this point in the history
re-add big(z::Complex) method
  • Loading branch information
tkelman committed Jun 1, 2015
2 parents 8d9f06c + 0dd5669 commit d20debf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ float{T<:FloatingPoint}(z::Complex{T}) = z
float(z::Complex) = Complex(float(real(z)), float(imag(z)))
@vectorize_1arg Complex float

big{T<:FloatingPoint}(z::Complex{T}) = Complex{BigFloat}(z)
big{T<:Integer}(z::Complex{T}) = Complex{BigInt}(z)

## Array operations on complex numbers ##

complex{T<:Complex}(x::AbstractArray{T}) = x
Expand All @@ -737,6 +740,7 @@ function complex(A::AbstractArray)
map_promote(cnv, A)
end

big{T<:Integer,N}(x::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigInt},N}, x)
big{T<:FloatingPoint,N}(x::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, x)

## promotion to complex ##
Expand Down
3 changes: 3 additions & 0 deletions base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ end
convert(::Type{Rational}, x::Float64) = convert(Rational{Int64}, x)
convert(::Type{Rational}, x::Float32) = convert(Rational{Int}, x)

big{T<:Integer}(z::Complex{Rational{T}}) = Complex{Rational{BigInt}}(z)
big{T<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) = convert(AbstractArray{Complex{Rational{BigInt}},N}, x)

promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{S}) = Rational{promote_type(T,S)}
promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{Rational{S}}) = Rational{promote_type(T,S)}
promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Rational{T}}, ::Type{S}) = promote_type(T,S)
Expand Down
7 changes: 7 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2481,3 +2481,10 @@ for T in (Int8,Int16,Int32,Int64,Int128,UInt8,UInt16,UInt32,UInt64,UInt128)
@test_throws InexactError T(big(typemax(T))+1)
@test_throws InexactError T(big(typemin(T))-1)
end

for (d,B) in ((4//2+1im,Rational{BigInt}),(3.0+1im,BigFloat),(2+1im,BigInt))
@test typeof(big(d)) == Complex{B}
@test big(d) == d
@test typeof(big([d])) == Vector{Complex{B}}
@test big([d]) == [d]
end

0 comments on commit d20debf

Please sign in to comment.