pub fn log2_int(comptime T: type, x: T) Log2Int(T)
Return the log base 2 of integer value x, rounding down to the nearest integer.
T: type
x: T
1277 1278 1279 1280 1281 1282
pub fn log2_int(comptime T: type, x: T) Log2Int(T) { if (@typeInfo(T) != .int or @typeInfo(T).int.signedness != .unsigned) @compileError("log2_int requires an unsigned integer, found " ++ @typeName(T)); assert(x != 0); return @as(Log2Int(T), @intCast(@typeInfo(T).int.bits - 1 - @clz(x))); }
Return the log base 2 of integer value x, rounding down to the nearest integer.