Implement Display for Numbers
This commit is contained in:
parent
a827958656
commit
b5e9ce6ae2
1 changed files with 12 additions and 1 deletions
|
|
@ -6,8 +6,10 @@
|
||||||
///
|
///
|
||||||
/// Scheme numbers are complex, literally.
|
/// Scheme numbers are complex, literally.
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
pub mod real;
|
pub mod real;
|
||||||
//mod add;
|
mod add;
|
||||||
mod math;
|
mod math;
|
||||||
|
|
||||||
pub use self::real::Real;
|
pub use self::real::Real;
|
||||||
|
|
@ -62,6 +64,15 @@ impl Number {
|
||||||
pub fn is_exact(&self) -> bool { self.exact }
|
pub fn is_exact(&self) -> bool { self.exact }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Number;
|
use super::Number;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue