Library reference

Smaller of two values

Compare two values and return the smaller one.

@min

Simple example

Start3 · 7
Result3
lesson.zig
const std = @import("std");

fn show(value: i64) !void {
    var buffer: [64]u8 = undefined;
    var writer = std.fs.File.stdout().writer(&buffer);
    try writer.interface.print("{d}\n", .{value});
    try writer.interface.flush();
}

pub fn main() !void {
    try show(@min(3, 7));
}
Output
3
Advertisements

Everyday examples

Two buses charge 8 and 5 for the same trip. Which fare is cheaper?

Start8 · 5
Result5
lesson.zig
const std = @import("std");

fn show(value: i64) !void {
    var buffer: [64]u8 = undefined;
    var writer = std.fs.File.stdout().writer(&buffer);
    try writer.interface.print("{d}\n", .{value});
    try writer.interface.flush();
}

pub fn main() !void {
    try show(@min(8, 5));
}
Output
5

A child wants 5 stickers. You have 3 left. How many can you give them?

Start5 · 3
Result3
lesson.zig
const std = @import("std");

fn show(value: i64) !void {
    var buffer: [64]u8 = undefined;
    var writer = std.fs.File.stdout().writer(&buffer);
    try writer.interface.print("{d}\n", .{value});
    try writer.interface.flush();
}

pub fn main() !void {
    try show(@min(5, 3));
}
Output
3

Two walks to school take 12 and 9 minutes. How long is the quicker walk?

Start12 · 9
Result9
lesson.zig
const std = @import("std");

fn show(value: i64) !void {
    var buffer: [64]u8 = undefined;
    var writer = std.fs.File.stdout().writer(&buffer);
    try writer.interface.print("{d}\n", .{value});
    try writer.interface.flush();
}

pub fn main() !void {
    try show(@min(12, 9));
}
Output
9

If both values are equal, the answer is that same value.

Run the example
Terminal
zig run lesson.zig
Official documentation