@@ -11,8 +11,6 @@ function Base.show(io::IO, params::DisplayParameters)
11
11
print (io, " - significant figures: $(params. sigfigs) " )
12
12
end
13
13
14
- Base. show (io:: IO , x:: Complex{<:Interval} ) = print (io, x. re, " + " , x. im, " im" )
15
-
16
14
const display_params = DisplayParameters (:standard , false , 6 )
17
15
18
16
const display_options = (:standard , :full , :midpoint )
@@ -274,6 +272,11 @@ function subscriptify(n::Integer)
274
272
join ( [Char (subscript_0 + i) for i in dig])
275
273
end
276
274
275
+ function superscriptify (n:: Integer )
276
+ exps = [' ⁰' , ' ¹' , ' ²' , ' ³' , ' ⁴' , ' ⁵' , ' ⁶' , ' ⁷' , ' ⁸' , ' ⁹' ]
277
+ dig = reverse (digits (n))
278
+ return join ([exps[d+ 1 ] for d in dig])
279
+ end
277
280
278
281
# fall-back:
279
282
representation (a:: Interval{T} , format= nothing ) where T =
@@ -319,29 +322,61 @@ function representation(a::DecoratedInterval{T}, format=nothing) where T
319
322
end
320
323
321
324
322
- function representation (X:: IntervalBox , format= nothing )
325
+ function representation (X:: IntervalBox{N, T} , format= nothing ) where {N, T}
323
326
324
327
if format == nothing
325
328
format = display_params. format # default
326
329
end
327
330
328
- if display_params. format == :full
329
- return string (" IntervalBox(" , join (X. v, " , " ), " )" )
331
+ n = format == :full ? N : superscriptify (N)
332
+
333
+ if isempty (X)
334
+ format == :full && return string (" IntervalBox(∅, " , n, " )" )
335
+ return string (" ∅" , n)
336
+ end
337
+
338
+ x = first (X)
339
+ if all (== (x), X)
340
+ if format == :full
341
+ return string (" IntervalBox(" , representation (x, format), " , " , n, " )" )
342
+ elseif format == :midpoint
343
+ return string (" (" , representation (x, format), " )" , n)
344
+ else
345
+ return string (representation (x, format), n)
346
+ end
347
+ end
330
348
349
+ if format == :full
350
+ full_str = representation .(X. v, :full )
351
+ return string (" IntervalBox(" , join (full_str, " , " ), " )" )
352
+ elseif format == :midpoint
353
+ return string (" (" , join (X. v, " ) × (" ), " )" )
331
354
else
332
355
return join (X. v, " × " )
333
356
end
334
357
335
358
end
336
359
360
+ function representation (x:: Complex{<:Interval} , format= nothing )
361
+
362
+ if format == nothing
363
+ format = display_params. format
364
+ end
365
+
366
+ format == :midpoint && return string (' (' , x. re, ' )' , " + " , ' (' , x. im, ' )' , " im" )
367
+
368
+ return string (x. re, " + " , x. im, " im" )
369
+ end
337
370
338
371
for T in (Interval, DecoratedInterval)
339
372
@eval show (io:: IO , a:: $T{S} ) where S = print (io, representation (a))
340
373
@eval showfull (io:: IO , a:: $T{S} ) where S = print (io, representation (a, :full ))
341
374
@eval showfull (a:: $T{S} ) where S = showfull (stdout , a)
342
375
end
343
376
344
- T = IntervalBox
345
- @eval show (io:: IO , a:: $T ) = print (io, representation (a))
346
- @eval show (io:: IO , :: MIME"text/plain" , a:: $T ) = print (io, representation (a))
347
- @eval showfull (io:: IO , a:: $T ) = print (io, representation (a, :full ))
377
+ for T in (IntervalBox, Complex{<: Interval })
378
+ @eval show (io:: IO , a:: $T ) = print (io, representation (a))
379
+ @eval show (io:: IO , :: MIME"text/plain" , a:: $T ) = print (io, representation (a))
380
+ @eval showfull (io:: IO , a:: $T ) = print (io, representation (a, :full ))
381
+ @eval showfull (a:: $T ) = showfull (stdout , a)
382
+ end
0 commit comments