From 0ab4afbf4236e6823be6b8845b7e9fa77f7c61f9 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Thu, 21 Jun 2018 08:14:26 -0400 Subject: [PATCH] Fix increment operation for bigint -1 --- src/bigint.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/bigint.cpp b/src/bigint.cpp index 367ae79b6c..088703402d 100644 --- a/src/bigint.cpp +++ b/src/bigint.cpp @@ -1683,10 +1683,20 @@ void bigint_incr(BigInt *x) { bigint_init_unsigned(x, 1); return; } - - if (x->digit_count == 1 && x->data.digit != UINT64_MAX) { - x->data.digit += 1; - return; + + if (x->digit_count == 1) { + if (x->is_negative) { + if (x->data.digit != 0) { + x->data.digit -= 1; + } + return; + } + else { + if (x->data.digit != UINT64_MAX) { + x->data.digit += 1; + } + return; + } } BigInt copy;