authorgravatar for 12179851+leesongun@users.noreply.github.comleesongun <12179851+leesongun@users.noreply.github.com> 2021-07-13 16:16:57+09:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-21 12:24:53-07:00
log1063bf696ed27d58d0c869f7b1f663a6c68b68c1
treeff6e348f8c51d91a849839966e88564a3add1694
parent3b8c4f07a4a83a31f9d863dd6410332982be1c1e

Fix bigint_shl (#9305)


2 files changed, 8 insertions(+), 1 deletions(-)

src/stage1/bigint.cpp+1-1
...@@ -1352,7 +1352,7 @@ void bigint_shl(BigInt *dest, const BigInt *op1, const BigInt *op2) {...@@ -1352,7 +1352,7 @@ void bigint_shl(BigInt *dest, const BigInt *op1, const BigInt *op2) {
13521352
1353 if (op1->digit_count == 1 && shift_amt < 64) {1353 if (op1->digit_count == 1 && shift_amt < 64) {
1354 dest->data.digit = op1_digits[0] << shift_amt;1354 dest->data.digit = op1_digits[0] << shift_amt;
1355 if (dest->data.digit > op1_digits[0]) {1355 if (dest->data.digit >> shift_amt == op1_digits[0]) {
1356 dest->digit_count = 1;1356 dest->digit_count = 1;
1357 dest->is_negative = op1->is_negative;1357 dest->is_negative = op1->is_negative;
1358 return;1358 return;
test/behavior/eval.zig+7
...@@ -570,6 +570,13 @@ test "comptime shlWithOverflow" {...@@ -570,6 +570,13 @@ test "comptime shlWithOverflow" {
570 try expect(ct_shifted == rt_shifted);570 try expect(ct_shifted == rt_shifted);
571}571}
572572
573test "comptime shl" {
574 var a: u128 = 3;
575 var b: u7 = 63;
576 var c: u128 = 3 << 63;
577 try expectEqual(a << b, c);
578}
579
573test "runtime 128 bit integer division" {580test "runtime 128 bit integer division" {
574 var a: u128 = 152313999999999991610955792383;581 var a: u128 = 152313999999999991610955792383;
575 var b: u128 = 10000000000000000000;582 var b: u128 = 10000000000000000000;