def Mag.fix

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

import bend-kit-bignum@0.1.0.0/bigint.bend as Bigint
import Base

206# Knuth's Algorithm D step D6: the estimate d is at most 2 over the true
207# quotient digit, so f = 3 steps of p - bn always settle it.
208def Mag.fix(+f: Nat, +d: U32, +p: List<&2, U32>, +r: List<&2, U32>,
209  +bn: List<&2, U32>, +q: List<&2, U32>) -> List<&2, U32> & List<&2, U32>:
210  match f:
211    case 0n:
212      (Con{d, q}, Mag.norm(Mag.sub(r, p, 0)))
213    case 1n+g:
214      Mag.if(List<&2, U32> & List<&2, U32>, Cmp.is_gt(Mag.cmp(p, r)),
215        u => Mag.fix(g, (d - 1 : U32), Mag.norm(Mag.sub(p, bn, 0)), r, bn, q),
216        u => (Con{d, q}, Mag.norm(Mag.sub(r, p, 0))))

Uses (11)

Used by (1)