def u32_wpow

bend-collections-laws-math@1.0.0.0 · src/math/fixed.bend:127

import bend-collections-laws-math@1.0.0.0/src/math/fixed.bend as Fixed
import Base
import bend-collections-laws-math@1.0.0.0/src/math/instances.bend as I

127# binary exponentiation modulo 2^32; e halves every step (32 steps)
128def u32_wpow(fuel: Nat, +e: U32, +b: U32, +acc: U32, z: Bool) -> U32:
129  match fuel z:
130    case 0n _:
131      acc
132    case 1n+f True{}:
133      acc
134    case 1n+ +f False{}:
135      u32_wpow(f, U32.shr(e), U32.mul(b, b), pick(U32, I.u32_odd(e), U32.mul(acc, b), acc), U32.is_zero(U32.shr(e)))

Uses (8)

Used by (2)