def Int.divmod.if

bend-kit-int@0.2.0.0 · int.bend:134

import bend-kit-int@0.2.0.0/int.bend as Int
import Base

134# x / 0 is 0 and x % 0 is x, as in Base's U32. MIN / -1 wraps to MIN.
135def Int.divmod.if(z: Bool, s: Bool, +n: Nat, +a: Word(n), +b: Word(n)) ->
136  Word(n) & Word(n):
137  match z:
138    case True{}:
139      (Word.zero(n), a)
140    case False{}:
141      match s:
142        case True{}:
143          Int.sdivmod.fix(n, Int.msb(n, a), Int.msb(n, b),
144            Int.udivmod.go(n, Int.abs(n, a), n, Int.abs(n, b)))
145        case False{}:
146          Int.udivmod.go(n, a, n, b)

Uses (10)

Used by (1)