Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › math › big › int › Managed › mul Public Function mul Doc Source Public Function std.math.big.int.Managed.mul
pub fn mul (rma : *Managed , a : *const Managed , b : *const Managed ) !void Params File math/big/int.zig: 3259
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278 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 ;
const needed = a .len () + b .len () + 1 ;
const capacity_alias = limbsAliasDistinct (rma , a ) or limbsAliasDistinct (rma , b );
try rma .ensureAliasAwareCapacity (needed , capacity_alias );
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 );
}
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.