Couple more tweaks to number printing

This commit is contained in:
Eryn Wells 2017-04-22 15:05:51 -07:00
parent 15910480ee
commit 2f8051135f
2 changed files with 3 additions and 4 deletions

View file

@ -66,10 +66,8 @@ impl Number {
impl fmt::Display for Number {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.real).and_then(|r| match self.imag {
Some(ref imag) => write!(f, "{}i", imag),
None => Ok(r),
})
write!(f, "{}", self.real).and_then(
|r| self.imag.map(|i| write!(f, "{:+}i", i)).unwrap_or(Ok(r)))
}
}

View file

@ -130,6 +130,7 @@ impl PartialEq for Real {
impl fmt::Display for Real {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// TODO: Figure out how to print the sign if `f.sign_plus() == true`.
match *self {
Real::Integer(v) => write!(f, "{}", v),
Real::Rational(p, q) => write!(f, "{}/{}", p, q),