diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-09-02 04:11:23 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-09-02 04:11:23 -0400 |
| commit | e1d5da20a5d5e54b9dba6031c97fe232192e69cd (patch) | |
| tree | 78d17c42ff26bed171582d31aa06647571d6cfdf /src/bigint.cpp | |
| parent | 0f38955ee5b5ff2251fdbc3ac4d95a9aecfdfd3c (diff) | |
| download | zig-e1d5da20a5d5e54b9dba6031c97fe232192e69cd.tar.gz zig-e1d5da20a5d5e54b9dba6031c97fe232192e69cd.zip | |
rewrite parseh to use AST instead of direct types
some tests still failing
Diffstat (limited to 'src/bigint.cpp')
| -rw-r--r-- | src/bigint.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/bigint.cpp b/src/bigint.cpp index 63393f6358..395d9fce80 100644 --- a/src/bigint.cpp +++ b/src/bigint.cpp @@ -165,6 +165,25 @@ void bigint_init_signed(BigInt *dest, int64_t x) { dest->data.digit = ((uint64_t)(-(x + 1))) + 1; } +void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count, bool is_negative) { + if (digit_count == 0) { + return bigint_init_unsigned(dest, 0); + } else if (digit_count == 1) { + dest->digit_count = 1; + dest->data.digit = digits[0]; + dest->is_negative = is_negative; + bigint_normalize(dest); + return; + } + + dest->digit_count = digit_count; + dest->is_negative = is_negative; + dest->data.digits = allocate_nonzero<uint64_t>(digit_count); + memcpy(dest->data.digits, digits, sizeof(uint64_t) * digit_count); + + bigint_normalize(dest); +} + void bigint_init_bigint(BigInt *dest, const BigInt *src) { if (src->digit_count == 0) { return bigint_init_unsigned(dest, 0); |
