Function mulWide [src]
Multiply a and b. Return type is wide enough to guarantee no
overflow.
Prototype
pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int( @typeInfo(T).int.signedness, @typeInfo(T).int.bits * 2, )
Parameters
T: type
a: T
b: T
Example
test mulWide {
try testing.expect(mulWide(u8, 5, 5) == 25);
try testing.expect(mulWide(i8, 5, -5) == -25);
try testing.expect(mulWide(u8, 100, 100) == 10000);
}
Source
pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(
@typeInfo(T).int.signedness,
@typeInfo(T).int.bits * 2,
) {
const ResultInt = std.meta.Int(
@typeInfo(T).int.signedness,
@typeInfo(T).int.bits * 2,
);
return @as(ResultInt, a) * @as(ResultInt, b);
}