float_eq-rs icon indicating copy to clipboard operation
float_eq-rs copied to clipboard

Print float values in asserts in non-scientific format

Open jtempest opened this issue 4 years ago • 0 comments

Rust 1.58 changed how floats output with {:?} are displayed. When they are larger or smaller than a specific threshold, then the output switches to scientific notation. This makes the assert_float_eq! output less helpful, as the non-scientific notation is much clearer for comparing values side by side:

    left: `1.0`,
   right: `1.0000002`,
abs_diff: `0.00000023841858`,

Compare with:

    left: `1.0`,
   right: `1.0000002`,
abs_diff: `2.3841858e-7`,

Unfortunately, there appears to be no way to disable this behaviour with a format specifier. It is plausible that a solution may involve wrapping numeric outputs from float_eq's traits to print in this format. This is a significant amount of work.

jtempest avatar Jan 22 '22 07:01 jtempest