From 0ab4afbf4236e6823be6b8845b7e9fa77f7c61f9 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Thu, 21 Jun 2018 08:14:26 -0400 Subject: Fix increment operation for bigint -1 --- src/bigint.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/bigint.cpp') 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; -- cgit v1.2.3 From eeda1a1396eb2732e8fe9234bd13d21ac334cfac Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Thu, 21 Jun 2018 08:17:08 -0400 Subject: Fix logic --- src/bigint.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/bigint.cpp') diff --git a/src/bigint.cpp b/src/bigint.cpp index 088703402d..bb227a7c3d 100644 --- a/src/bigint.cpp +++ b/src/bigint.cpp @@ -1685,16 +1685,11 @@ void bigint_incr(BigInt *x) { } if (x->digit_count == 1) { - if (x->is_negative) { - if (x->data.digit != 0) { - x->data.digit -= 1; - } + if (x->is_negative && x->data.digit != 0) { + x->data.digit -= 1; return; - } - else { - if (x->data.digit != UINT64_MAX) { - x->data.digit += 1; - } + } else if (!x->is_negative && x->data.digit != UINT64_MAX) { + x->data.digit += 1; return; } } -- cgit v1.2.3