Couple more tweaks to number printing
This commit is contained in:
parent
15910480ee
commit
2f8051135f
2 changed files with 3 additions and 4 deletions
|
@ -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)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue