IntFittingRange
Returns the smallest integer type that can hold both from and to.
Source
Implementation
pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) type {
assert(from <= to);
const signedness: std.builtin.Signedness = if (from < 0) .signed else .unsigned;
return @Type(.{ .int = .{
.signedness = signedness,
.bits = @as(u16, @intFromBool(signedness == .signed)) +
switch (if (from < 0) @max(@abs(from) - 1, to) else to) {
0 => 0,
else => |pos_max| 1 + log2(pos_max),
},
} });
}