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
  • Loading branch information
KristofferC authored Jun 7, 2017
1 parent 4e6ccf6 commit 1e9fb81
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 @@ -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
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([
"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

2 comments on commit 1e9fb81

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

Please sign in to comment.