Add fmt::Display impl to Real

This commit is contained in:
Eryn Wells 2017-04-15 11:13:05 -07:00
parent 161c122327
commit 392c9e5ef8

View file

@ -2,6 +2,7 @@
* Eryn Wells <eryn@erynwells.me>
*/
use std::fmt;
use super::*;
use number::math::*;
@ -111,6 +112,16 @@ impl PartialEq for Real {
}
}
impl fmt::Display for Real {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Real::Integer(v) => write!(f, "{}", v),
Real::Rational(p, q) => write!(f, "{}/{}", p, q),
Real::Irrational(v) => write!(f, "{}", v),
}
}
}
#[cfg(test)]
mod tests {
mod integers {