Skip to content

@log2 should work on integers in addition to floats #13642

Open
@andrewrk

Description

@andrewrk
const std = @import("std");

const page_size = 4096;

test {
    try std.testing.expect(@log2(page_size) == 12);
}
test.zig:6:34: error: expected vector of floats or float type, found 'comptime_int'
    try std.testing.expect(@log2(page_size) == 12);
                                 ^~~~~~~~~

This code should work, in addition to runtime-known integers. It should return a value whose type has log2 number of bits.

Related: #3321

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.enhancementSolving this issue will likely involve adding new logic or components to the codebase.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions