diff --git a/types/src/number/add.rs b/types/src/number/add.rs index e9c1366..88fcf20 100644 --- a/types/src/number/add.rs +++ b/types/src/number/add.rs @@ -7,17 +7,8 @@ impl Add for Real { type Output = Real; fn add(self, other: Real) -> Real { - match other { - Real::Integer(v) => self.add_integer(v), - _ => Real::Integer(0) - } - } -} - -impl Real { - fn add_integer(self, v_other: Int) -> Real { - match self { - Real::Integer(v) => Real::Integer(v + v_other), + match (self, other) { + (Real::Integer(v), Real::Integer(ov)) => Real::Integer(v + ov), _ => Real::Integer(0) } } diff --git a/types/src/number/real.rs b/types/src/number/real.rs index 9539acf..9912151 100644 --- a/types/src/number/real.rs +++ b/types/src/number/real.rs @@ -3,11 +3,10 @@ */ use std::any::Any; -use std::ops::{Add, Sub, Mul, Div}; use super::*; use value::*; -#[derive(Debug)] +#[derive(Clone, Copy, Debug)] pub enum Real { Integer(Int), Rational(Int, Int), @@ -16,32 +15,11 @@ pub enum Real { impl PartialEq for Real { fn eq(&self, other: &Real) -> bool { - match *other { - Real::Integer(v) => self.eq_integer(v), - Real::Rational(p, q) => self.eq_rational(p, q), - Real::Irrational(v) => self.eq_irrational(v) - } - } -} - -impl Real { - fn eq_integer(&self, v_other: Int) -> bool { - match *self { - Real::Integer(v) => v == v_other, - _ => false - } - } - - fn eq_rational(&self, p_other: Int, q_other: Int) -> bool { - match *self { - Real::Rational(p, q) => p == p_other && q == q_other, - _ => false - } - } - - fn eq_irrational(&self, v_other: Flt) -> bool { - match *self { - Real::Irrational(v) => v == v_other, + // TODO: Make comparing different variants possible. + match (self, other) { + (&Real::Integer(v), &Real::Integer(ov)) => v == ov, + (&Real::Rational(p, q), &Real::Rational(op, oq)) => p == op && q == oq, + (&Real::Irrational(v), &Real::Irrational(ov)) => v == ov, _ => false } }