Function mul [src]
rma = a * b
rma, a and b may be aliases. However, it is more efficient if rma does not alias a or b.
Returns an error if memory could not be allocated.
rma's allocator is used for temporary storage to speed up the multiplication.
Prototype
pub fn mul(rma: *Managed, a: *const Managed, b: *const Managed) !void
Parameters
rma: *Managed
a: *const Managed
b: *const Managed
Source
pub fn mul(rma: *Managed, a: *const Managed, b: *const Managed) !void {
var alias_count: usize = 0;
if (rma.limbs.ptr == a.limbs.ptr)
alias_count += 1;
if (rma.limbs.ptr == b.limbs.ptr)
alias_count += 1;
try rma.ensureMulCapacity(a.toConst(), b.toConst());
var m = rma.toMutable();
if (alias_count == 0) {
m.mulNoAlias(a.toConst(), b.toConst(), rma.allocator);
} else {
const limb_count = calcMulLimbsBufferLen(a.len(), b.len(), alias_count);
const limbs_buffer = try rma.allocator.alloc(Limb, limb_count);
defer rma.allocator.free(limbs_buffer);
m.mul(a.toConst(), b.toConst(), limbs_buffer, rma.allocator);
}
rma.setMetadata(m.positive, m.len);
}