diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-06-21 13:40:37 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-21 13:40:37 -0400 |
| commit | 47dd1049c8ef4064084af05e7b62becf502e41e6 (patch) | |
| tree | ac9e77d8b76f5733c3309f4f0dbc83b0246c75b7 /src/bigint.cpp | |
| parent | f50c0c664f3bd7a56c0274ffecae28e2b41c8d20 (diff) | |
| parent | f1207a8e744617d62e5c535cf05764cdf2cfd99e (diff) | |
| download | zig-47dd1049c8ef4064084af05e7b62becf502e41e6.tar.gz zig-47dd1049c8ef4064084af05e7b62becf502e41e6.zip | |
Merge pull request #1145 from isaachier/bigint-neg-one-incr-fix
Fix bigint -1 increment operation
Diffstat (limited to 'src/bigint.cpp')
| -rw-r--r-- | src/bigint.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/bigint.cpp b/src/bigint.cpp index 367ae79b6c..bb227a7c3d 100644 --- a/src/bigint.cpp +++ b/src/bigint.cpp @@ -1683,10 +1683,15 @@ 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 && x->data.digit != 0) { + x->data.digit -= 1; + return; + } else if (!x->is_negative && x->data.digit != UINT64_MAX) { + x->data.digit += 1; + return; + } } BigInt copy; |
