diff options
| author | Robin Voetter <robin@voetter.nl> | 2021-10-23 21:03:19 +0200 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2021-10-24 01:21:33 +0200 |
| commit | 87b7b31557b182411f22b613aec7cbf7396972fe (patch) | |
| tree | de43b88b2d88762a0d66b7e03ff13331f02c2089 /src/value.zig | |
| parent | ee98d8700818aa667137e3aa580b16df2ba6d680 (diff) | |
| download | zig-87b7b31557b182411f22b613aec7cbf7396972fe.tar.gz zig-87b7b31557b182411f22b613aec7cbf7396972fe.zip | |
big ints: improve division
Diffstat (limited to 'src/value.zig')
| -rw-r--r-- | src/value.zig | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/value.zig b/src/value.zig index 3a4cdb1438..15970390ba 100644 --- a/src/value.zig +++ b/src/value.zig @@ -2301,11 +2301,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 + rhs_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, @@ -2313,7 +2313,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) { @@ -2332,11 +2332,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 + rhs_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, @@ -2344,7 +2344,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) { @@ -2363,13 +2363,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 + rhs_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, @@ -2377,7 +2377,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) { @@ -2396,11 +2396,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 + rhs_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, @@ -2408,7 +2408,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) { |
