Commit 1063bf696e
2021-07-13 09:16:57
1 parent
3b8c4f0Changed files (2)
src
stage1
test
behavior
src/stage1/bigint.cpp
@@ -1352,7 +1352,7 @@ void bigint_shl(BigInt *dest, const BigInt *op1, const BigInt *op2) {
if (op1->digit_count == 1 && shift_amt < 64) {
dest->data.digit = op1_digits[0] << shift_amt;
- if (dest->data.digit > op1_digits[0]) {
+ if (dest->data.digit >> shift_amt == op1_digits[0]) {
dest->digit_count = 1;
dest->is_negative = op1->is_negative;
return;
test/behavior/eval.zig
@@ -570,6 +570,13 @@ test "comptime shlWithOverflow" {
try expect(ct_shifted == rt_shifted);
}
+test "comptime shl" {
+ var a: u128 = 3;
+ var b: u7 = 63;
+ var c: u128 = 3 << 63;
+ try expectEqual(a << b, c);
+}
+
test "runtime 128 bit integer division" {
var a: u128 = 152313999999999991610955792383;
var b: u128 = 10000000000000000000;