Skip to content

Commit

Permalink
Fix #33262 by ensuring Base.print prints full precision for Float16/F…
Browse files Browse the repository at this point in the history
…loat32, but doesn't include type info
  • Loading branch information
quinnj committed Sep 19, 2019
1 parent 0bd60e6 commit 1c280a7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/ryu/Ryu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ function writeexp(x::T,
return String(resize!(buf, pos - 1))
end

function Base.show(io::IO, x::T) where {T <: Base.IEEEFloat}
function Base.show(io::IO, x::T, forceuntyped::Bool=false) where {T <: Base.IEEEFloat}
compact = get(io, :compact, false)
buf = Base.StringVector(neededdigits(T))
typed = !compact && get(io, :typeinfo, Any) != typeof(x)
typed = !forceuntyped && !compact && get(io, :typeinfo, Any) != typeof(x)
pos = writeshortest(buf, 1, x, false, false, true, -1,
x isa Float32 ? UInt8('f') : UInt8('e'), false, UInt8('.'), typed, compact)
write(io, resize!(buf, pos - 1))
Expand All @@ -118,6 +118,6 @@ function Base.string(x::T) where {T <: Base.IEEEFloat}
return String(resize!(buf, pos - 1))
end

Base.print(io::IO, x::Union{Float16, Float32}) = show(IOContext(io, :compact => true), x)
Base.print(io::IO, x::Union{Float16, Float32}) = show(io, x, true)

end # module

0 comments on commit 1c280a7

Please sign in to comment.