Feat: make MOFraction comparable

This commit is contained in:
Bertrand Benjamin 2021-09-26 08:29:07 +02:00
parent 78ce8f767a
commit bf55470467
2 changed files with 7 additions and 1 deletions

View File

@ -269,7 +269,8 @@ class Fraction(Token):
>>> f.decimal
<Decimal 0.3333333333333333333333333333>
"""
return Decimal(_Decimal(self._mo.numerator._value) / _Decimal(self._mo.denominator._value))
return Decimal(self._mo._value)
# -----------------------------

View File

@ -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)