diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-06-24 16:58:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-24 16:58:19 -0700 |
| commit | 146b79af153bbd5dafda0ba12a040385c7fc58f8 (patch) | |
| tree | 67e3db8b444d65c667e314770fc983a7fc8ba293 /lib/std/math/modf.zig | |
| parent | 13853bef0df3c90633021850cc6d6abaeea03282 (diff) | |
| parent | 21ac0beb436f49fe49c6982a872f2dc48e4bea5e (diff) | |
| download | zig-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/modf.zig')
| -rw-r--r-- | lib/std/math/modf.zig | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/std/math/modf.zig b/lib/std/math/modf.zig index d12c497729..b9d0083e3c 100644 --- a/lib/std/math/modf.zig +++ b/lib/std/math/modf.zig @@ -37,8 +37,8 @@ pub fn modf(x: anytype) modf_result(@TypeOf(x)) { fn modf32(x: f32) modf32_result { var result: modf32_result = undefined; - const u = @bitCast(u32, x); - const e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F; + const u = @as(u32, @bitCast(x)); + const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F; const us = u & 0x80000000; // TODO: Shouldn't need this. @@ -54,26 +54,26 @@ fn modf32(x: f32) modf32_result { if (e == 0x80 and u << 9 != 0) { // nan result.fpart = x; } else { - result.fpart = @bitCast(f32, us); + result.fpart = @as(f32, @bitCast(us)); } return result; } // no integral part if (e < 0) { - result.ipart = @bitCast(f32, us); + result.ipart = @as(f32, @bitCast(us)); result.fpart = x; return result; } - const mask = @as(u32, 0x007FFFFF) >> @intCast(u5, e); + const mask = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e)); if (u & mask == 0) { result.ipart = x; - result.fpart = @bitCast(f32, us); + result.fpart = @as(f32, @bitCast(us)); return result; } - const uf = @bitCast(f32, u & ~mask); + const uf = @as(f32, @bitCast(u & ~mask)); result.ipart = uf; result.fpart = x - uf; return result; @@ -82,8 +82,8 @@ fn modf32(x: f32) modf32_result { fn modf64(x: f64) modf64_result { var result: modf64_result = undefined; - const u = @bitCast(u64, x); - const e = @intCast(i32, (u >> 52) & 0x7FF) - 0x3FF; + const u = @as(u64, @bitCast(x)); + const e = @as(i32, @intCast((u >> 52) & 0x7FF)) - 0x3FF; const us = u & (1 << 63); if (math.isInf(x)) { @@ -98,26 +98,26 @@ fn modf64(x: f64) modf64_result { if (e == 0x400 and u << 12 != 0) { // nan result.fpart = x; } else { - result.fpart = @bitCast(f64, us); + result.fpart = @as(f64, @bitCast(us)); } return result; } // no integral part if (e < 0) { - result.ipart = @bitCast(f64, us); + result.ipart = @as(f64, @bitCast(us)); result.fpart = x; return result; } - const mask = @as(u64, maxInt(u64) >> 12) >> @intCast(u6, e); + const mask = @as(u64, maxInt(u64) >> 12) >> @as(u6, @intCast(e)); if (u & mask == 0) { result.ipart = x; - result.fpart = @bitCast(f64, us); + result.fpart = @as(f64, @bitCast(us)); return result; } - const uf = @bitCast(f64, u & ~mask); + const uf = @as(f64, @bitCast(u & ~mask)); result.ipart = uf; result.fpart = x - uf; return result; |
