aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/math.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2021-12-18 04:42:13 +0100
committerRobin Voetter <robin@voetter.nl>2021-12-21 01:41:51 +0100
commitf3d635b6683ba4a53f82ae8087b1cf78552abac5 (patch)
treebd038a7404df4e79170915e07528694768f44f7c /test/behavior/math.zig
parent28bcd7dbdda7fb2c2fe80dbdb5981479a04e973a (diff)
downloadzig-f3d635b6683ba4a53f82ae8087b1cf78552abac5.tar.gz
zig-f3d635b6683ba4a53f82ae8087b1cf78552abac5.zip
stage2: @addWithOverflow
Diffstat (limited to 'test/behavior/math.zig')
-rw-r--r--test/behavior/math.zig27
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);
+}