aboutsummaryrefslogtreecommitdiff
path: root/src/bigint.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-09-02 04:11:23 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-09-02 04:11:23 -0400
commite1d5da20a5d5e54b9dba6031c97fe232192e69cd (patch)
tree78d17c42ff26bed171582d31aa06647571d6cfdf /src/bigint.cpp
parent0f38955ee5b5ff2251fdbc3ac4d95a9aecfdfd3c (diff)
downloadzig-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.cpp19
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);