From db0fc32ab2d5277655a87200be8f602473ed30d2 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Wed, 17 Jan 2018 14:00:27 +0100 Subject: [PATCH] fixed xor with zero --- src/bigint.cpp | 6 ++++++ test/cases/math.zig | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/bigint.cpp b/src/bigint.cpp index a68dd3a4b8..05c6463aa3 100644 --- a/src/bigint.cpp +++ b/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)); diff --git a/test/cases/math.zig b/test/cases/math.zig index 090e2b9dfd..7f57838ecb 100644 --- a/test/cases/math.zig +++ b/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); +}