Compare commits

..

No commits in common. "1347c30b9270ba78c07096e4d5a1aa9cba6c0b18" and "78ce8f767a79448bdda3c4c94e79de48548df456" have entirely different histories.

2 changed files with 1 additions and 62 deletions

View File

@ -269,31 +269,7 @@ class Fraction(Token):
>>> f.decimal
<Decimal 0.3333333333333333333333333333>
"""
return Decimal(self._mo._value)
def simplified(self):
""" Get the irreductible version of self
:example:
>>> f = Fraction("3/4")
>>> f.simplified()
<Fraction 3 / 4>
>>> f = Fraction("12/9")
>>> f.simplified()
<Fraction 4 / 3>
>>> f = Fraction("12/4")
>>> f.simplified()
<Integer 3>
"""
simplified = self._mo.simplified()
if isinstance(simplified, MOnumber):
return Integer(simplified)
return Fraction(simplified)
return Decimal(_Decimal(self._mo.numerator._value) / _Decimal(self._mo.denominator._value))
# -----------------------------

View File

@ -9,8 +9,6 @@
from mapytex.calculus.core.tree import Tree
from .mo import Molecule, MO
from .atoms import MOnumber
from decimal import Decimal
from ..arithmetic import gcd
__all__ = ["MOFraction"]
@ -72,10 +70,6 @@ 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)
@ -96,37 +90,6 @@ class MOFraction(Molecule):
else:
raise NotImplementedError
def simplified(self):
""" Simplified version of self
:examplex
>>> f = MOFraction(2, 3)
>>> f
<MOFraction 2 / 3>
>>> f.simplified()
<MOFraction 2 / 3>
>>> f = MOFraction(2, 6)
>>> f
<MOFraction 2 / 6>
>>> f.simplified()
<MOFraction 1 / 3>
>>> f = MOFraction(32, 24)
>>> f.simplified()
<MOFraction 4 / 3>
>>> f = MOFraction(32, 8)
>>> f.simplified()
<MOnumber 4>
"""
frac_gcd = gcd(self.numerator._value, self.denominator._value)
new_num = self.numerator._value / frac_gcd
new_denom = self.denominator._value / frac_gcd
if new_denom == 1:
return MOnumber(new_num)
return MOFraction(new_num, new_denom)
# -----------------------------
# Reglages pour 'vim'