From 8d527e88168885ab754a039219d0ae682fa4508b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 21 Mar 2019 21:27:36 +0100 Subject: Follow the spec for handling Doubles --- dhall_core/src/printer.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'dhall_core/src/printer.rs') 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 Expr { 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() { -- cgit v1.2.3