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:
mlugg
2023-06-22 18:46:56 +01:00
committed by Andrew Kelley
parent 447ca4e3ff
commit f26dda2117
651 changed files with 8967 additions and 9039 deletions

View File

@@ -32,7 +32,7 @@ fn redupif32(x: f32) f32 {
t -= 0.5;
}
const u = @floatFromInt(f32, @intFromFloat(i32, t));
const u = @as(f32, @floatFromInt(@as(i32, @intFromFloat(t))));
return ((x - u * DP1) - u * DP2) - t * DP3;
}
@@ -81,7 +81,7 @@ fn redupif64(x: f64) f64 {
t -= 0.5;
}
const u = @floatFromInt(f64, @intFromFloat(i64, t));
const u = @as(f64, @floatFromInt(@as(i64, @intFromFloat(t))));
return ((x - u * DP1) - u * DP2) - t * DP3;
}

View File

@@ -26,10 +26,10 @@ fn cosh32(z: Complex(f32)) Complex(f32) {
const x = z.re;
const y = z.im;
const hx = @bitCast(u32, x);
const hx = @as(u32, @bitCast(x));
const ix = hx & 0x7fffffff;
const hy = @bitCast(u32, y);
const hy = @as(u32, @bitCast(y));
const iy = hy & 0x7fffffff;
if (ix < 0x7f800000 and iy < 0x7f800000) {
@@ -89,14 +89,14 @@ fn cosh64(z: Complex(f64)) Complex(f64) {
const x = z.re;
const y = z.im;
const fx = @bitCast(u64, x);
const hx = @intCast(u32, fx >> 32);
const lx = @truncate(u32, fx);
const fx = @as(u64, @bitCast(x));
const hx = @as(u32, @intCast(fx >> 32));
const lx = @as(u32, @truncate(fx));
const ix = hx & 0x7fffffff;
const fy = @bitCast(u64, y);
const hy = @intCast(u32, fy >> 32);
const ly = @truncate(u32, fy);
const fy = @as(u64, @bitCast(y));
const hy = @as(u32, @intCast(fy >> 32));
const ly = @as(u32, @truncate(fy));
const iy = hy & 0x7fffffff;
// nearly non-exceptional case where x, y are finite

View File

@@ -30,13 +30,13 @@ fn exp32(z: Complex(f32)) Complex(f32) {
const x = z.re;
const y = z.im;
const hy = @bitCast(u32, y) & 0x7fffffff;
const hy = @as(u32, @bitCast(y)) & 0x7fffffff;
// cexp(x + i0) = exp(x) + i0
if (hy == 0) {
return Complex(f32).init(@exp(x), y);
}
const hx = @bitCast(u32, x);
const hx = @as(u32, @bitCast(x));
// cexp(0 + iy) = cos(y) + isin(y)
if ((hx & 0x7fffffff) == 0) {
return Complex(f32).init(@cos(y), @sin(y));
@@ -75,18 +75,18 @@ fn exp64(z: Complex(f64)) Complex(f64) {
const x = z.re;
const y = z.im;
const fy = @bitCast(u64, y);
const hy = @intCast(u32, (fy >> 32) & 0x7fffffff);
const ly = @truncate(u32, fy);
const fy = @as(u64, @bitCast(y));
const hy = @as(u32, @intCast((fy >> 32) & 0x7fffffff));
const ly = @as(u32, @truncate(fy));
// cexp(x + i0) = exp(x) + i0
if (hy | ly == 0) {
return Complex(f64).init(@exp(x), y);
}
const fx = @bitCast(u64, x);
const hx = @intCast(u32, fx >> 32);
const lx = @truncate(u32, fx);
const fx = @as(u64, @bitCast(x));
const hx = @as(u32, @intCast(fx >> 32));
const lx = @as(u32, @truncate(fx));
// cexp(0 + iy) = cos(y) + isin(y)
if ((hx & 0x7fffffff) | lx == 0) {

View File

@@ -27,10 +27,10 @@ fn frexp_exp32(x: f32, expt: *i32) f32 {
const kln2 = 162.88958740; // k * ln2
const exp_x = @exp(x - kln2);
const hx = @bitCast(u32, exp_x);
const hx = @as(u32, @bitCast(exp_x));
// TODO zig should allow this cast implicitly because it should know the value is in range
expt.* = @intCast(i32, hx >> 23) - (0x7f + 127) + k;
return @bitCast(f32, (hx & 0x7fffff) | ((0x7f + 127) << 23));
expt.* = @as(i32, @intCast(hx >> 23)) - (0x7f + 127) + k;
return @as(f32, @bitCast((hx & 0x7fffff) | ((0x7f + 127) << 23)));
}
fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {
@@ -39,10 +39,10 @@ fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {
const exptf = expt + ex_expt;
const half_expt1 = @divTrunc(exptf, 2);
const scale1 = @bitCast(f32, (0x7f + half_expt1) << 23);
const scale1 = @as(f32, @bitCast((0x7f + half_expt1) << 23));
const half_expt2 = exptf - half_expt1;
const scale2 = @bitCast(f32, (0x7f + half_expt2) << 23);
const scale2 = @as(f32, @bitCast((0x7f + half_expt2) << 23));
return Complex(f32).init(
@cos(z.im) * exp_x * scale1 * scale2,
@@ -56,14 +56,14 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
const exp_x = @exp(x - kln2);
const fx = @bitCast(u64, exp_x);
const hx = @intCast(u32, fx >> 32);
const lx = @truncate(u32, fx);
const fx = @as(u64, @bitCast(exp_x));
const hx = @as(u32, @intCast(fx >> 32));
const lx = @as(u32, @truncate(fx));
expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k;
expt.* = @as(i32, @intCast(hx >> 20)) - (0x3ff + 1023) + k;
const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20);
return @bitCast(f64, (@as(u64, high_word) << 32) | lx);
return @as(f64, @bitCast((@as(u64, high_word) << 32) | lx));
}
fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
@@ -72,10 +72,10 @@ fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
const exptf = @as(i64, expt + ex_expt);
const half_expt1 = @divTrunc(exptf, 2);
const scale1 = @bitCast(f64, (0x3ff + half_expt1) << (20 + 32));
const scale1 = @as(f64, @bitCast((0x3ff + half_expt1) << (20 + 32)));
const half_expt2 = exptf - half_expt1;
const scale2 = @bitCast(f64, (0x3ff + half_expt2) << (20 + 32));
const scale2 = @as(f64, @bitCast((0x3ff + half_expt2) << (20 + 32)));
return Complex(f64).init(
@cos(z.im) * exp_x * scale1 * scale2,

View File

@@ -26,10 +26,10 @@ fn sinh32(z: Complex(f32)) Complex(f32) {
const x = z.re;
const y = z.im;
const hx = @bitCast(u32, x);
const hx = @as(u32, @bitCast(x));
const ix = hx & 0x7fffffff;
const hy = @bitCast(u32, y);
const hy = @as(u32, @bitCast(y));
const iy = hy & 0x7fffffff;
if (ix < 0x7f800000 and iy < 0x7f800000) {
@@ -89,14 +89,14 @@ fn sinh64(z: Complex(f64)) Complex(f64) {
const x = z.re;
const y = z.im;
const fx = @bitCast(u64, x);
const hx = @intCast(u32, fx >> 32);
const lx = @truncate(u32, fx);
const fx = @as(u64, @bitCast(x));
const hx = @as(u32, @intCast(fx >> 32));
const lx = @as(u32, @truncate(fx));
const ix = hx & 0x7fffffff;
const fy = @bitCast(u64, y);
const hy = @intCast(u32, fy >> 32);
const ly = @truncate(u32, fy);
const fy = @as(u64, @bitCast(y));
const hy = @as(u32, @intCast(fy >> 32));
const ly = @as(u32, @truncate(fy));
const iy = hy & 0x7fffffff;
if (ix < 0x7ff00000 and iy < 0x7ff00000) {

View File

@@ -58,14 +58,14 @@ fn sqrt32(z: Complex(f32)) Complex(f32) {
if (dx >= 0) {
const t = @sqrt((dx + math.hypot(f64, dx, dy)) * 0.5);
return Complex(f32).init(
@floatCast(f32, t),
@floatCast(f32, dy / (2.0 * t)),
@as(f32, @floatCast(t)),
@as(f32, @floatCast(dy / (2.0 * t))),
);
} else {
const t = @sqrt((-dx + math.hypot(f64, dx, dy)) * 0.5);
return Complex(f32).init(
@floatCast(f32, @fabs(y) / (2.0 * t)),
@floatCast(f32, math.copysign(t, y)),
@as(f32, @floatCast(@fabs(y) / (2.0 * t))),
@as(f32, @floatCast(math.copysign(t, y))),
);
}
}

View File

@@ -24,7 +24,7 @@ fn tanh32(z: Complex(f32)) Complex(f32) {
const x = z.re;
const y = z.im;
const hx = @bitCast(u32, x);
const hx = @as(u32, @bitCast(x));
const ix = hx & 0x7fffffff;
if (ix >= 0x7f800000) {
@@ -32,7 +32,7 @@ fn tanh32(z: Complex(f32)) Complex(f32) {
const r = if (y == 0) y else x * y;
return Complex(f32).init(x, r);
}
const xx = @bitCast(f32, hx - 0x40000000);
const xx = @as(f32, @bitCast(hx - 0x40000000));
const r = if (math.isInf(y)) y else @sin(y) * @cos(y);
return Complex(f32).init(xx, math.copysign(@as(f32, 0.0), r));
}
@@ -62,11 +62,11 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
const x = z.re;
const y = z.im;
const fx = @bitCast(u64, x);
const fx = @as(u64, @bitCast(x));
// TODO: zig should allow this conversion implicitly because it can notice that the value necessarily
// fits in range.
const hx = @intCast(u32, fx >> 32);
const lx = @truncate(u32, fx);
const hx = @as(u32, @intCast(fx >> 32));
const lx = @as(u32, @truncate(fx));
const ix = hx & 0x7fffffff;
if (ix >= 0x7ff00000) {
@@ -75,7 +75,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
return Complex(f64).init(x, r);
}
const xx = @bitCast(f64, (@as(u64, hx - 0x40000000) << 32) | lx);
const xx = @as(f64, @bitCast((@as(u64, hx - 0x40000000) << 32) | lx));
const r = if (math.isInf(y)) y else @sin(y) * @cos(y);
return Complex(f64).init(xx, math.copysign(@as(f64, 0.0), r));
}