Skip to content

Commit 3371d04

Browse files
authored
Convert to Float64 in TOML's printvalue() to avoid invalidations (JuliaLang#61509)
1 parent 8c59e8e commit 3371d04

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

base/toml/printer.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,15 @@ function printvalue(f::Function, io::IO, value::Integer, sorted::Bool)
128128
end
129129

130130
function printvalue(f::Function, io::IO, value::AbstractFloat, sorted::Bool)
131+
# The early conversion here avoids invalidations from isnan/isinf
132+
value = Float64(value)
133+
131134
if isnan(value)
132135
Base.print(io, "nan")
133136
elseif isinf(value)
134137
Base.print(io, value > 0 ? "+inf" : "-inf")
135138
else
136-
Base.print(io, Float64(value)) # TOML specifies IEEE 754 binary64 for float
139+
Base.print(io, value) # TOML specifies IEEE 754 binary64 for float
137140
end
138141
end
139142

0 commit comments

Comments
 (0)