From bf5547046727ec789469fa3118522df7288ef529 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sun, 26 Sep 2021 08:29:07 +0200 Subject: [PATCH] Feat: make MOFraction comparable --- mapytex/calculus/API/tokens/number.py | 3 ++- mapytex/calculus/core/MO/fraction.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mapytex/calculus/API/tokens/number.py b/mapytex/calculus/API/tokens/number.py index 030f8cb..7924b9a 100644 --- a/mapytex/calculus/API/tokens/number.py +++ b/mapytex/calculus/API/tokens/number.py @@ -269,7 +269,8 @@ class Fraction(Token): >>> f.decimal """ - return Decimal(_Decimal(self._mo.numerator._value) / _Decimal(self._mo.denominator._value)) + return Decimal(self._mo._value) + # ----------------------------- diff --git a/mapytex/calculus/core/MO/fraction.py b/mapytex/calculus/core/MO/fraction.py index 798920f..133b1b1 100644 --- a/mapytex/calculus/core/MO/fraction.py +++ b/mapytex/calculus/core/MO/fraction.py @@ -9,6 +9,7 @@ from mapytex.calculus.core.tree import Tree from .mo import Molecule, MO from .atoms import MOnumber +from decimal import Decimal __all__ = ["MOFraction"] @@ -70,6 +71,10 @@ class MOFraction(Molecule): def denominator(self): return self._denominator + @property + def _value(self): + return Decimal(self._numerator._value) / Decimal(self._denominator._value) + def inverse(self): """ return the inverse fraction """ return MOFraction(self._denominator, self._numerator, self.negative)