aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-23 22:49:33 -0400
committerGitHub <noreply@github.com>2021-10-23 22:49:33 -0400
commit94879506ea8fe51310f38b3db1bc1ea1e71a4389 (patch)
treea9d14300c4a6ff01c5a5eff22dcbf63cd23558e1 /src/value.zig
parent1690b35770a97aec4b8a7b1b31a61b01e04f5656 (diff)
parentc563521d44e857e2ef80885a43304f1e6c64713b (diff)
downloadzig-94879506ea8fe51310f38b3db1bc1ea1e71a4389.tar.gz
zig-94879506ea8fe51310f38b3db1bc1ea1e71a4389.zip
Merge pull request #10017 from Snektron/big-int-div
Big ints: division fixes
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/value.zig b/src/value.zig
index af1216f652..cbfeea9786 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -2307,11 +2307,11 @@ pub const Value = extern union {
const rhs_bigint = rhs.toBigInt(&rhs_space);
const limbs_q = try allocator.alloc(
std.math.big.Limb,
- lhs_bigint.limbs.len + rhs_bigint.limbs.len + 1,
+ lhs_bigint.limbs.len,
);
const limbs_r = try allocator.alloc(
std.math.big.Limb,
- lhs_bigint.limbs.len,
+ rhs_bigint.limbs.len,
);
const limbs_buffer = try allocator.alloc(
std.math.big.Limb,
@@ -2319,7 +2319,7 @@ pub const Value = extern union {
);
var result_q = BigIntMutable{ .limbs = limbs_q, .positive = undefined, .len = undefined };
var result_r = BigIntMutable{ .limbs = limbs_r, .positive = undefined, .len = undefined };
- result_q.divTrunc(&result_r, lhs_bigint, rhs_bigint, limbs_buffer, null);
+ result_q.divTrunc(&result_r, lhs_bigint, rhs_bigint, limbs_buffer);
const result_limbs = result_q.limbs[0..result_q.len];
if (result_q.positive) {
@@ -2338,11 +2338,11 @@ pub const Value = extern union {
const rhs_bigint = rhs.toBigInt(&rhs_space);
const limbs_q = try allocator.alloc(
std.math.big.Limb,
- lhs_bigint.limbs.len + rhs_bigint.limbs.len + 1,
+ lhs_bigint.limbs.len,
);
const limbs_r = try allocator.alloc(
std.math.big.Limb,
- lhs_bigint.limbs.len,
+ rhs_bigint.limbs.len,
);
const limbs_buffer = try allocator.alloc(
std.math.big.Limb,
@@ -2350,7 +2350,7 @@ pub const Value = extern union {
);
var result_q = BigIntMutable{ .limbs = limbs_q, .positive = undefined, .len = undefined };
var result_r = BigIntMutable{ .limbs = limbs_r, .positive = undefined, .len = undefined };
- result_q.divFloor(&result_r, lhs_bigint, rhs_bigint, limbs_buffer, null);
+ result_q.divFloor(&result_r, lhs_bigint, rhs_bigint, limbs_buffer);
const result_limbs = result_q.limbs[0..result_q.len];
if (result_q.positive) {
@@ -2369,13 +2369,13 @@ pub const Value = extern union {
const rhs_bigint = rhs.toBigInt(&rhs_space);
const limbs_q = try allocator.alloc(
std.math.big.Limb,
- lhs_bigint.limbs.len + rhs_bigint.limbs.len + 1,
+ lhs_bigint.limbs.len,
);
const limbs_r = try allocator.alloc(
std.math.big.Limb,
- // TODO: audit this size, and also consider reworking Sema to re-use Values rather than
+ // TODO: consider reworking Sema to re-use Values rather than
// always producing new Value objects.
- rhs_bigint.limbs.len + 1,
+ rhs_bigint.limbs.len,
);
const limbs_buffer = try allocator.alloc(
std.math.big.Limb,
@@ -2383,7 +2383,7 @@ pub const Value = extern union {
);
var result_q = BigIntMutable{ .limbs = limbs_q, .positive = undefined, .len = undefined };
var result_r = BigIntMutable{ .limbs = limbs_r, .positive = undefined, .len = undefined };
- result_q.divTrunc(&result_r, lhs_bigint, rhs_bigint, limbs_buffer, null);
+ result_q.divTrunc(&result_r, lhs_bigint, rhs_bigint, limbs_buffer);
const result_limbs = result_r.limbs[0..result_r.len];
if (result_r.positive) {
@@ -2402,11 +2402,11 @@ pub const Value = extern union {
const rhs_bigint = rhs.toBigInt(&rhs_space);
const limbs_q = try allocator.alloc(
std.math.big.Limb,
- lhs_bigint.limbs.len + rhs_bigint.limbs.len + 1,
+ lhs_bigint.limbs.len,
);
const limbs_r = try allocator.alloc(
std.math.big.Limb,
- lhs_bigint.limbs.len,
+ rhs_bigint.limbs.len,
);
const limbs_buffer = try allocator.alloc(
std.math.big.Limb,
@@ -2414,7 +2414,7 @@ pub const Value = extern union {
);
var result_q = BigIntMutable{ .limbs = limbs_q, .positive = undefined, .len = undefined };
var result_r = BigIntMutable{ .limbs = limbs_r, .positive = undefined, .len = undefined };
- result_q.divFloor(&result_r, lhs_bigint, rhs_bigint, limbs_buffer, null);
+ result_q.divFloor(&result_r, lhs_bigint, rhs_bigint, limbs_buffer);
const result_limbs = result_r.limbs[0..result_r.len];
if (result_r.positive) {