log2_exact!
Static base 2 logarithm of a scalar, meant for powers of two. Integer and field arithmetic
log2_exact! n
Returns log2(n) for a static scalar n taken as its canonical integer. Use it where n is known to be a power of two, such as the depth of a binary tree over n leaves.
Arguments
n- Static nonzero scalar.
Returns
A static scalar. Expression form only.
Constraints
None.
Example
(let x) static depth = log2_exact! 32 x * depth
Notes
Despite the name, exactness is not checked: the result is the floor of the logarithm, so log2_exact! 12 is 3. Assert the power of two yourself if it matters, e.g. assert_eq! n, pow2 with a static power computed in a loop. n = 0 panics inside the compiler. Errors: input must be static, input must be scalar. See log2_ceil! for the rounded-up logarithm.