Open vtjnash opened 4 years ago
plausible logic
restr = sprint(show, complexnum.re)
imstr = sprint(show, complexnum.im)
imstr = '9' < imstr[end] ? (imstr * "*im") : (imstr * "im")
imstr = signbit(complexnum.im) ? " - "*imstr[2:end] : " + " * imstr
str = restr * imstr
Perhaps we also just might want to do show_unquoted(:($(z.re) + $(z.im) * im))
, since that already handles all this logic. We would be putting arbitrary number types into the AST, but I don't think that should be a problem if it's just for printing, since show_unquoted
should always fall back to show
.
I was unaware of show_unquoted
. With Complex{<:Unsigned}
it interposes spaces around the '*', though.
julia> z = complex(0x3a, 0x2e)
0x3a + 0x2eim
julia> Base.show_unquoted(stdout,:($(z.re) + $(z.im) * im))
0x3a + 0x2e * im
julia> z = complex(58, 46)
58 + 46im
julia> Base.show_unquoted(stdout,:($(z.re) + $(z.im) * im))
58 + 46im
Bump, I tested this today on Julia 1.6.2 and it was still a problem.
I would like to take up this issue, but I wanted to clarify what exactly the problem is.
We would like complex numbers to be printed in the following manner, right?
z=complex(1,2) 1 + 2*im
Or is something else needed?
I would like to contribute to resolving this issue. Please assign this issue to me.
Please assign this issue to me.
This is generally not done. But don't let that stop you from working on it :)
Complex number printing assumes that simple concatenation will produce something meaningful: