From 9468d6381997dedaf3330f0c6e1b4290a9af1345 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 16 Dec 2019 10:17:43 -0500 Subject: allow comparison of any numeric types --- src/bigint.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/bigint.cpp') diff --git a/src/bigint.cpp b/src/bigint.cpp index 6c74b5f64a..1127033d02 100644 --- a/src/bigint.cpp +++ b/src/bigint.cpp @@ -1759,3 +1759,27 @@ void bigint_incr(BigInt *x) { bigint_add(x, ©, &one); } +void bigint_decr(BigInt *x) { + if (x->digit_count == 0) { + bigint_init_signed(x, -1); + return; + } + + if (x->digit_count == 1) { + if (x->is_negative && x->data.digit != UINT64_MAX) { + x->data.digit += 1; + return; + } else if (!x->is_negative && x->data.digit != 0) { + x->data.digit -= 1; + return; + } + } + + BigInt copy; + bigint_init_bigint(©, x); + + BigInt neg_one; + bigint_init_signed(&neg_one, -1); + + bigint_add(x, ©, &neg_one); +} -- cgit v1.2.3