# Generated by tools/algo/legacy.py from the corpus: do not edit. # TheAlgorithms' two gcds (maths.viv). # Element comparisons are routed through lib/algo/legacy/order.viv; nothing else changes. import algo.legacy.order # from study/idioms/thealgorithms-python/maths.viv: greatest_common_divisor gcd_by_iterative #| greatest_common_divisor.py: gcd(a, b) = |b| if a == 0 else gcd(b % a, a). #| `%` takes the sign of the divisor, as Python's does, which the doctests with negatives rely on. def greatest_common_divisor(a, b) { if a == 0.0 { return abs(b) } return greatest_common_divisor(b % a, a) } def gcd_by_iterative(x0, y0) { x = x0 y = y0 while y != 0.0 { r = x % y x = y y = r } return abs(x) }