fixed xor with zero

This commit is contained in:
Jimmi Holst Christensen 2018-01-17 14:00:27 +01:00
parent 1eda7e0fde
commit db0fc32ab2
2 changed files with 11 additions and 0 deletions

View File

@ -1271,6 +1271,12 @@ void bigint_and(BigInt *dest, const BigInt *op1, const BigInt *op2) {
}
void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2) {
if (op1->digit_count == 0) {
return bigint_init_bigint(dest, op2);
}
if (op2->digit_count == 0) {
return bigint_init_bigint(dest, op1);
}
if (op1->is_negative || op2->is_negative) {
// TODO this code path is untested
size_t big_bit_count = max(bigint_bits_needed(op1), bigint_bits_needed(op2));

View File

@ -369,3 +369,8 @@ fn test_f128() {
fn should_not_be_zero(x: f128) {
assert(x != 0.0);
}
test "xor with zero" {
assert(0xFF ^ 0x00 == 0xFF);
comptime assert(0xFF ^ 0x00 == 0xFF);
}