Skip to content

Commit 1c280a7

Browse files
committed
Fix #33262 by ensuring Base.print prints full precision for Float16/Float32, but doesn't include type info
1 parent 0bd60e6 commit 1c280a7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

base/ryu/Ryu.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ function writeexp(x::T,
101101
return String(resize!(buf, pos - 1))
102102
end
103103

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

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

123123
end # module

0 commit comments

Comments
 (0)