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

Activity for 1.2.2 Display - Formatting a Complex Struct #1678

Open
j-medland opened this issue Feb 8, 2023 · 0 comments
Open

Activity for 1.2.2 Display - Formatting a Complex Struct #1678

j-medland opened this issue Feb 8, 2023 · 0 comments

Comments

@j-medland
Copy link

j-medland commented Feb 8, 2023

I am having some difficulty with achieving the activity in 1.2.2 Display due to the presence of a space between the sign and the imaginary component.

The activity asks to add a fmt::Display implementation for a struct representing a complex number with real and imaginary f64 values with the output:

3.3 + 7.2i

Using "{} {:+}i" would seem like the reasonable approach but this yields 3.3 +7.2i and it is not obvious how I can pad between the sign and imaginary component to get the output specified. As the activity doesn't test complex numbers with a negative imaginary component, some folks might just use "{} + {}i" and move on to the next lesson.

So am I missing something - is there a way to add padding? should I use some conditional statement based on the sign of the imaginary component?

I noticed this change was introduced by PR #1123 where previous to this, there was no space.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant