diff --git a/base/show.jl b/base/show.jl index 301fa3c9171a9..b7b1a77032257 100644 --- a/base/show.jl +++ b/base/show.jl @@ -1363,7 +1363,7 @@ function alignment(io::IO, x::Real) end "`alignment(1 + 10im)` yields (3,5) for `1 +` and `_10im` (plus sign on left, space on right)" function alignment(io::IO, x::Complex) - m = match(r"^(.*[\+\-])(.*)$", sprint(0, show, x, env=io)) + m = match(r"^(.*[^e][\+\-])(.*)$", sprint(0, show, x, env=io)) m === nothing ? (length(sprint(0, show, x, env=io)), 0) : (length(m.captures[1]), length(m.captures[2])) end diff --git a/test/complex.jl b/test/complex.jl index 161222835a686..40171cd00a602 100644 --- a/test/complex.jl +++ b/test/complex.jl @@ -963,3 +963,14 @@ end x = @inferred expm1(0.1f0im) @test x isa Complex64 end + +@testset "array printing with exponent format" begin + a = [1.0 + 1e-10im, 2.0e-15 - 2.0e-5im, 1.0e-15 + 2im, 1.0 + 2e-15im] + @test sprint((io, x) -> show(io, MIME("text/plain"), x), a) == + join([ + "4-element Array{Complex{Float64},1}:", + " 1.0+1.0e-10im", + " 2.0e-15-2.0e-5im ", + " 1.0e-15+2.0im ", + " 1.0+2.0e-15im"], "\n") +end