You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Display trait associated with the imaginary part of underflow negative numbers #157
Hi, I have encountered an issue when printing an imaginary part of underflow negative numbers using the Display trait when a floating point number is underflow. Here is an example code:
use num::complex::Complex64;
fn main() {
let cn = Complex64::new(2.0, -1.0e-330);
println!("{:}", cn);
}
The output is 2+-0i
The output of the imaginary part is unreasonable due to the +- sign. The expected output is 2-0i or 2+0i. This is caused by the conditional statement $im < $T::zero() of fmt_re_im function in write_complex!() macro in lib.rs file. When $im is underflow, the statement is equal, but the Display trait of floating point numbers still outputs the negative sign. Maybe $im <= $T::zero() is a better choice. I'm hoping for a better idea for this issue. Thanks.
Can confirm, although simply -0.0 is enough to confuse it, as that is actually the floating point -0 which is equal in value to 0, but has a different representation. It can be reliably checked for using the signum or copysign functions.
Activity
redweasel commentedon Apr 29, 2026
Can confirm, although simply
-0.0is enough to confuse it, as that is actually the floating point -0 which is equal in value to 0, but has a different representation. It can be reliably checked for using thesignumorcopysignfunctions.