Fix printing of zero floats and doubles (!)
This commit is contained in:
parent
7c4b9151ab
commit
bf85504233
|
@ -208,22 +208,22 @@ impl<W: io::Write> Writer for TextWriter<W> {
|
|||
}
|
||||
|
||||
fn write_f32(&mut self, v: f32) -> io::Result<()> {
|
||||
if f32::is_normal(v) || f32::is_subnormal(v) {
|
||||
if v.is_nan() || v.is_infinite() {
|
||||
write!(self.w, "#xf\"{}\"",
|
||||
HexFormatter::Packed.encode(&u32::to_be_bytes(f32::to_bits(v))))
|
||||
} else {
|
||||
dtoa::write(&mut self.w, v)?;
|
||||
write!(self.w, "f")
|
||||
} else {
|
||||
let bs = v.to_be_bytes();
|
||||
write!(self.w, "#xf\"{}\"", HexFormatter::Packed.encode(&bs))
|
||||
}
|
||||
}
|
||||
|
||||
fn write_f64(&mut self, v: f64) -> io::Result<()> {
|
||||
if f64::is_normal(v) || f64::is_subnormal(v) {
|
||||
if v.is_nan() || v.is_infinite() {
|
||||
write!(self.w, "#xd\"{}\"",
|
||||
HexFormatter::Packed.encode(&u64::to_be_bytes(f64::to_bits(v))))
|
||||
} else {
|
||||
dtoa::write(&mut self.w, v)?;
|
||||
Ok(())
|
||||
} else {
|
||||
let bs = v.to_be_bytes();
|
||||
write!(self.w, "#xd\"{}\"", HexFormatter::Packed.encode(&bs))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue