Fix bigint_shl (#9305)

This commit is contained in:
leesongun 2021-07-13 16:16:57 +09:00 committed by GitHub
parent 9086452ff9
commit 132b18e2b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -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;

View File

@ -573,6 +573,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;