@@ -38,6 +38,8 @@ Base.string(f::Spec{T}; modifier::String="") where {T} =
38
38
f. precision == 0 ? " .0" : f. precision > 0 ? " .$(f. precision) " : " " , modifier, char (T))
39
39
Base. show (io:: IO , f:: Spec ) = print (io, string (f))
40
40
41
+ nonfinitefmt (s:: Spec{T} ) where {T} =
42
+ Spec {Val{'g'}} (s. leftalign, s. plus, s. space, s. zero, s. hash, s. width, s. precision)
41
43
ptrfmt (s:: Spec{T} , x) where {T} =
42
44
Spec {Val{'x'}} (s. leftalign, s. plus, s. space, s. zero, true , s. width, sizeof (x) == 8 ? 16 : 8 )
43
45
264
266
# integers
265
267
toint (x) = x
266
268
toint (x:: Rational ) = Integer (x)
267
- toint (x:: AbstractFloat ) = x > typemax (Int128) ?
269
+ toint (x:: AbstractFloat ) = ! isfinite (x) ? x : x > typemax (Int128) ?
268
270
BigInt (round (x)) : x > typemax (Int64) ?
269
271
Int128 (round (x)) : Int64 (round (x))
270
272
@@ -273,6 +275,9 @@ toint(x::AbstractFloat) = x > typemax(Int128) ?
273
275
spec. leftalign, spec. plus, spec. space, spec. zero, spec. hash, spec. width, spec. precision
274
276
bs = base (T)
275
277
arg2 = toint (arg)
278
+ if ! isfinite (arg2)
279
+ return fmt (buf, pos, arg, nonfinitefmt (spec))
280
+ end
276
281
n = i = ndigits (arg2, base= bs, pad= 1 )
277
282
x, neg = arg2 < 0 ? (- arg2, true ) : (arg2, false )
278
283
arglen = n + (neg || (plus | space)) +
682
687
683
688
function plength (f:: Spec{T} , x) where {T <: Ints }
684
689
x2 = toint (x)
690
+ if ! isfinite (x2)
691
+ return plength (nonfinitefmt (f), x)
692
+ end
685
693
return max (f. width, f. precision + ndigits (x2, base= base (T), pad= 1 ) + 5 )
686
694
end
687
695
0 commit comments