num icon indicating copy to clipboard operation
num copied to clipboard

Invalid Complex formatting for floats (f32 and f64).

Open BilakshanP opened this issue 2 years ago • 3 comments

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.

BilakshanP avatar Jul 07 '23 17:07 BilakshanP

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.

cuviper avatar Jul 07 '23 19:07 cuviper

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

BilakshanP avatar Jul 15 '23 15:07 BilakshanP

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.

BilakshanP avatar Jul 17 '23 06:07 BilakshanP