From 3e667fd2925274c674bddfd2d3f67f6edd1bf72b Mon Sep 17 00:00:00 2001 From: Hiroaki Nakamura Date: Sat, 16 Jul 2022 11:46:13 +0900 Subject: [PATCH] Use Managed.len in sub, divFloor, and divTrunc too --- lib/std/math/big/int.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index cf6dad23b6..2a141ac243 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -2719,7 +2719,7 @@ pub const Managed = struct { /// /// Returns an error if memory could not be allocated. pub fn sub(r: *Managed, a: *const Managed, b: *const Managed) !void { - try r.ensureCapacity(math.max(a.limbs.len, b.limbs.len) + 1); + try r.ensureCapacity(math.max(a.len(), b.len()) + 1); var m = r.toMutable(); m.sub(a.toConst(), b.toConst()); r.setMetadata(m.positive, m.len); @@ -2813,7 +2813,7 @@ pub const Managed = struct { if (alias_count == 0) { m.mulWrapNoAlias(a.toConst(), b.toConst(), signedness, bit_count, rma.allocator); } else { - const limb_count = calcMulWrapLimbsBufferLen(bit_count, a.limbs.len, b.limbs.len, alias_count); + const limb_count = calcMulWrapLimbsBufferLen(bit_count, a.len(), b.len(), alias_count); const limbs_buffer = try rma.allocator.alloc(Limb, limb_count); defer rma.allocator.free(limbs_buffer); m.mulWrap(a.toConst(), b.toConst(), signedness, bit_count, limbs_buffer, rma.allocator); @@ -2843,11 +2843,11 @@ pub const Managed = struct { /// /// Returns an error if memory could not be allocated. pub fn divFloor(q: *Managed, r: *Managed, a: *const Managed, b: *const Managed) !void { - try q.ensureCapacity(a.limbs.len); - try r.ensureCapacity(b.limbs.len); + try q.ensureCapacity(a.len()); + try r.ensureCapacity(b.len()); var mq = q.toMutable(); var mr = r.toMutable(); - const limbs_buffer = try q.allocator.alloc(Limb, calcDivLimbsBufferLen(a.limbs.len, b.limbs.len)); + const limbs_buffer = try q.allocator.alloc(Limb, calcDivLimbsBufferLen(a.len(), b.len())); defer q.allocator.free(limbs_buffer); mq.divFloor(&mr, a.toConst(), b.toConst(), limbs_buffer); q.setMetadata(mq.positive, mq.len); @@ -2860,11 +2860,11 @@ pub const Managed = struct { /// /// Returns an error if memory could not be allocated. pub fn divTrunc(q: *Managed, r: *Managed, a: *const Managed, b: *const Managed) !void { - try q.ensureCapacity(a.limbs.len); - try r.ensureCapacity(b.limbs.len); + try q.ensureCapacity(a.len()); + try r.ensureCapacity(b.len()); var mq = q.toMutable(); var mr = r.toMutable(); - const limbs_buffer = try q.allocator.alloc(Limb, calcDivLimbsBufferLen(a.limbs.len, b.limbs.len)); + const limbs_buffer = try q.allocator.alloc(Limb, calcDivLimbsBufferLen(a.len(), b.len())); defer q.allocator.free(limbs_buffer); mq.divTrunc(&mr, a.toConst(), b.toConst(), limbs_buffer); q.setMetadata(mq.positive, mq.len);