-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add formatting options for Complex #170
Conversation
It failed CI because If there's no other way to accomplish this, then we'll have to save this PR until we finally batch up breaking changes. |
☔ The latest upstream changes (presumably #171) made this pull request unmergeable. Please resolve the merge conflicts. |
da99676
to
977a7d9
Compare
Thanks for working on this! What are the drawbacks of just forwarding the whole formatter? Basically call |
@bluss if there's any padding/alignment requested, your way would do it twice. |
If we don't care about padding/alignment, then forwarding the formatter might be the best solution. It's succinct, relatively readable and we'd get scientific notation, precision etc. "for free". Another advantage of bluss's solution is that it's backwards compatible with 1.0.0 (I think). If we want to support padding/alignment, however, we would probably have to do it manually. It might be best to make another macro to reduce repetition between Display, LowerExp and UpperExp, and put all the padding/precision code in there. That way we could reduce the body of the |
I'm OK with a pass-through for now. Please leave a "FIXME" comment that we
should improve this once we move to a newer Rust baseline.
|
☔ The latest upstream changes (presumably #164) made this pull request unmergeable. Please resolve the merge conflicts. |
@DonSheddow Care to revisit this? We just bumped to rust 1.8 in #263, so I think this won't require any breaking change to implement in full now, right? |
2fddb7b
to
6c5bb31
Compare
I'm gonna start working on this now. We want to support scientific notation and all formatting parameters -- fill/alignment, precision, etc., right? I'm not sure the '#' and '0' flags makes sense for complex numbers though. How about binary and hex? Python does not support displaying complex numbers as hex, so maybe we shouldn't either. |
Come to think of it, representing floats as hex or binary doesn't make sense... I suppose the only traits we need to implement is Display, LowerExp and UpperExp. Looking at https://doc.rust-lang.org/std/fmt/struct.Formatter.html, the only function that isn't stable and pre-1.8 is |
Since this is generic code, I'd just do it for any Huh, |
6c5bb31
to
c61be82
Compare
@cuviper How does this implementation look? Since you can't specify a fill character without specifying alignment, I thought we'd just ignore both for now and implement fill when we can do alignment too. So this implementation just right-aligns and uses spaces as padding. It's not quite clear what the '0' flag would do for complex numbers, but I thought it would make more sense if it applies the padding to each scalar individually, instead of at the beginning or end. So |
That's tricky. It looks fine to split the padding when real and imaginary are near equal length, but consider If it looks too weird or difficult, we can decline to implement zero padding too. Is there any guidance to be had from how other languages pad complex numbers? |
I know atleast Python and Ruby ignores the zero pad flag when formatting complex numbers, but I don't know how any other languages do it.
I see, |
Yeah, you've understood my suggested padding, but I'm totally fine with ignoring this if other languages do. |
Alright, I'm just gonna remove it for now, if it's not that important. We can always implement it later if we want. |
I don't know why it doesn't pass CI by the way. Do I have to do anything else before this is merged? |
Hmm, compiler panic on |
Add formatting options for Complex This adds LowerExp and UpperExp traits for Complex, taking precision into account. Fixes #148
☀️ Test successful - status |
This adds LowerExp and UpperExp traits for Complex, taking precision into account. Fixes #148