Skip to content

Commit

Permalink
re-add big(z::Complex) method (inadvertently deleted in JuliaLang#8253?…
Browse files Browse the repository at this point in the history
…) and related methods
  • Loading branch information
stevengj committed May 29, 2015
1 parent 6b4c275 commit d6809c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,10 @@ 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{Rational{T}}) = Complex{Rational{BigInt}}(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 +741,8 @@ 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<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) = convert(AbstractArray{Complex{Rational{BigInt}},N}, x)
big{T<:FloatingPoint,N}(x::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, x)

## promotion to complex ##
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 d6809c3

Please sign in to comment.