def S32.divmod.if

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

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

606# x / 0 is 0 and x % 0 is x, as in Base's U32. MIN / -1 wraps to MIN.
607def S32.divmod.if(z: Bool, +a: U32, +b: U32) -> U32 & U32:
608  match z:
609    case True{}:
610      (0, a)
611    case False{}:
612      (S32.neg_if(Bool.xor(S32.is_neg(a), S32.is_neg(b)),
613        U32.div(S32.abs(a), S32.abs(b))),
614        S32.neg_if(S32.is_neg(a), U32.mod(S32.abs(a), S32.abs(b))))

Uses (10)

Used by (2)