src/util/pm_integer.c in prism-0.30.0 vs src/util/pm_integer.c in prism-1.0.0
- old
+ new
@@ -41,11 +41,11 @@
if (carry > 0) {
values[length] = (uint32_t) carry;
length++;
}
- *destination = (pm_integer_t) { 0, length, values, false };
+ *destination = (pm_integer_t) { length, values, 0, false };
}
/**
* Internal use for karatsuba_multiply. Calculates `a - b - c` with the given
* base. Assume a, b, c, a - b - c all to be positive.
@@ -85,11 +85,11 @@
carry = sub / (int64_t) base - 2;
}
}
while (a_length > 1 && values[a_length - 1] == 0) a_length--;
- *destination = (pm_integer_t) { 0, a_length, values, false };
+ *destination = (pm_integer_t) { a_length, values, 0, false };
}
/**
* Multiply two positive integers with the given base using karatsuba algorithm.
* Return pm_integer_t with values allocated. Not normalized.
@@ -128,11 +128,11 @@
}
values[left_index + right_length] = carry;
}
while (length > 1 && values[length - 1] == 0) length--;
- *destination = (pm_integer_t) { 0, length, values, false };
+ *destination = (pm_integer_t) { length, values, 0, false };
return;
}
if (left_length * 2 <= right_length) {
uint32_t *values = (uint32_t *) xcalloc(left_length + right_length, sizeof(uint32_t));
@@ -140,20 +140,20 @@
for (size_t start_offset = 0; start_offset < right_length; start_offset += left_length) {
size_t end_offset = start_offset + left_length;
if (end_offset > right_length) end_offset = right_length;
pm_integer_t sliced_left = {
- .value = 0,
.length = left_length,
.values = left_values,
+ .value = 0,
.negative = false
};
pm_integer_t sliced_right = {
- .value = 0,
.length = end_offset - start_offset,
.values = right_values + start_offset,
+ .value = 0,
.negative = false
};
pm_integer_t product;
karatsuba_multiply(&product, &sliced_left, &sliced_right, base);
@@ -167,19 +167,19 @@
if (carry > 0) values[start_offset + product.length] += carry;
pm_integer_free(&product);
}
- *destination = (pm_integer_t) { 0, left_length + right_length, values, false };
+ *destination = (pm_integer_t) { left_length + right_length, values, 0, false };
return;
}
size_t half = left_length / 2;
- pm_integer_t x0 = { 0, half, left_values, false };
- pm_integer_t x1 = { 0, left_length - half, left_values + half, false };
- pm_integer_t y0 = { 0, half, right_values, false };
- pm_integer_t y1 = { 0, right_length - half, right_values + half, false };
+ pm_integer_t x0 = { half, left_values, 0, false };
+ pm_integer_t x1 = { left_length - half, left_values + half, 0, false };
+ pm_integer_t y0 = { half, right_values, 0, false };
+ pm_integer_t y1 = { right_length - half, right_values + half, 0, false };
pm_integer_t z0 = { 0 };
karatsuba_multiply(&z0, &x0, &y0, base);
pm_integer_t z2 = { 0 };
@@ -227,11 +227,11 @@
pm_integer_free(&z2);
pm_integer_free(&x01);
pm_integer_free(&y01);
pm_integer_free(&xy);
- *destination = (pm_integer_t) { 0, length, values, false };
+ *destination = (pm_integer_t) { length, values, 0, false };
}
/**
* The values of a hexadecimal digit, where the index is the ASCII character.
* Note that there's an odd exception here where _ is mapped to 0. This is
@@ -321,11 +321,11 @@
uint32_t value = integer->values[0];
bool negative = integer->negative && value != 0;
pm_integer_free(integer);
- *integer = (pm_integer_t) { .value = value, .length = 0, .values = NULL, .negative = negative };
+ *integer = (pm_integer_t) { .values = NULL, .value = value, .length = 0, .negative = negative };
}
/**
* Convert base of the integer.
* In practice, it converts 10**9 to 1<<32 or 1<<32 to 10**9.
@@ -410,11 +410,11 @@
values[index] |= value << shift;
if (32 - shift < bit) values[index + 1] |= value >> (32 - shift);
}
while (length > 1 && values[length - 1] == 0) length--;
- *integer = (pm_integer_t) { .value = 0, .length = length, .values = values, .negative = false };
+ *integer = (pm_integer_t) { .length = length, .values = values, .value = 0, .negative = false };
pm_integer_normalize(integer);
}
/**
* Convert decimal digits to pm_integer_t.
@@ -436,10 +436,10 @@
value = 0;
}
}
// Convert base from 10**9 to 1<<32.
- pm_integer_convert_base(integer, &((pm_integer_t) { .value = 0, .length = length, .values = values, .negative = false }), 1000000000, ((uint64_t) 1 << 32));
+ pm_integer_convert_base(integer, &((pm_integer_t) { .length = length, .values = values, .value = 0, .negative = false }), 1000000000, ((uint64_t) 1 << 32));
xfree(values);
}
/**
* Parse a large integer from a string that does not fit into uint32_t.