Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

Log2Int

Returns an unsigned int type that can hold the number of bits in T - 1. Suitable for 0-based bit indices of T.

math.Log2Int
pub fn Log2Int(comptime T: type) type

File

lib/std/math.zig:782

Code

pub fn Log2Int(comptime T: type) type {
    // comptime ceil log2
    if (T == comptime_int) return comptime_int;
    const bits: u16 = @typeInfo(T).int.bits;
    const log2_bits = 16 - @clz(bits - 1);
    return @Int(.unsigned, log2_bits);
}