Skip to content

Commit

Permalink
fix alignment in complex numbers with exponents (#22223)
Browse files Browse the repository at this point in the history
* fix alignment in complex numbers with exponents

* indent

* indent v2

(cherry picked from commit 1e9fb81)
  • Loading branch information
KristofferC authored and tkelman committed Jun 17, 2017
1 parent 06dd3e0 commit e11880e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,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
Expand Down
11 changes: 11 additions & 0 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -962,3 +962,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

0 comments on commit e11880e

Please sign in to comment.