Library reference

Larger of two values

Compare two values and return the larger one.

@max

Simple example

Start3 · 7
Result7
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(@max(3, 7));
}
Output
7
Advertisements

Everyday examples

Two rooms are at 18 and 22 degrees. What is the warmer reading?

Start18 · 22
Result22
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(@max(18, 22));
}
Output
22

Two friends arrive after 7 and 11 minutes. When will both be there?

Start7 · 11
Result11
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(@max(7, 11));
}
Output
11

Two shelves are 90 and 75 cm tall. How tall is the taller shelf?

Start90 · 75
Result90
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(@max(90, 75));
}
Output
90

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

Run the example
Terminal
zig run lesson.zig
Official documentation