def Mag.gcd
import bend-kit-bignum@0.1.0.0/bigint.bend as Bigintimport Base
288# Euclid. Lame: under 5 steps per decimal digit of the smaller, so f from
289# 20 per limb of both never runs out.
290def Mag.gcd(+f: Nat, +a: List<&2, U32>, +b: List<&2, U32>) -> List<&2, U32>:
291 match f:
292 case 0n:
293 a
294 case 1n+g:
295 Mag.if(List<&2, U32>, List.is_empty(&2, U32, b), u => a,
296 u => Mag.gcd(g, b, Mag.rem(a, b)))