Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad print format for Complex{Unsigned} #37756

Open
vtjnash opened this issue Sep 25, 2020 · 7 comments
Open

bad print format for Complex{Unsigned} #37756

vtjnash opened this issue Sep 25, 2020 · 7 comments
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. good first issue Indicates a good issue for first-time contributors to Julia kind:bug Indicates an unexpected problem or unintended behavior status:help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@vtjnash
Copy link
Sponsor Member

vtjnash commented Sep 25, 2020

Complex number printing assumes that simple concatenation will produce something meaningful:

julia> 0x1e*im
0x00 + 0x1eim

julia> 0x1eim
ERROR: syntax: invalid numeric constant "0x1ei"
@vtjnash vtjnash added the domain:display and printing Aesthetics and correctness of printed representations of objects. label Sep 25, 2020
@JeffreySarnoff
Copy link
Contributor

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

@simeonschaub
Copy link
Member

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.

@JeffreySarnoff
Copy link
Contributor

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

@JeffBezanson JeffBezanson added the kind:bug Indicates an unexpected problem or unintended behavior label Sep 28, 2020
@User-764Q
Copy link

Bump, I tested this today on Julia 1.6.2 and it was still a problem.

@simeonschaub simeonschaub added good first issue Indicates a good issue for first-time contributors to Julia status:help wanted Indicates that a maintainer wants help on an issue or pull request labels Oct 16, 2021
@P3rcy-8685
Copy link

P3rcy-8685 commented Aug 20, 2022

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?

@divyaS09
Copy link

I would like to contribute to resolving this issue. Please assign this issue to me.

@KristofferC
Copy link
Sponsor Member

Please assign this issue to me.

This is generally not done. But don't let that stop you from working on it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. good first issue Indicates a good issue for first-time contributors to Julia kind:bug Indicates an unexpected problem or unintended behavior status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

8 participants