diff options
| author | gingerBill <bill@gingerbill.org> | 2021-07-11 17:43:56 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-07-11 17:43:56 +0100 |
| commit | ff2e5c3efe931e6a088c2368b0ce5d5c21f03c65 (patch) | |
| tree | bdda8406d8d60baa1f8cff600e695586c5b45939 /src/big_int.cpp | |
| parent | 3600b2e209dd1826f7aa75de904854b142244dc0 (diff) | |
Simplify `big_int_not` for negative inputs
Diffstat (limited to 'src/big_int.cpp')
| -rw-r--r-- | src/big_int.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/big_int.cpp b/src/big_int.cpp index 231064bea..9cb1ec586 100644 --- a/src/big_int.cpp +++ b/src/big_int.cpp @@ -415,6 +415,14 @@ void big_int_not(BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed) { big_int_from_u64(dst, 0); return; } + if (big_int_is_neg(x)) { + // ~x == -x - 1 + big_int_neg(dst, x); + mp_decr(dst); + mp_mod_2d(dst, bit_count, dst); + return; + } + BigInt pow2b = {}; mp_2expt(&pow2b, bit_count); |