My friend loves JavaScript. I need to make him believe he can use Zig as inefficient as he uses JavaScript. Here is what I came up with:
fn power_of_two (index: u8) !u64 {
@setEvalBranchQuota(100000);
switch (index) {
inline 0...63 => |comptime_value| {
return comptime std.fmt.parseInt(
u64,
"1" ++ "0" ** comptime_value,
2,
) catch unreachable;
},
else => return error.IndexOutOfBounds,
}
}
Who needs << when you can parse strings?
Can the compiler optimize the hell out of this mess? Compiler Explorer