Skip to content

Fix issue #157: Display negative imaginary component#158

Open
Astronomy487 wants to merge 2 commits into
rust-num:masterfrom
Astronomy487:iss157-display-negative-imaginary-component
Open

Fix issue #157: Display negative imaginary component#158
Astronomy487 wants to merge 2 commits into
rust-num:masterfrom
Astronomy487:iss157-display-negative-imaginary-component

Conversation

@Astronomy487
Copy link
Copy Markdown

@Astronomy487 Astronomy487 commented May 23, 2026

This PR fixes #157. The original implementation of Display checks what sign is needed between the real and imaginary components by comparing the imaginary component to T::zero(). This fails for negative-zero, which should be treated as negative but not less than zero, producing 2+-0i when it should produce 2-0i.

This fix replaces a comparison against T::zero() with the is_negative method. This fix replaces the trait bound of PartialOrd with a trait bound of Signed. Technically can break people's custom types that implement PartialOrd but not Signed. Added an appropriate test to test_string_formatting.

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

Successfully merging this pull request may close these issues.

Display trait associated with the imaginary part of underflow negative numbers

1 participant