diff options
| author | Robin Voetter <robin@voetter.nl> | 2021-12-18 04:42:13 +0100 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2021-12-21 01:41:51 +0100 |
| commit | f3d635b6683ba4a53f82ae8087b1cf78552abac5 (patch) | |
| tree | bd038a7404df4e79170915e07528694768f44f7c /test/behavior/math.zig | |
| parent | 28bcd7dbdda7fb2c2fe80dbdb5981479a04e973a (diff) | |
| download | zig-f3d635b6683ba4a53f82ae8087b1cf78552abac5.tar.gz zig-f3d635b6683ba4a53f82ae8087b1cf78552abac5.zip | |
stage2: @addWithOverflow
Diffstat (limited to 'test/behavior/math.zig')
| -rw-r--r-- | test/behavior/math.zig | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/behavior/math.zig b/test/behavior/math.zig index 1073183a3c..2cd67854af 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -444,3 +444,30 @@ test "128-bit multiplication" { var c = a * b; try expect(c == 6); } + +test "@addWithOverflow" { + var result: u8 = undefined; + try expect(@addWithOverflow(u8, 250, 100, &result)); + try expect(result == 94); + try expect(!@addWithOverflow(u8, 100, 150, &result)); + try expect(result == 250); +} + +test "small int addition" { + var x: u2 = 0; + try expect(x == 0); + + x += 1; + try expect(x == 1); + + x += 1; + try expect(x == 2); + + x += 1; + try expect(x == 3); + + var result: @TypeOf(x) = 3; + try expect(@addWithOverflow(@TypeOf(x), x, 1, &result)); + + try expect(result == 0); +} |
