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.

floorPowerOfTwo

Returns the nearest power of two less than or equal to value, or zero if value is less than or equal to zero.

math.floorPowerOfTwo
pub fn floorPowerOfTwo(comptime T: type, value: T) T

File

lib/std/math.zig:1173

Code

pub fn floorPowerOfTwo(comptime T: type, value: T) T {
    const uT = @Int(.unsigned, @typeInfo(T).int.bits);
    if (value <= 0) return 0;
    return @as(T, 1) << log2_int(uT, @as(uT, @intCast(value)));
}