Index Mathematics Conjectures nbv lettuce Widgets

log2_ceil!

Static base 2 logarithm of a scalar, rounded up. Integer and field arithmetic

log2_ceil! n

Returns ceil(log2(n)) for a static scalar n taken as its canonical integer: the number of bits needed to index n items, or the number of halvings that reduce n to one.

Arguments

n
Static scalar.

Returns

A static scalar. Expression form only.

Constraints

None.

Example

(let x)
static a = log2_ceil! 5
static b = log2_ceil! 1
static c = log2_ceil! 4
x * [a b c]

Notes

Computed in f64, which is exact for the sizes used in practice but can misround for values very close to a power of two above 2^53. n = 0 gives 0. The argument runs to the next comma: log2_ceil! k + 1 is the logarithm of k + 1, so wrap the precompile in parentheses inside larger expressions (16 + (log2_ceil! terms)). Errors: input must be static, input must be scalar.

Used in the standard library

bits/add32_bits, blake3/blake3_core, mersenne61/mldsa/mldsa_reduce, milli/mldsa/mldsa_reduce, polynomial/poly_norm_inf_lt, slip/slip_r1cs_arg_verify