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.
Sean
Hi, I have encountered an issue when printing an imaginary part of underflow negative numbers using the
Displaytrait when a floating point number is underflow. Here is an example code:The output is
2+-0iThe output of the imaginary part is unreasonable due to the
+-sign. The expected output is2-0ior2+0i. This is caused by the conditional statement$im < $T::zero()offmt_re_imfunction inwrite_complex!()macro inlib.rsfile. When$imis underflow, the statement is equal, but theDisplaytrait 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.Sean