Index Mathematics Conjectures nbv lettuce Widgets

typed_varint_len

stdlib/typed/typed_varint_len.nbv

typed_varint_len(static n)

Number of bytes in the postcard (LEB128) varint of a static n: 7 bits per byte, least significant group first, the top bit of every byte but the last set.

Precompiles
div_floor!, if_lte!, loop!
Used by
typed/typed_varint_static, typed/typed_width

Source

# Number of bytes in the postcard (LEB128) varint of a static `n`: 7 bits
# per byte, least significant group first, the top bit of every byte but the
# last set.
(static n)

static mut l = 1
static mut x = n
loop! 18 {
  if_lte! 128, x {
    l = l + 1
    x = div_floor! x, 128
  }
}
l