authorgravatar for 12179851+leesongun@users.noreply.github.comleesongun <12179851+leesongun@users.noreply.github.com> 2021-07-13 16:16:57+09:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-07-13 10:16:57+03:00
log132b18e2b39feca3b90b1b13df2b4649b1661fd5
tree12fdd08a6b571f29be3555f8350e53a73da60a1e
parent9086452ff98cf0ec271f449d0824d5b070b26f45
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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
...@@ -573,6 +573,13 @@ test "comptime shlWithOverflow" {...@@ -573,6 +573,13 @@ test "comptime shlWithOverflow" {
573 try expect(ct_shifted == rt_shifted);573 try expect(ct_shifted == rt_shifted);
574}574}
575575
576test "comptime shl" {
577 var a: u128 = 3;
578 var b: u7 = 63;
579 var c: u128 = 3 << 63;
580 try expectEqual(a << b, c);
581}
582
576test "runtime 128 bit integer division" {583test "runtime 128 bit integer division" {
577 var a: u128 = 152313999999999991610955792383;584 var a: u128 = 152313999999999991610955792383;
578 var b: u128 = 10000000000000000000;585 var b: u128 = 10000000000000000000;