aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fmt/parse_float.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-11-08 18:30:07 -0500
committerGitHub <noreply@github.com>2019-11-08 18:30:07 -0500
commit6d5abf87ecd3509c6fb8b9c917b73b4db2ae59ff (patch)
treefcf1f309750159e579bdf99e2f7646c3bbd8a1a9 /lib/std/fmt/parse_float.zig
parent6d28b28ccc689e6bf8849b1d39e969e8da760999 (diff)
parentf7b1e02158550a8df3c189299da88568b381f5b1 (diff)
downloadzig-6d5abf87ecd3509c6fb8b9c917b73b4db2ae59ff.tar.gz
zig-6d5abf87ecd3509c6fb8b9c917b73b4db2ae59ff.zip
Merge pull request #3628 from ziglang/as-builtin
implement `@as` builtin and fix result location semantics with regards to type coercion
Diffstat (limited to 'lib/std/fmt/parse_float.zig')
-rw-r--r--lib/std/fmt/parse_float.zig20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/std/fmt/parse_float.zig b/lib/std/fmt/parse_float.zig
index 9a35e27c21..78ce0b7d0a 100644
--- a/lib/std/fmt/parse_float.zig
+++ b/lib/std/fmt/parse_float.zig
@@ -59,29 +59,29 @@ const Z96 = struct {
// d += s
inline fn add(d: *Z96, s: Z96) void {
- var w = u64(d.d0) + u64(s.d0);
+ var w = @as(u64, d.d0) + @as(u64, s.d0);
d.d0 = @truncate(u32, w);
w >>= 32;
- w += u64(d.d1) + u64(s.d1);
+ w += @as(u64, d.d1) + @as(u64, s.d1);
d.d1 = @truncate(u32, w);
w >>= 32;
- w += u64(d.d2) + u64(s.d2);
+ w += @as(u64, d.d2) + @as(u64, s.d2);
d.d2 = @truncate(u32, w);
}
// d -= s
inline fn sub(d: *Z96, s: Z96) void {
- var w = u64(d.d0) -% u64(s.d0);
+ var w = @as(u64, d.d0) -% @as(u64, s.d0);
d.d0 = @truncate(u32, w);
w >>= 32;
- w += u64(d.d1) -% u64(s.d1);
+ w += @as(u64, d.d1) -% @as(u64, s.d1);
d.d1 = @truncate(u32, w);
w >>= 32;
- w += u64(d.d2) -% u64(s.d2);
+ w += @as(u64, d.d2) -% @as(u64, s.d2);
d.d2 = @truncate(u32, w);
}
};
@@ -160,7 +160,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T {
break :blk if (n.negative) f64_minus_zero else f64_plus_zero;
} else if (s.d2 != 0) {
const binexs2 = @intCast(u64, binary_exponent) << 52;
- const rr = (u64(s.d2 & ~mask28) << 24) | ((u64(s.d1) + 128) >> 8) | binexs2;
+ const rr = (@as(u64, s.d2 & ~mask28) << 24) | ((@as(u64, s.d1) + 128) >> 8) | binexs2;
break :blk if (n.negative) rr | (1 << 63) else rr;
} else {
break :blk 0;
@@ -375,7 +375,7 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
return switch (try parseRepr(s, &r)) {
ParseResult.Ok => convertRepr(T, r),
ParseResult.PlusZero => 0.0,
- ParseResult.MinusZero => -T(0.0),
+ ParseResult.MinusZero => -@as(T, 0.0),
ParseResult.PlusInf => std.math.inf(T),
ParseResult.MinusInf => -std.math.inf(T),
};
@@ -426,8 +426,8 @@ test "fmt.parseFloat" {
expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
- expect(approxEq(T, try parseFloat(T, "-123142.1124"), T(-123142.1124), epsilon));
- expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), T(0.7062146892655368), epsilon));
+ expect(approxEq(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
+ expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
}
}
}