Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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. Public Function

sqr

Public Function
std.math.big.int.Managed.sqr
pub fn sqr(rma: *Managed, a: *const Managed) !void

r = a * a

Params

File

math/big/int.zig:3520
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
    pub fn sqr(rma: *Managed, a: *const Managed) !void {
        const needed_limbs = 2 * a.len() + 1;
        const capacity_alias = limbsAliasDistinct(rma, a);
        const same_buffer = rma.limbs.ptr == a.limbs.ptr;
        try rma.ensureAliasAwareCapacity(needed_limbs, capacity_alias);

        if (same_buffer) {
            const a_len = a.len();
            const tmp = try rma.allocator.alloc(Limb, a_len);
            defer rma.allocator.free(tmp);
            @memcpy(tmp[0..a_len], a.limbs[0..a_len]);
            const a_const: Const = .{ .limbs = tmp[0..a_len], .positive = a.isPositive() };
            var rma_mut = rma.toMutable();
            rma_mut.sqrNoAlias(a_const, rma.allocator);
            rma.setMetadata(rma_mut.positive, rma_mut.len);
        } else {
            var rma_mut = rma.toMutable();
            rma_mut.sqrNoAlias(a.toConst(), rma.allocator);
            rma.setMetadata(rma_mut.positive, rma_mut.len);
        }
    }