Skip to content

Commit 46331a3

Browse files
committed
Avoid overflow when rounding
1 parent 4edb75c commit 46331a3

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/fmtcore.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat)
228228
e = 0
229229
u = zero(x)
230230
else
231-
e = floor(Integer, log10(ax))
232-
scale = exp10(-e + fs.prec)
233-
rax = round(ax * scale) / scale
231+
rax = signif(ax, fs.prec + 1)
234232
e = floor(Integer, log10(rax)) # exponent
235233
u = rax / exp10(e) # significand
236234
end

0 commit comments

Comments
 (0)