From 0abd80655abb3529908606c6f4ed6916415c146e Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Mon, 14 Oct 2019 22:26:51 +0200 Subject: [PATCH] Feat: dirty way to get decimal approx of a function --- mapytex/calculus/API/tokens/number.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mapytex/calculus/API/tokens/number.py b/mapytex/calculus/API/tokens/number.py index 8a03731..d321291 100644 --- a/mapytex/calculus/API/tokens/number.py +++ b/mapytex/calculus/API/tokens/number.py @@ -16,6 +16,7 @@ from ...core.arithmetic import gcd from ...core.random.int_gene import filter_random from ...core.MO import MO, MOnumber from ...core.MO.fraction import MOFraction +from random import random __all__ = ["Integer", "Decimal"] @@ -242,6 +243,20 @@ class Fraction(Token): def denominator(self): return self._mo.denominator + @property + def decimal(self): + """ return decimal approximation of the fraction + + :example: + >>> f = Fraction("3/4") + >>> f.decimal + + >>> f = Fraction("1/3") + >>> f.decimal + + """ + return Decimal(_Decimal(self._mo.numerator._value) / _Decimal(self._mo.denominator._value)) + # ----------------------------- # Reglages pour 'vim'