def Mag.gcd

bend-kit-bignum@0.1.0.0 · bigint.bend:288

import bend-kit-bignum@0.1.0.0/bigint.bend as Bigint
import 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)))

Uses (6)

Used by (1)