Skip to content

Commit

Permalink
Fix bigint shift-right partial shift
Browse files Browse the repository at this point in the history
  • Loading branch information
tiehuis committed May 10, 2018
1 parent c3ddf50 commit efa39c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bigint.cpp
Expand Up @@ -1425,7 +1425,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) {
uint64_t digit = op1_digits[op_digit_index];
size_t dest_digit_index = op_digit_index - digit_shift_count;
dest->data.digits[dest_digit_index] = carry | (digit >> leftover_shift_count);
carry = digit << leftover_shift_count;
carry = digit << (64 - leftover_shift_count);

if (dest_digit_index == 0) { break; }
op_digit_index -= 1;
Expand Down
8 changes: 8 additions & 0 deletions test/cases/math.zig
Expand Up @@ -366,6 +366,14 @@ test "big number multi-limb shift and mask" {
}
}

test "big number multi-limb partial shift right" {
comptime {
var a = 0x1ffffffffeeeeeeee;
a >>= 16;
assert(a == 0x1ffffffffeeee);
}
}

test "xor" {
test_xor();
comptime test_xor();
Expand Down

0 comments on commit efa39c5

Please sign in to comment.