diff options
author | Nadrieril | 2019-03-21 21:27:36 +0100 |
---|---|---|
committer | Nadrieril | 2019-03-21 21:27:36 +0100 |
commit | 8d527e88168885ab754a039219d0ae682fa4508b (patch) | |
tree | b26d26902ba84d611f9905add97b3a29d0dcf025 /dhall_core/src/printer.rs | |
parent | 6cbe21b84ffd274f92791ab8dbf9af6527978688 (diff) |
Follow the spec for handling Doubles
Diffstat (limited to '')
-rw-r--r-- | dhall_core/src/printer.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index b72f32b..e43f1be 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -183,7 +183,23 @@ impl<S, A: Display> Expr<S, A> { a.fmt(f) } &IntegerLit(a) => a.fmt(f), - &DoubleLit(a) => a.fmt(f), + &DoubleLit(a) => { + let a = f64::from(*a); + if a == std::f64::INFINITY { + f.write_str("Infinity") + } else if a == std::f64::NEG_INFINITY { + f.write_str("-Infinity") + } else if a.is_nan() { + f.write_str("NaN") + } else { + let s = format!("{}", a); + if s.contains("e") || s.contains(".") { + f.write_str(&s) + } else { + write!(f, "{}.0", s) + } + } + } &TextLit(ref a) => { f.write_str("\"")?; for x in a.iter() { |