Skip to content

Commit

Permalink
more compact output for Irrational show/print (JuliaLang#30960)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Feb 5, 2019
1 parent 2ae7372 commit f52c911
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ Construct a tuple of the given objects.
# Examples
```jldoctest
julia> tuple(1, 'a', pi)
(1, 'a', π = 3.1415926535897...)
(1, 'a', π)
```
"""
tuple
Expand Down
6 changes: 5 additions & 1 deletion base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ symbol `sym`.
"""
struct Irrational{sym} <: AbstractIrrational end

show(io::IO, x::Irrational{sym}) where {sym} = print(io, "$sym = $(string(float(x))[1:15])...")
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], "...")
end

promote_rule(::Type{<:AbstractIrrational}, ::Type{Float16}) = Float16
promote_rule(::Type{<:AbstractIrrational}, ::Type{Float32}) = Float32
Expand Down
6 changes: 3 additions & 3 deletions doc/src/manual/performance-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ julia> a = Real[]
julia> push!(a, 1); push!(a, 2.0); push!(a, π)
3-element Array{Real,1}:
1
2.0
π = 3.1415926535897...
1
2.0
π
```

Because `a` is a an array of abstract type [`Real`](@ref), it must be able to hold any
Expand Down
5 changes: 4 additions & 1 deletion test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ end

@test Float16(3.0) < pi
@test pi < Float16(4.0)
@test occursin("3.14159", sprint(show, π))
@test widen(pi) === pi

@test occursin("3.14159", sprint(show, MIME"text/plain"(), π))
@test repr(Any[pi ℯ; ℯ pi]) == "Any[π ℯ; ℯ π]"
@test string(pi) == "π"
end

@testset "frexp,ldexp,significand,exponent" begin
Expand Down

0 comments on commit f52c911

Please sign in to comment.