Add fmt::Display impl to Real
This commit is contained in:
parent
161c122327
commit
392c9e5ef8
1 changed files with 11 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue