Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix alignment in complex numbers with exponents #22223

Merged
merged 3 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,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 @@ -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([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent line continuations, would look clearer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is also a continuation after the ==

"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