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

Invalid Complex formatting for floats (f32 and f64). #425

Open
BilakshanP opened this issue Jul 7, 2023 · 3 comments
Open

Invalid Complex formatting for floats (f32 and f64). #425

BilakshanP opened this issue Jul 7, 2023 · 3 comments

Comments

@BilakshanP
Copy link

format!("{}", num::complex::Complex64::new(1.0, -0.0)) should yield 1+0i or 1-0i as result but instead 1+-0i is returned which is a mistake.

Here, real part is taken as 1 for demonstration purposes only.

@cuviper
Copy link
Member

cuviper commented Jul 7, 2023

Ugh. This is difficult because the formatting implementation is more generic than just float-like T, so we don't have any methods like is_sign_negative to detect the difference between +/-0.0. We only deal with negatives now by testing < T::zero(). I guess we could normalize == T::zero() to positive zero, as you allowed in your "should yield" possibilities -- not the best, but better than 1+-0i brokenness.

@BilakshanP
Copy link
Author

Yeah normalizing is a good patch-up maybe not a very great fix, but it should achieve the expected result regardless.

@BilakshanP
Copy link
Author

BilakshanP commented Jul 17, 2023

Just figured out that doing, format!("{:+}", number) would print the sign of the number whether it's positive or negative so, it should fix the problem.

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

2 participants