From 6509e0164a987b6531e03771552fa88603503179 Mon Sep 17 00:00:00 2001 From: Lafrite Date: Fri, 21 Feb 2014 18:02:34 +0100 Subject: [PATCH] Add __eq__ in fraction --- pymath/fraction.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pymath/fraction.py b/pymath/fraction.py index ab774f5..1b91b02 100644 --- a/pymath/fraction.py +++ b/pymath/fraction.py @@ -166,13 +166,24 @@ class Fraction(object): return steps + def __eq__(self, other): + """ == """ + if type(other) == Fraction: + number = other + else: + number = Fraction(other) + + return self._num * number._denom == self._denom * number._num + def __lt__(self, other): + """ < """ if type(other) == Fraction: return (self._num / self._denom) < (other._num / other._denom) else: return (self._num / self._denom) < other def __le__(self, other): + """ <= """ if type(other) == Fraction: return (self._num / self._denom) <= (other._num / other._denom) else: