aboutsummaryrefslogtreecommitdiff
path: root/doc/langref/test_wraparound_semantics.zig
blob: 491b0907f678b617ad55ad65d703dc1835f5bd14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const std = @import("std");
const expect = std.testing.expect;
const minInt = std.math.minInt;
const maxInt = std.math.maxInt;

test "wraparound addition and subtraction" {
    const x: i32 = maxInt(i32);
    const min_val = x +% 1;
    try expect(min_val == minInt(i32));
    const max_val = min_val -% 1;
    try expect(max_val == maxInt(i32));
}

// test