mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 15:42:49 +00:00
619140c0d2
When a signed integer's bitsize is not 32 or 64, but the given bitsize and wanted bitsize are either both represented by Wasm's i32 or i64, we must either sign extend or wrap the integer.
32 lines
1.1 KiB
Zig
32 lines
1.1 KiB
Zig
const builtin = @import("builtin");
|
|
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
const maxInt = std.math.maxInt;
|
|
|
|
test "@intCast i32 to u7" {
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
|
|
var x: u128 = maxInt(u128);
|
|
var y: i32 = 120;
|
|
var z = x >> @as(u7, @intCast(y));
|
|
try expect(z == 0xff);
|
|
}
|
|
|
|
test "coerce i8 to i32 and @intCast back" {
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
|
|
var x: i8 = -5;
|
|
var y: i32 = -5;
|
|
try expect(y == x);
|
|
|
|
var x2: i32 = -5;
|
|
var y2: i8 = -5;
|
|
try expect(y2 == @as(i8, @intCast(x2)));
|
|
}
|