Function floorPowerOfTwo [src]
Returns the nearest power of two less than or equal to value, or
zero if value is less than or equal to zero.
Prototype
pub fn floorPowerOfTwo(comptime T: type, value: T) T
Parameters
T: type
value: T
Example
test floorPowerOfTwo {
try testFloorPowerOfTwo();
try comptime testFloorPowerOfTwo();
}
Source
pub fn floorPowerOfTwo(comptime T: type, value: T) T {
const uT = std.meta.Int(.unsigned, @typeInfo(T).int.bits);
if (value <= 0) return 0;
return @as(T, 1) << log2_int(uT, @as(uT, @intCast(value)));
}