|
210 | 210 | # That's called by b & c but not d: |
211 | 211 | # (a = 3f0, b = randn(3) .> 0, c = [true, false], d = randn(1000) .> 0) |
212 | 212 |
|
| 213 | +##### |
| 214 | +##### complex |
| 215 | +##### |
| 216 | + |
| 217 | +# function show(io::IO, z::Complex) |
| 218 | +# r, i = reim(z) |
| 219 | +# compact = get(io, :compact, false)::Bool |
| 220 | +# show(io, r) |
| 221 | +# if signbit(i) && !isnan(i) |
| 222 | +# print(io, compact ? "-" : " - ") |
| 223 | +# if isa(i,Signed) && !isa(i,BigInt) && i == typemin(typeof(i)) |
| 224 | +# show(io, -widen(i)) |
| 225 | +# else |
| 226 | +# show(io, -i) |
| 227 | +# end |
| 228 | +# else |
| 229 | +# print(io, compact ? "+" : " + ") |
| 230 | +# show(io, i) |
| 231 | +# end |
| 232 | +# if !(isa(i,Integer) && !isa(i,Bool) || isa(i,AbstractFloat) && isfinite(i)) |
| 233 | +# print(io, "*") |
| 234 | +# end |
| 235 | +# print(io, "im") |
| 236 | +# end |
| 237 | + |
| 238 | +function Base.show(io::IO, z::Complex{<:Union{Integer, AbstractFloat}}) |
| 239 | + r, i = reim(z) |
| 240 | + compact = get(io, :compact, false)::Bool |
| 241 | + show(io, r) |
| 242 | + if signbit(i) && !isnan(i) |
| 243 | + print(io, compact ? "-" : " - ") |
| 244 | + # if isa(i,Signed) && !isa(i,BigInt) && i == typemin(typeof(i)) |
| 245 | + # show(io, -widen(i)) |
| 246 | + # else |
| 247 | + # show(io, -i) |
| 248 | + # end |
| 249 | + str = sprint(show, i, context=IOContext(io)) |
| 250 | + j = findfirst('-', str) |
| 251 | + str = string(str[1:j-1], str[j+1:end]) |
| 252 | + print(io, str) |
| 253 | + else |
| 254 | + print(io, compact ? "+" : " + ") |
| 255 | + show(io, i) |
| 256 | + end |
| 257 | + if !(isa(i,Integer) && !isa(i,Bool) || isa(i,AbstractFloat) && isfinite(i)) |
| 258 | + print(io, "*") |
| 259 | + end |
| 260 | + print(io, "im") |
| 261 | + |
| 262 | + # iscolor = get(io, :color, false)::Bool |
| 263 | + # q = iscolor && _preprint(io, i) |
| 264 | + # print(io, "im") # this looks weird for randn(ComplexF32, 30) |
| 265 | + # q && _postprint(io) |
| 266 | +end |
| 267 | + |
213 | 268 |
|
214 | 269 | ##### |
215 | 270 | ##### types |
@@ -286,7 +341,7 @@ function Base.print_matrix_row(io::IO, |
286 | 341 | 2::Int) # this 2 is a trick to make 2nd column line up! |
287 | 342 |
|
288 | 343 | skip && return |
289 | | - printstyled(io, " # ", hidden=true) |
| 344 | + printstyled(io, " # ", hidden=true, color=:light_black) # some terminals can't do hidden=true |
290 | 345 |
|
291 | 346 | WIDTH = 33.0 # NB not an integer, else `2*WIDTH * xi` overflows Float16 |
292 | 347 |
|
@@ -320,12 +375,14 @@ function Base.print_matrix_row(io::IO, |
320 | 375 | printstyled(io, repeat(" ", spaces), minus_str, mid_str, plus_str; color) |
321 | 376 | end |
322 | 377 |
|
| 378 | +ARROWS = collect("➡️↗️⬆️↖️⬅️↙️⬇️↘️0️⃣⏹")[1:2:end] |
| 379 | + |
323 | 380 | function _arrow(x::Complex) |
324 | | - symb = collect("➡️↗️⬆️↖️⬅️↙️⬇️↘️0️⃣⏹")[1:2:end] |
325 | 381 | isfinite(x) || return " " |
326 | | - iszero(x) && return symb[end-1] |
327 | | - i = trunc(Int, mod(angle(x) - pi/8, 2pi) * (4/pi)) + 1 |
328 | | - symb[mod1(i+1, 8)] |
| 382 | + iszero(x) && return ARROWS[end-1] |
| 383 | + i = trunc(Int, mod(angle(x) - pi / 8, 2pi) * (4 / pi)) + 1 |
| 384 | + ARROWS[mod1(i + 1, 8)] |
| 385 | +end |
329 | 386 | end |
330 | 387 |
|
331 | 388 | end # module InTheRed |
|
0 commit comments