Overload operators for MOnumbers in order to use gcd

This commit is contained in:
2018-03-13 18:57:38 +03:00
parent 3c133250ec
commit d1c6e2d3da
3 changed files with 132 additions and 3 deletions

View File

@@ -14,11 +14,13 @@ from .exceptions import ComputeError
from .add import add
from .minus import minus
from .multiply import multiply
from .divide import divide
OPERATIONS = {
"+": add,
"-": minus,
"*": multiply,
"/": divide,
}
def compute(node, left_v, right_v):

View File

@@ -24,10 +24,15 @@ def gcd(a, b):
2
"""
pos_a, _a = (a >= 0), abs(a)
pos_b, _b = (b >= 0), abs(b)
try:
pos_a, _a = (a >= 0), abs(a)
pos_b, _b = (b >= 0), abs(b)
gcd_sgn = (-1 + 2 * (pos_a or pos_b))
gcd_sgn = (-1 + 2 * (pos_a or pos_b))
except TypeError:
_a = a
_b = b
gcd_sgn = 1
if _a > _b:
c = _a % _b