Skip to content

Commit dcb7a98

Browse files
fredrikekreararslan
authored andcommitted
showcompact(io, ...) -> show(IOContext(io, :compact=>true), ...) (#110)
1 parent 619ea0a commit dcb7a98

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/FixedPointNumbers.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module FixedPointNumbers
55
using Base: reducedim_initarray
66

77
import Base: ==, <, <=, -, +, *, /, ~, isapprox,
8-
convert, promote_rule, show, showcompact, isinteger, abs, decompose,
8+
convert, promote_rule, show, isinteger, abs, decompose,
99
isnan, isinf, isfinite,
1010
zero, oneunit, one, typemin, typemax, realmin, realmax, eps, sizeof, reinterpret,
1111
float, trunc, round, floor, ceil, bswap,
@@ -101,11 +101,10 @@ function showtype(io::IO, ::Type{X}) where {X <: FixedPoint}
101101
io
102102
end
103103
function show(io::IO, x::FixedPoint{T,f}) where {T,f}
104-
showcompact(io, x)
105-
showtype(io, typeof(x))
104+
show(io, round(convert(Float64,x), digits=ceil(Int,f/_log2_10)))
105+
get(io, :compact, false) || showtype(io, typeof(x))
106106
end
107107
const _log2_10 = 3.321928094887362
108-
showcompact(io::IO, x::FixedPoint{T,f}) where {T,f} = show(io, round(convert(Float64,x), digits=ceil(Int,f/_log2_10)))
109108

110109
function Base.showarg(io::IO, a::Array{T}, toplevel) where {T<:FixedPoint}
111110
toplevel || print(io, "::")
@@ -176,8 +175,8 @@ scaledual(b::Tdual, x::Union{T,AbstractArray{T}}) where {Tdual <: Number,T <: Fi
176175
n = 2^(8*sizeof(T))
177176
bitstring = sizeof(T) == 1 ? "an 8-bit" : "a $(8*sizeof(T))-bit"
178177
io = IOBuffer()
179-
showcompact(io, typemin(T)); Tmin = String(take!(io))
180-
showcompact(io, typemax(T)); Tmax = String(take!(io))
178+
show(IOContext(io, :compact=>true), typemin(T)); Tmin = String(take!(io))
179+
show(IOContext(io, :compact=>true), typemax(T)); Tmax = String(take!(io))
181180
throw(ArgumentError("$T is $bitstring type representing $n values from $Tmin to $Tmax; cannot represent $x"))
182181
end
183182

0 commit comments

Comments
 (0)