From de00cd31ec774452cbb24b4791473326fa76d223 Mon Sep 17 00:00:00 2001 From: bryant Date: Tue, 6 Jun 2017 17:34:52 -0400 Subject: [PATCH] de-obfuscate default output format --- src/mpf.rs | 11 +++++++++-- src/test.rs | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/mpf.rs b/src/mpf.rs index 25a2d0f..0604794 100644 --- a/src/mpf.rs +++ b/src/mpf.rs @@ -232,12 +232,19 @@ impl fmt::Display for Mpf { impl fmt::Debug for Mpf { /// Due to the way `Mpf::get_str` works, the output contains an implicit /// radix point to the left of the first digit. `3.14`, for instance, will - /// print as `314e1` which means `0.314e1`. + /// print as `0.314e1`. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut exp: c_long = 0; match self.get_str(0, 10, &mut exp) { ref n if n.len() == 0 => write!(f, "0"), - n => write!(f, "{}e{}", n, exp) + n => { + if self.sign() == Sign::Negative { + // Skip sign output + write!(f, "-0.{}e{}", &n[1..], exp) + } else { + write!(f, "0.{}e{}", n, exp) + } + } } } } diff --git a/src/test.rs b/src/test.rs index ceca5bf..ee160f7 100644 --- a/src/test.rs +++ b/src/test.rs @@ -727,7 +727,7 @@ mod mpf { // digit. The applicable exponent is written through the expptr pointer. // For example, the number 3.1416 would be returned as string "31416" // and exponent 1." - assert_eq!(format!("{:?}", pi), "3141592653589e1"); - assert_eq!(format!("{:?}", -&pi), "-3141592653589e1"); + assert_eq!(format!("{:?}", pi), "0.3141592653589e1"); + assert_eq!(format!("{:?}", -&pi), "-0.3141592653589e1"); } }