diff --git a/src/serializer.rs b/src/serializer.rs index 78175925..ca6eda81 100644 --- a/src/serializer.rs +++ b/src/serializer.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use crate::match_byte; -use dtoa_short::Notation; use std::fmt::{self, Write}; use std::str; @@ -32,30 +31,21 @@ fn write_numeric(value: f32, int_value: Option, has_sign: bool, dest: &m where W: fmt::Write, { - // `value.value >= 0` is true for negative 0. - if has_sign && value.is_sign_positive() { + if value == 0.0 && value.is_sign_negative() { + // Negative zero. Work around #20596. + return dest.write_str("-0"); + } + // NOTE: `value.value >= 0` is true for negative 0 but we've dealt with it above. + if has_sign && value >= 0.0 { dest.write_str("+")?; } - let notation = if value == 0.0 && value.is_sign_negative() { - // Negative zero. Work around #20596. - dest.write_str("-0")?; - Notation { - decimal_point: false, - scientific: false, - } - } else if let Some(int_val) = int_value { - write!(dest, "{}", int_val)?; - Notation { - decimal_point: false, - scientific: false, - } - } else { - dtoa_short::write(dest, value)? - }; + if let Some(v) = int_value { + return write!(dest, "{}", v); + } - if int_value.is_none() && value.fract() == 0. && !notation.decimal_point && !notation.scientific - { + let notation = dtoa_short::write(dest, value)?; + if value.fract() == 0. && !notation.decimal_point && !notation.scientific { dest.write_str(".0")?; } Ok(())