Fix serialization of -0.0. (#426)
This commit is contained in:
parent
2c08988a44
commit
fed4022c88
24
src/ser.rs
24
src/ser.rs
|
@ -751,17 +751,21 @@ impl<'a> Serializer<'a> {
|
||||||
macro_rules! serialize_float {
|
macro_rules! serialize_float {
|
||||||
($this:expr, $v:expr) => {{
|
($this:expr, $v:expr) => {{
|
||||||
$this.emit_key(ArrayState::Started)?;
|
$this.emit_key(ArrayState::Started)?;
|
||||||
if ($v.is_nan() || $v == 0.0) && $v.is_sign_negative() {
|
match ($v.is_sign_negative(), $v.is_nan(), $v == 0.0) {
|
||||||
write!($this.dst, "-").map_err(ser::Error::custom)?;
|
(true, true, _) => write!($this.dst, "-nan"),
|
||||||
}
|
(false, true, _) => write!($this.dst, "nan"),
|
||||||
if $v.is_nan() {
|
(true, false, true) => write!($this.dst, "-0.0"),
|
||||||
write!($this.dst, "nan").map_err(ser::Error::custom)?;
|
(false, false, true) => write!($this.dst, "0.0"),
|
||||||
} else {
|
(_, false, false) => write!($this.dst, "{}", $v).and_then(|_| {
|
||||||
write!($this.dst, "{}", $v).map_err(ser::Error::custom)?;
|
if $v % 1.0 == 0.0 {
|
||||||
}
|
write!($this.dst, ".0")
|
||||||
if $v % 1.0 == 0.0 {
|
} else {
|
||||||
write!($this.dst, ".0").map_err(ser::Error::custom)?;
|
Ok(())
|
||||||
|
}
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
|
.map_err(ser::Error::custom)?;
|
||||||
|
|
||||||
if let State::Table { .. } = $this.state {
|
if let State::Table { .. } = $this.state {
|
||||||
$this.dst.push_str("\n");
|
$this.dst.push_str("\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue