def bit_length_go

bend-collections-laws-math@1.0.0.0 · src/math/generic.bend:348

import bend-collections-laws-math@1.0.0.0/src/math/generic.bend as Generic
import Base
import bend-collections-laws-math@1.0.0.0/src/math/num.bend as N

348# the number of halvings to reach zero
349def bit_length_go(~T: Data, ~op: N.Op<T> -> T, ~test: N.Test<T> -> Bool, fuel: Nat, +k: Nat, st: T & Bool) -> Nat:
350  match fuel st:
351    case 0n _:
352      k
353    case 1n+f Tuple{n, True{}}:
354      k
355    case 1n+f Tuple{+n, False{}}:
356      bit_length_go(~T, ~op, ~test, f, 1n+k, zst(~T, ~test, op(N.Half{n})))

Uses (7)

Used by (3)