Overload operators for MOnumbers in order to use gcd
This commit is contained in:
@@ -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):
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user