Feat: simplified version for Fraction and MOFraction
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -271,6 +271,29 @@ class Fraction(Token):
|
||||
"""
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
|
||||
Reference in New Issue
Block a user