Skip to content

Commit 6967a85

Browse files
authored
serializer: Simplify a bit number serialization. (#421)
Follow-up to #410
1 parent 452e6af commit 6967a85

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/serializer.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use crate::match_byte;
6-
use dtoa_short::Notation;
76
use std::fmt::{self, Write};
87
use std::str;
98

@@ -32,30 +31,21 @@ fn write_numeric<W>(value: f32, int_value: Option<i32>, has_sign: bool, dest: &m
3231
where
3332
W: fmt::Write,
3433
{
35-
// `value.value >= 0` is true for negative 0.
36-
if has_sign && value.is_sign_positive() {
34+
if value == 0.0 && value.is_sign_negative() {
35+
// Negative zero. Work around #20596.
36+
return dest.write_str("-0");
37+
}
38+
// NOTE: `value.value >= 0` is true for negative 0 but we've dealt with it above.
39+
if has_sign && value >= 0.0 {
3740
dest.write_str("+")?;
3841
}
3942

40-
let notation = if value == 0.0 && value.is_sign_negative() {
41-
// Negative zero. Work around #20596.
42-
dest.write_str("-0")?;
43-
Notation {
44-
decimal_point: false,
45-
scientific: false,
46-
}
47-
} else if let Some(int_val) = int_value {
48-
write!(dest, "{}", int_val)?;
49-
Notation {
50-
decimal_point: false,
51-
scientific: false,
52-
}
53-
} else {
54-
dtoa_short::write(dest, value)?
55-
};
43+
if let Some(v) = int_value {
44+
return write!(dest, "{}", v);
45+
}
5646

57-
if int_value.is_none() && value.fract() == 0. && !notation.decimal_point && !notation.scientific
58-
{
47+
let notation = dtoa_short::write(dest, value)?;
48+
if value.fract() == 0. && !notation.decimal_point && !notation.scientific {
5949
dest.write_str(".0")?;
6050
}
6151
Ok(())

0 commit comments

Comments
 (0)