| ... | @@ -86,6 +86,11 @@ static void to_twos_complement(BigInt *dest, const BigInt *op, size_t bit_count) | ... | @@ -86,6 +86,11 @@ static void to_twos_complement(BigInt *dest, const BigInt *op, size_t bit_count) |
| 86 | size_t digits_to_copy = bit_count / 64; | 86 | size_t digits_to_copy = bit_count / 64; |
| 87 | size_t leftover_bits = bit_count % 64; | 87 | size_t leftover_bits = bit_count % 64; |
| 88 | dest->digit_count = digits_to_copy + ((leftover_bits == 0) ? 0 : 1); | 88 | dest->digit_count = digits_to_copy + ((leftover_bits == 0) ? 0 : 1); |
| | 89 | if (dest->digit_count == 1 && leftover_bits == 0) { |
| | 90 | dest->data.digit = op_digits[0]; |
| | 91 | if (dest->data.digit == 0) dest->digit_count = 0; |
| | 92 | return; |
| | 93 | } |
| 89 | dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count); | 94 | dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count); |
| 90 | for (size_t i = 0; i < digits_to_copy; i += 1) { | 95 | for (size_t i = 0; i < digits_to_copy; i += 1) { |
| 91 | uint64_t digit = (i < op->digit_count) ? op_digits[i] : 0; | 96 | uint64_t digit = (i < op->digit_count) ? op_digits[i] : 0; |