Cannot cast `usize` to `i64` in `std.math.pow`

In a << b, b must be comptime-known or have a type with log2 number of bits as a, see Bit Shift Left in langref’s table of operators.

Here’s a working case:

const std = @import("std");

fn foo(input: []const u8) void {
    var acc: u64 = 0;
    for (0..4) |pow| {
        acc += @as(u64, input[pow + 1]) << @as(u6, @truncate(std.math.pow(usize, 8, pow)));
    }
}

pub fn main() !void {
    const input: []const u8 = "\xFF\xFF\xFF\xFF\xFF";
    foo(input);
}
1 Like