Commit db0fc32ab2

Jimmi Holst Christensen <jhc@liab.dk>
2018-01-17 14:00:27
fixed xor with zero
1 parent 1eda7e0
Changed files (2)
src
test
cases
src/bigint.cpp
@@ -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));
test/cases/math.zig
@@ -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);
+}