def ilog_go

bend-collections-laws-crypto@1.0.0.0 · src/math/natural.bend:252

import bend-collections-laws-crypto@1.0.0.0/src/math/natural.bend as Natural
import Base

252# the largest k with b^k <= n: p is b^k, `up` is p * b <= n, asked as
253# p <= n / b so no product above n is formed
254def ilog_go(fuel: Nat, +n: Nat, +b: Nat, +k: Nat, +p: Nat, +up: Bool) -> Nat:
255  match fuel up:
256    case 0n _:
257      k
258    case 1n+f False{}:
259      k
260    case 1n+f True{}:
261      ilog_go(f, n, b, 1n+k, Nat.mul(p, b), Nat.is_le(Nat.mul(p, b), Nat.div(n, b)))

Uses (5)

Used by (6)