Skip to content

Display trait associated with the imaginary part of underflow negative numbers #157

@seanxnie

Description

@seanxnie

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions