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 {
|
impl fmt::Display for Number {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", self.real).and_then(|r| match self.imag {
|
write!(f, "{}", self.real).and_then(
|
||||||
Some(ref imag) => write!(f, "{}i", imag),
|
|r| self.imag.map(|i| write!(f, "{:+}i", i)).unwrap_or(Ok(r)))
|
||||||
None => Ok(r),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,7 @@ impl PartialEq for Real {
|
||||||
|
|
||||||
impl fmt::Display for Real {
|
impl fmt::Display for Real {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
// TODO: Figure out how to print the sign if `f.sign_plus() == true`.
|
||||||
match *self {
|
match *self {
|
||||||
Real::Integer(v) => write!(f, "{}", v),
|
Real::Integer(v) => write!(f, "{}", v),
|
||||||
Real::Rational(p, q) => write!(f, "{}/{}", p, q),
|
Real::Rational(p, q) => write!(f, "{}/{}", p, q),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue