Fix display of 0.0.

This commit is contained in:
Stephen Chung 2021-11-03 08:44:07 +08:00
parent f1c5f0a232
commit 7c6b444616
2 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,15 @@
Rhai Release Notes Rhai Release Notes
================== ==================
Version 1.1.2
=============
Bug fixes
---------
* `0.0` now prints correctly (used to print `0e0`).
Version 1.1.1 Version 1.1.1
============= =============

View File

@ -1825,7 +1825,9 @@ impl<F: Float + fmt::Debug> fmt::Debug for FloatWrapper<F> {
impl<F: Float + fmt::Display + fmt::LowerExp + From<f32>> fmt::Display for FloatWrapper<F> { impl<F: Float + fmt::Display + fmt::LowerExp + From<f32>> fmt::Display for FloatWrapper<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let abs = self.0.abs(); let abs = self.0.abs();
if abs > Self::MAX_NATURAL_FLOAT_FOR_DISPLAY.into() if abs.fract().is_zero() {
f.write_str("0.0")
} else if abs > Self::MAX_NATURAL_FLOAT_FOR_DISPLAY.into()
|| abs < Self::MIN_NATURAL_FLOAT_FOR_DISPLAY.into() || abs < Self::MIN_NATURAL_FLOAT_FOR_DISPLAY.into()
{ {
write!(f, "{:e}", self.0) write!(f, "{:e}", self.0)