Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Public Type Function

Log2Int

Public Type Function
std.math.Log2Int
pub fn Log2Int(comptime T: type) type

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

File

math.zig:782
782
783
784
785
786
787
788
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);
}