Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -32,30 +31,21 @@ fn write_numeric<W>(value: f32, int_value: Option<i32>, 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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be expressed slightly more succinctly inline:

Suggested change
}
if let Some(v) = int_value {
return write!(dest, "{v}");
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, auto-merge was faster...


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(())
Expand Down
Loading