Skip to content

Commit

Permalink
Add compact 3-arg show for Irrational (#34741)
Browse files Browse the repository at this point in the history
  • Loading branch information
omus authored Feb 13, 2020
1 parent 83fd1e8 commit 79f31e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ struct Irrational{sym} <: AbstractIrrational end
show(io::IO, x::Irrational{sym}) where {sym} = print(io, sym)

function show(io::IO, ::MIME"text/plain", x::Irrational{sym}) where {sym}
print(io, sym, " = ", string(float(x))[1:15], "...")
if get(io, :compact, false)
print(io, sym)
else
print(io, sym, " = ", string(float(x))[1:15], "...")
end
end

promote_rule(::Type{<:AbstractIrrational}, ::Type{Float16}) = Float16
Expand Down
6 changes: 6 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,12 @@ end

@test sqrt(2) == 1.4142135623730951
end
@testset "Irrational printing" begin
@test sprint(show, "text/plain", π) == "π = 3.1415926535897..."
@test sprint(show, "text/plain", π, context=:compact => true) == "π"
@test sprint(show, π) == "π"

end
@testset "issue #6365" begin
for T in (Float32, Float64)
for i = 9007199254740992:9007199254740996
Expand Down

0 comments on commit 79f31e4

Please sign in to comment.