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 library itself.

floatRoundOp

AstGen.floatRoundOp
fn floatRoundOp(
    gz: *GenZir,
    scope: *Scope,
    ri: ResultInfo,
    node: Ast.Node.Index,
    operand_node: Ast.Node.Index,
    float_tag: Zir.Inst.Tag,
) InnerError!Zir.Inst.Ref

File

lib/std/zig/AstGen.zig:9760

Code

fn floatRoundOp(
    gz: *GenZir,
    scope: *Scope,
    ri: ResultInfo,
    node: Ast.Node.Index,
    operand_node: Ast.Node.Index,
    float_tag: Zir.Inst.Tag,
) InnerError!Zir.Inst.Ref {
    if (try ri.rl.resultType(gz, node)) |dest_type| {
        const cursor = maybeAdvanceSourceCursorToMainToken(gz, node);

        const operand_ty_inst = try gz.addExtendedPayload(.round_op_ty, Zir.Inst.UnNode{
            .node = gz.nodeIndexToRelative(node),
            .operand = dest_type,
        });

        const operand = try expr(gz, scope, .{ .rl = .{ .coerced_ty = operand_ty_inst } }, operand_node);

        try emitDbgStmt(gz, cursor);
        const round_op: Zir.Inst.RoundOp = switch (float_tag) {
            .round => .round,
            .floor => .floor,
            .ceil => .ceil,
            .trunc => .trunc,
            else => unreachable,
        };
        const result = try gz.addExtendedPayloadSmall(.round_op, @backingInt(round_op), Zir.Inst.BinNode{
            .node = gz.nodeIndexToRelative(node),
            .lhs = dest_type,
            .rhs = operand,
        });
        return rvalue(gz, ri, result, node);
    } else {
        return floatUnOp(gz, scope, ri, node, operand_node, float_tag);
    }
}