aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math/complex
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-06-24 16:58:19 -0700
committerGitHub <noreply@github.com>2023-06-24 16:58:19 -0700
commit146b79af153bbd5dafda0ba12a040385c7fc58f8 (patch)
tree67e3db8b444d65c667e314770fc983a7fc8ba293 /lib/std/math/complex
parent13853bef0df3c90633021850cc6d6abaeea03282 (diff)
parent21ac0beb436f49fe49c6982a872f2dc48e4bea5e (diff)
downloadzig-146b79af153bbd5dafda0ba12a040385c7fc58f8.tar.gz
zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.zip
Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty
Infer destination type of cast builtins using result type
Diffstat (limited to 'lib/std/math/complex')
-rw-r--r--lib/std/math/complex/atan.zig4
-rw-r--r--lib/std/math/complex/cosh.zig16
-rw-r--r--lib/std/math/complex/exp.zig16
-rw-r--r--lib/std/math/complex/ldexp.zig24
-rw-r--r--lib/std/math/complex/sinh.zig16
-rw-r--r--lib/std/math/complex/sqrt.zig8
-rw-r--r--lib/std/math/complex/tanh.zig12
7 files changed, 48 insertions, 48 deletions
diff --git a/lib/std/math/complex/atan.zig b/lib/std/math/complex/atan.zig
index 56c199016d..381fc43f7d 100644
--- a/lib/std/math/complex/atan.zig
+++ b/lib/std/math/complex/atan.zig
@@ -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;
}
diff --git a/lib/std/math/complex/cosh.zig b/lib/std/math/complex/cosh.zig
index b3ffab5175..413279db2d 100644
--- a/lib/std/math/complex/cosh.zig
+++ b/lib/std/math/complex/cosh.zig
@@ -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
diff --git a/lib/std/math/complex/exp.zig b/lib/std/math/complex/exp.zig
index 84ee251d0e..4644ea4be7 100644
--- a/lib/std/math/complex/exp.zig
+++ b/lib/std/math/complex/exp.zig
@@ -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) {
diff --git a/lib/std/math/complex/ldexp.zig b/lib/std/math/complex/ldexp.zig
index c196d4afe6..201b6305af 100644
--- a/lib/std/math/complex/ldexp.zig
+++ b/lib/std/math/complex/ldexp.zig
@@ -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,
diff --git a/lib/std/math/complex/sinh.zig b/lib/std/math/complex/sinh.zig
index 9afb7faf30..c9ea0d04fc 100644
--- a/lib/std/math/complex/sinh.zig
+++ b/lib/std/math/complex/sinh.zig
@@ -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) {
diff --git a/lib/std/math/complex/sqrt.zig b/lib/std/math/complex/sqrt.zig
index 456d10aa85..fe2e8e6531 100644
--- a/lib/std/math/complex/sqrt.zig
+++ b/lib/std/math/complex/sqrt.zig
@@ -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))),
);
}
}
diff --git a/lib/std/math/complex/tanh.zig b/lib/std/math/complex/tanh.zig
index 92e197e308..a90f141741 100644
--- a/lib/std/math/complex/tanh.zig
+++ b/lib/std/math/complex/tanh.zig
@@ -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));
}