authorgravatar for hnakamur@gmail.comHiroaki Nakamura <hnakamur@gmail.com> 2022-07-16 11:46:13+09:00
committergravatar for hnakamur@gmail.comHiroaki Nakamura <hnakamur@gmail.com> 2022-07-16 11:46:13+09:00
log3e667fd2925274c674bddfd2d3f67f6edd1bf72b
treeddb8453bd5e09089438fec6f31055d7ecb188f05
parent0cee8372cfe31e58eaa66621ac4d2039d4600ce9

Use Managed.len in sub, divFloor, and divTrunc too


1 files changed, 8 insertions(+), 8 deletions(-)

lib/std/math/big/int.zig+8-8
......@@ -2719,7 +2719,7 @@ pub const Managed = struct {
27192719 ///
27202720 /// Returns an error if memory could not be allocated.
27212721 pub fn sub(r: *Managed, a: *const Managed, b: *const Managed) !void {
2722 try r.ensureCapacity(math.max(a.limbs.len, b.limbs.len) + 1);
2722 try r.ensureCapacity(math.max(a.len(), b.len()) + 1);
27232723 var m = r.toMutable();
27242724 m.sub(a.toConst(), b.toConst());
27252725 r.setMetadata(m.positive, m.len);
......@@ -2813,7 +2813,7 @@ pub const Managed = struct {
28132813 if (alias_count == 0) {
28142814 m.mulWrapNoAlias(a.toConst(), b.toConst(), signedness, bit_count, rma.allocator);
28152815 } else {
2816 const limb_count = calcMulWrapLimbsBufferLen(bit_count, a.limbs.len, b.limbs.len, alias_count);
2816 const limb_count = calcMulWrapLimbsBufferLen(bit_count, a.len(), b.len(), alias_count);
28172817 const limbs_buffer = try rma.allocator.alloc(Limb, limb_count);
28182818 defer rma.allocator.free(limbs_buffer);
28192819 m.mulWrap(a.toConst(), b.toConst(), signedness, bit_count, limbs_buffer, rma.allocator);
......@@ -2843,11 +2843,11 @@ pub const Managed = struct {
28432843 ///
28442844 /// Returns an error if memory could not be allocated.
28452845 pub fn divFloor(q: *Managed, r: *Managed, a: *const Managed, b: *const Managed) !void {
2846 try q.ensureCapacity(a.limbs.len);
2847 try r.ensureCapacity(b.limbs.len);
2846 try q.ensureCapacity(a.len());
2847 try r.ensureCapacity(b.len());
28482848 var mq = q.toMutable();
28492849 var mr = r.toMutable();
2850 const limbs_buffer = try q.allocator.alloc(Limb, calcDivLimbsBufferLen(a.limbs.len, b.limbs.len));
2850 const limbs_buffer = try q.allocator.alloc(Limb, calcDivLimbsBufferLen(a.len(), b.len()));
28512851 defer q.allocator.free(limbs_buffer);
28522852 mq.divFloor(&mr, a.toConst(), b.toConst(), limbs_buffer);
28532853 q.setMetadata(mq.positive, mq.len);
......@@ -2860,11 +2860,11 @@ pub const Managed = struct {
28602860 ///
28612861 /// Returns an error if memory could not be allocated.
28622862 pub fn divTrunc(q: *Managed, r: *Managed, a: *const Managed, b: *const Managed) !void {
2863 try q.ensureCapacity(a.limbs.len);
2864 try r.ensureCapacity(b.limbs.len);
2863 try q.ensureCapacity(a.len());
2864 try r.ensureCapacity(b.len());
28652865 var mq = q.toMutable();
28662866 var mr = r.toMutable();
2867 const limbs_buffer = try q.allocator.alloc(Limb, calcDivLimbsBufferLen(a.limbs.len, b.limbs.len));
2867 const limbs_buffer = try q.allocator.alloc(Limb, calcDivLimbsBufferLen(a.len(), b.len()));
28682868 defer q.allocator.free(limbs_buffer);
28692869 mq.divTrunc(&mr, a.toConst(), b.toConst(), limbs_buffer);
28702870 q.setMetadata(mq.positive, mq.len);