all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
This commit is contained in:
@@ -391,11 +391,11 @@ test "binary not 128-bit" {
|
||||
break :x ~@as(u128, 0x55555555_55555555_55555555_55555555) == 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa;
|
||||
});
|
||||
try expect(comptime x: {
|
||||
break :x ~@as(i128, 0x55555555_55555555_55555555_55555555) == @bitCast(i128, @as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa));
|
||||
break :x ~@as(i128, 0x55555555_55555555_55555555_55555555) == @as(i128, @bitCast(@as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa)));
|
||||
});
|
||||
|
||||
try testBinaryNot128(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa);
|
||||
try testBinaryNot128(i128, @bitCast(i128, @as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa)));
|
||||
try testBinaryNot128(i128, @as(i128, @bitCast(@as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa))));
|
||||
}
|
||||
|
||||
fn testBinaryNot128(comptime Type: type, x: Type) !void {
|
||||
@@ -1156,29 +1156,29 @@ test "quad hex float literal parsing accurate" {
|
||||
|
||||
// implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.
|
||||
const expected: u128 = 0x3fff1111222233334444555566667777;
|
||||
try expect(@bitCast(u128, a) == expected);
|
||||
try expect(@as(u128, @bitCast(a)) == expected);
|
||||
|
||||
// non-normalized
|
||||
const b: f128 = 0x11.111222233334444555566667777p-4;
|
||||
try expect(@bitCast(u128, b) == expected);
|
||||
try expect(@as(u128, @bitCast(b)) == expected);
|
||||
|
||||
const S = struct {
|
||||
fn doTheTest() !void {
|
||||
{
|
||||
var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;
|
||||
try expect(@bitCast(u128, f) == 0x40042eab345678439abcdefea5678234);
|
||||
try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234);
|
||||
}
|
||||
{
|
||||
var f: f128 = 0x1.edcb34a235253948765432134674fp-1;
|
||||
try expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134675); // round-to-even
|
||||
try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even
|
||||
}
|
||||
{
|
||||
var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;
|
||||
try expect(@bitCast(u128, f) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
|
||||
try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
|
||||
}
|
||||
{
|
||||
var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;
|
||||
try expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568);
|
||||
try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568);
|
||||
}
|
||||
const exp2ft = [_]f64{
|
||||
0x1.6a09e667f3bcdp-1,
|
||||
@@ -1233,7 +1233,7 @@ test "quad hex float literal parsing accurate" {
|
||||
};
|
||||
|
||||
for (exp2ft, 0..) |x, i| {
|
||||
try expect(@bitCast(u64, x) == answers[i]);
|
||||
try expect(@as(u64, @bitCast(x)) == answers[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1586,7 +1586,7 @@ test "signed zeros are represented properly" {
|
||||
fn testOne(comptime T: type) !void {
|
||||
const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
|
||||
var as_fp_val = -@as(T, 0.0);
|
||||
var as_uint_val = @bitCast(ST, as_fp_val);
|
||||
var as_uint_val = @as(ST, @bitCast(as_fp_val));
|
||||
// Ensure the sign bit is set.
|
||||
try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user