Skip to content

Commit cf67f99

Browse files
committed
remove type instability
1 parent 874d042 commit cf67f99

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/fmtspec.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,28 +172,34 @@ function printfmt(io::IO, fs::FormatSpec, x)
172172
cls = fs.cls
173173
ty = fs.typ
174174
if cls == 'i'
175-
ix = x
176175
try
177176
ix = Integer(x)
177+
ty == 'd' || ty == 'n' ? _pfmt_i(io, fs, ix, _Dec()) :
178+
ty == 'x' ? _pfmt_i(io, fs, ix, _Hex()) :
179+
ty == 'X' ? _pfmt_i(io, fs, ix, _HEX()) :
180+
ty == 'o' ? _pfmt_i(io, fs, ix, _Oct()) :
181+
_pfmt_i(io, fs, ix, _Bin())
178182
catch
183+
ty == 'd' || ty == 'n' ? _pfmt_i(io, fs, x, _Dec()) :
184+
ty == 'x' ? _pfmt_i(io, fs, x, _Hex()) :
185+
ty == 'X' ? _pfmt_i(io, fs, x, _HEX()) :
186+
ty == 'o' ? _pfmt_i(io, fs, x, _Oct()) :
187+
_pfmt_i(io, fs, x, _Bin())
179188
end
180-
ty == 'd' || ty == 'n' ? _pfmt_i(io, fs, ix, _Dec()) :
181-
ty == 'x' ? _pfmt_i(io, fs, ix, _Hex()) :
182-
ty == 'X' ? _pfmt_i(io, fs, ix, _HEX()) :
183-
ty == 'o' ? _pfmt_i(io, fs, ix, _Oct()) :
184-
_pfmt_i(io, fs, ix, _Bin())
185189
elseif cls == 'f'
186-
fx = x
187190
try
188191
fx = float(x)
192+
if isfinite(fx)
193+
ty == 'f' || ty == 'F' ? _pfmt_f(io, fs, fx) :
194+
ty == 'e' || ty == 'E' ? _pfmt_e(io, fs, fx) :
195+
error("format for type g or G is not supported yet (use f or e instead).")
196+
else
197+
_pfmt_specialf(io, fs, fx)
198+
end
189199
catch
190-
end
191-
if isfinite(fx)
192-
ty == 'f' || ty == 'F' ? _pfmt_f(io, fs, fx) :
193-
ty == 'e' || ty == 'E' ? _pfmt_e(io, fs, fx) :
200+
ty == 'f' || ty == 'F' ? _pfmt_f(io, fs, x) :
201+
ty == 'e' || ty == 'E' ? _pfmt_e(io, fs, x) :
194202
error("format for type g or G is not supported yet (use f or e instead).")
195-
else
196-
_pfmt_specialf(io, fs, fx)
197203
end
198204
elseif cls == 's'
199205
_pfmt_s(io, fs, _srepr(x))

0 commit comments

Comments
 (0)