diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2022-12-20 21:31:44 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-12-21 03:04:59 -0500 |
| commit | a52dcdd3c5ebd3a1d5a0189ded830dadd253193c (patch) | |
| tree | 80bd063b2e762914a87bde8a393281ce0864a06a /test | |
| parent | 471f3c470fdeb00596ebd0d045a5b0dab737947d (diff) | |
| download | zig-a52dcdd3c5ebd3a1d5a0189ded830dadd253193c.tar.gz zig-a52dcdd3c5ebd3a1d5a0189ded830dadd253193c.zip | |
CBE: fix bitwise not
Closes #13911
Diffstat (limited to 'test')
| -rw-r--r-- | test/behavior/math.zig | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/behavior/math.zig b/test/behavior/math.zig index d819743390..763c249c50 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -532,6 +532,19 @@ fn testUnsignedNegationWrappingEval(x: u16) !void { try expect(neg == maxInt(u16)); } +test "negation wrapping" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + + try expectEqual(@as(u1, 1), negateWrap(u1, 1)); +} + +fn negateWrap(comptime T: type, x: T) T { + // This is specifically testing a safety-checked add, so + // special case minInt(T) which would overflow otherwise. + return if (x == minInt(T)) minInt(T) else ~x + 1; +} + test "unsigned 64-bit division" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
