Skip to content

Commit f3bb151

Browse files
committed
de-obfuscate default output format
1 parent 346854d commit f3bb151

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/mpf.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,19 @@ impl fmt::Display for Mpf {
232232
impl fmt::Debug for Mpf {
233233
/// Due to the way `Mpf::get_str` works, the output contains an implicit
234234
/// radix point to the left of the first digit. `3.14`, for instance, will
235-
/// print as `314e1` which means `0.314e1`.
235+
/// print as `0.314e1`.
236236
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
237237
let mut exp: c_long = 0;
238238
match self.get_str(0, 10, &mut exp) {
239239
ref n if n.len() == 0 => write!(f, "0"),
240-
n => write!(f, "{}e{}", n, exp)
240+
n => {
241+
if self.sign() == Sign::Negative {
242+
// Skip sign output
243+
write!(f, "-0.{}e{}", &n[1..], exp)
244+
} else {
245+
write!(f, "0.{}e{}", n, exp)
246+
}
247+
}
241248
}
242249
}
243250
}

src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ mod mpf {
727727
// digit. The applicable exponent is written through the expptr pointer.
728728
// For example, the number 3.1416 would be returned as string "31416"
729729
// and exponent 1."
730-
assert_eq!(format!("{:?}", pi), "3141592653589e1");
731-
assert_eq!(format!("{:?}", -&pi), "-3141592653589e1");
730+
assert_eq!(format!("{:?}", pi), "0.3141592653589e1");
731+
assert_eq!(format!("{:?}", -&pi), "-0.3141592653589e1");
732732
}
733733
}

0 commit comments

Comments
 (0)