aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fmt
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/fmt
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/fmt')
-rw-r--r--lib/std/fmt/errol.zig98
-rw-r--r--lib/std/fmt/parse_float.zig2
-rw-r--r--lib/std/fmt/parse_float/common.zig10
-rw-r--r--lib/std/fmt/parse_float/convert_eisel_lemire.zig16
-rw-r--r--lib/std/fmt/parse_float/convert_fast.zig10
-rw-r--r--lib/std/fmt/parse_float/convert_hex.zig2
-rw-r--r--lib/std/fmt/parse_float/convert_slow.zig12
-rw-r--r--lib/std/fmt/parse_float/decimal.zig20
-rw-r--r--lib/std/fmt/parse_float/parse.zig14
9 files changed, 92 insertions, 92 deletions
diff --git a/lib/std/fmt/errol.zig b/lib/std/fmt/errol.zig
index b438733589..af686d6448 100644
--- a/lib/std/fmt/errol.zig
+++ b/lib/std/fmt/errol.zig
@@ -29,11 +29,11 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro
switch (mode) {
RoundMode.Decimal => {
if (float_decimal.exp >= 0) {
- round_digit = precision + @intCast(usize, float_decimal.exp);
+ round_digit = precision + @as(usize, @intCast(float_decimal.exp));
} else {
// if a small negative exp, then adjust we need to offset by the number
// of leading zeros that will occur.
- const min_exp_required = @intCast(usize, -float_decimal.exp);
+ const min_exp_required = @as(usize, @intCast(-float_decimal.exp));
if (precision > min_exp_required) {
round_digit = precision - min_exp_required;
}
@@ -59,7 +59,7 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro
float_decimal.exp += 1;
// Re-size the buffer to use the reserved leading byte.
- const one_before = @ptrFromInt([*]u8, @intFromPtr(&float_decimal.digits[0]) - 1);
+ const one_before = @as([*]u8, @ptrFromInt(@intFromPtr(&float_decimal.digits[0]) - 1));
float_decimal.digits = one_before[0 .. float_decimal.digits.len + 1];
float_decimal.digits[0] = '1';
return;
@@ -80,7 +80,7 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro
/// Corrected Errol3 double to ASCII conversion.
pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
- const bits = @bitCast(u64, value);
+ const bits = @as(u64, @bitCast(value));
const i = tableLowerBound(bits);
if (i < enum3.len and enum3[i] == bits) {
const data = enum3_data[i];
@@ -113,16 +113,16 @@ fn errolSlow(val: f64, buffer: []u8) FloatDecimal {
// normalize the midpoint
const e = math.frexp(val).exponent;
- var exp = @intFromFloat(i16, @floor(307 + @floatFromInt(f64, e) * 0.30103));
+ var exp = @as(i16, @intFromFloat(@floor(307 + @as(f64, @floatFromInt(e)) * 0.30103)));
if (exp < 20) {
exp = 20;
- } else if (@intCast(usize, exp) >= lookup_table.len) {
- exp = @intCast(i16, lookup_table.len - 1);
+ } else if (@as(usize, @intCast(exp)) >= lookup_table.len) {
+ exp = @as(i16, @intCast(lookup_table.len - 1));
}
- var mid = lookup_table[@intCast(usize, exp)];
+ var mid = lookup_table[@as(usize, @intCast(exp))];
mid = hpProd(mid, val);
- const lten = lookup_table[@intCast(usize, exp)].val;
+ const lten = lookup_table[@as(usize, @intCast(exp))].val;
exp -= 307;
@@ -171,25 +171,25 @@ fn errolSlow(val: f64, buffer: []u8) FloatDecimal {
var buf_index: usize = 0;
const bound = buffer.len - 1;
while (buf_index < bound) {
- var hdig = @intFromFloat(u8, @floor(high.val));
- if ((high.val == @floatFromInt(f64, hdig)) and (high.off < 0)) hdig -= 1;
+ var hdig = @as(u8, @intFromFloat(@floor(high.val)));
+ if ((high.val == @as(f64, @floatFromInt(hdig))) and (high.off < 0)) hdig -= 1;
- var ldig = @intFromFloat(u8, @floor(low.val));
- if ((low.val == @floatFromInt(f64, ldig)) and (low.off < 0)) ldig -= 1;
+ var ldig = @as(u8, @intFromFloat(@floor(low.val)));
+ if ((low.val == @as(f64, @floatFromInt(ldig))) and (low.off < 0)) ldig -= 1;
if (ldig != hdig) break;
buffer[buf_index] = hdig + '0';
buf_index += 1;
- high.val -= @floatFromInt(f64, hdig);
- low.val -= @floatFromInt(f64, ldig);
+ high.val -= @as(f64, @floatFromInt(hdig));
+ low.val -= @as(f64, @floatFromInt(ldig));
hpMul10(&high);
hpMul10(&low);
}
const tmp = (high.val + low.val) / 2.0;
- var mdig = @intFromFloat(u8, @floor(tmp + 0.5));
- if ((@floatFromInt(f64, mdig) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1;
+ var mdig = @as(u8, @intFromFloat(@floor(tmp + 0.5)));
+ if ((@as(f64, @floatFromInt(mdig)) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1;
buffer[buf_index] = mdig + '0';
buf_index += 1;
@@ -248,9 +248,9 @@ fn split(val: f64, hi: *f64, lo: *f64) void {
}
fn gethi(in: f64) f64 {
- const bits = @bitCast(u64, in);
+ const bits = @as(u64, @bitCast(in));
const new_bits = bits & 0xFFFFFFFFF8000000;
- return @bitCast(f64, new_bits);
+ return @as(f64, @bitCast(new_bits));
}
/// Normalize the number by factoring in the error.
@@ -303,21 +303,21 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));
- var mid = @intFromFloat(u128, val);
+ var mid = @as(u128, @intFromFloat(val));
var low: u128 = mid - fpeint((fpnext(val) - val) / 2.0);
var high: u128 = mid + fpeint((val - fpprev(val)) / 2.0);
- if (@bitCast(u64, val) & 0x1 != 0) {
+ if (@as(u64, @bitCast(val)) & 0x1 != 0) {
high -= 1;
} else {
low -= 1;
}
- var l64 = @intCast(u64, low % pow19);
- const lf = @intCast(u64, (low / pow19) % pow19);
+ var l64 = @as(u64, @intCast(low % pow19));
+ const lf = @as(u64, @intCast((low / pow19) % pow19));
- var h64 = @intCast(u64, high % pow19);
- const hf = @intCast(u64, (high / pow19) % pow19);
+ var h64 = @as(u64, @intCast(high % pow19));
+ const hf = @as(u64, @intCast((high / pow19) % pow19));
if (lf != hf) {
l64 = lf;
@@ -333,7 +333,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
x *= 10;
}
}
- const m64 = @truncate(u64, @divTrunc(mid, x));
+ const m64 = @as(u64, @truncate(@divTrunc(mid, x)));
if (lf != hf) mi += 19;
@@ -349,7 +349,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
return FloatDecimal{
.digits = buffer[0..buf_index],
- .exp = @intCast(i32, buf_index) + mi,
+ .exp = @as(i32, @intCast(buf_index)) + mi,
};
}
@@ -360,33 +360,33 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
assert((val >= 16.0) and (val < 9.007199254740992e15));
- const u = @intFromFloat(u64, val);
- const n = @floatFromInt(f64, u);
+ const u = @as(u64, @intFromFloat(val));
+ const n = @as(f64, @floatFromInt(u));
var mid = val - n;
var lo = ((fpprev(val) - n) + mid) / 2.0;
var hi = ((fpnext(val) - n) + mid) / 2.0;
var buf_index = u64toa(u, buffer);
- var exp = @intCast(i32, buf_index);
+ var exp = @as(i32, @intCast(buf_index));
var j = buf_index;
buffer[j] = 0;
if (mid != 0.0) {
while (mid != 0.0) {
lo *= 10.0;
- const ldig = @intFromFloat(i32, lo);
- lo -= @floatFromInt(f64, ldig);
+ const ldig = @as(i32, @intFromFloat(lo));
+ lo -= @as(f64, @floatFromInt(ldig));
mid *= 10.0;
- const mdig = @intFromFloat(i32, mid);
- mid -= @floatFromInt(f64, mdig);
+ const mdig = @as(i32, @intFromFloat(mid));
+ mid -= @as(f64, @floatFromInt(mdig));
hi *= 10.0;
- const hdig = @intFromFloat(i32, hi);
- hi -= @floatFromInt(f64, hdig);
+ const hdig = @as(i32, @intFromFloat(hi));
+ hi -= @as(f64, @floatFromInt(hdig));
- buffer[j] = @intCast(u8, mdig + '0');
+ buffer[j] = @as(u8, @intCast(mdig + '0'));
j += 1;
if (hdig != ldig or j > 50) break;
@@ -413,11 +413,11 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
}
fn fpnext(val: f64) f64 {
- return @bitCast(f64, @bitCast(u64, val) +% 1);
+ return @as(f64, @bitCast(@as(u64, @bitCast(val)) +% 1));
}
fn fpprev(val: f64) f64 {
- return @bitCast(f64, @bitCast(u64, val) -% 1);
+ return @as(f64, @bitCast(@as(u64, @bitCast(val)) -% 1));
}
pub const c_digits_lut = [_]u8{
@@ -453,7 +453,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
var buf_index: usize = 0;
if (value < kTen8) {
- const v = @intCast(u32, value);
+ const v = @as(u32, @intCast(value));
if (v < 10000) {
const d1: u32 = (v / 100) << 1;
const d2: u32 = (v % 100) << 1;
@@ -508,8 +508,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
buf_index += 1;
}
} else if (value < kTen16) {
- const v0: u32 = @intCast(u32, value / kTen8);
- const v1: u32 = @intCast(u32, value % kTen8);
+ const v0: u32 = @as(u32, @intCast(value / kTen8));
+ const v1: u32 = @as(u32, @intCast(value % kTen8));
const b0: u32 = v0 / 10000;
const c0: u32 = v0 % 10000;
@@ -579,11 +579,11 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
buffer[buf_index] = c_digits_lut[d8 + 1];
buf_index += 1;
} else {
- const a = @intCast(u32, value / kTen16); // 1 to 1844
+ const a = @as(u32, @intCast(value / kTen16)); // 1 to 1844
value %= kTen16;
if (a < 10) {
- buffer[buf_index] = '0' + @intCast(u8, a);
+ buffer[buf_index] = '0' + @as(u8, @intCast(a));
buf_index += 1;
} else if (a < 100) {
const i: u32 = a << 1;
@@ -592,7 +592,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
buffer[buf_index] = c_digits_lut[i + 1];
buf_index += 1;
} else if (a < 1000) {
- buffer[buf_index] = '0' + @intCast(u8, a / 100);
+ buffer[buf_index] = '0' + @as(u8, @intCast(a / 100));
buf_index += 1;
const i: u32 = (a % 100) << 1;
@@ -613,8 +613,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
buf_index += 1;
}
- const v0 = @intCast(u32, value / kTen8);
- const v1 = @intCast(u32, value % kTen8);
+ const v0 = @as(u32, @intCast(value / kTen8));
+ const v1 = @as(u32, @intCast(value % kTen8));
const b0: u32 = v0 / 10000;
const c0: u32 = v0 % 10000;
@@ -672,10 +672,10 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
}
fn fpeint(from: f64) u128 {
- const bits = @bitCast(u64, from);
+ const bits = @as(u64, @bitCast(from));
assert((bits & ((1 << 52) - 1)) == 0);
- return @as(u128, 1) << @truncate(u7, (bits >> 52) -% 1023);
+ return @as(u128, 1) << @as(u7, @truncate((bits >> 52) -% 1023));
}
/// Given two different integers with the same length in terms of the number
diff --git a/lib/std/fmt/parse_float.zig b/lib/std/fmt/parse_float.zig
index b14fe5ca3c..98fbe28032 100644
--- a/lib/std/fmt/parse_float.zig
+++ b/lib/std/fmt/parse_float.zig
@@ -78,7 +78,7 @@ test "fmt.parseFloat nan and inf" {
inline for ([_]type{ f16, f32, f64, f128 }) |T| {
const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
- try expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));
+ try expectEqual(@as(Z, @bitCast(try parseFloat(T, "nAn"))), @as(Z, @bitCast(std.math.nan(T))));
try expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
}
diff --git a/lib/std/fmt/parse_float/common.zig b/lib/std/fmt/parse_float/common.zig
index c1b34a081b..8dba3b4498 100644
--- a/lib/std/fmt/parse_float/common.zig
+++ b/lib/std/fmt/parse_float/common.zig
@@ -32,7 +32,7 @@ pub fn BiasedFp(comptime T: type) type {
pub fn toFloat(self: Self, comptime FloatT: type, negative: bool) FloatT {
var word = self.f;
- word |= @intCast(MantissaT, self.e) << std.math.floatMantissaBits(FloatT);
+ word |= @as(MantissaT, @intCast(self.e)) << std.math.floatMantissaBits(FloatT);
var f = floatFromUnsigned(FloatT, MantissaT, word);
if (negative) f = -f;
return f;
@@ -42,10 +42,10 @@ pub fn BiasedFp(comptime T: type) type {
pub fn floatFromUnsigned(comptime T: type, comptime MantissaT: type, v: MantissaT) T {
return switch (T) {
- f16 => @bitCast(f16, @truncate(u16, v)),
- f32 => @bitCast(f32, @truncate(u32, v)),
- f64 => @bitCast(f64, @truncate(u64, v)),
- f128 => @bitCast(f128, v),
+ f16 => @as(f16, @bitCast(@as(u16, @truncate(v)))),
+ f32 => @as(f32, @bitCast(@as(u32, @truncate(v)))),
+ f64 => @as(f64, @bitCast(@as(u64, @truncate(v)))),
+ f128 => @as(f128, @bitCast(v)),
else => unreachable,
};
}
diff --git a/lib/std/fmt/parse_float/convert_eisel_lemire.zig b/lib/std/fmt/parse_float/convert_eisel_lemire.zig
index 5c49553a14..6831a308ea 100644
--- a/lib/std/fmt/parse_float/convert_eisel_lemire.zig
+++ b/lib/std/fmt/parse_float/convert_eisel_lemire.zig
@@ -36,7 +36,7 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) {
}
// Normalize our significant digits, so the most-significant bit is set.
- const lz = @clz(@bitCast(u64, w));
+ const lz = @clz(@as(u64, @bitCast(w)));
w = math.shl(u64, w, lz);
const r = computeProductApprox(q, w, float_info.mantissa_explicit_bits + 3);
@@ -62,9 +62,9 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) {
}
}
- const upper_bit = @intCast(i32, r.hi >> 63);
- var mantissa = math.shr(u64, r.hi, upper_bit + 64 - @intCast(i32, float_info.mantissa_explicit_bits) - 3);
- var power2 = power(@intCast(i32, q)) + upper_bit - @intCast(i32, lz) - float_info.minimum_exponent;
+ const upper_bit = @as(i32, @intCast(r.hi >> 63));
+ var mantissa = math.shr(u64, r.hi, upper_bit + 64 - @as(i32, @intCast(float_info.mantissa_explicit_bits)) - 3);
+ var power2 = power(@as(i32, @intCast(q))) + upper_bit - @as(i32, @intCast(lz)) - float_info.minimum_exponent;
if (power2 <= 0) {
if (-power2 + 1 >= 64) {
// Have more than 64 bits below the minimum exponent, must be 0.
@@ -93,7 +93,7 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) {
q >= float_info.min_exponent_round_to_even and
q <= float_info.max_exponent_round_to_even and
mantissa & 3 == 1 and
- math.shl(u64, mantissa, (upper_bit + 64 - @intCast(i32, float_info.mantissa_explicit_bits) - 3)) == r.hi)
+ math.shl(u64, mantissa, (upper_bit + 64 - @as(i32, @intCast(float_info.mantissa_explicit_bits)) - 3)) == r.hi)
{
// Zero the lowest bit, so we don't round up.
mantissa &= ~@as(u64, 1);
@@ -139,8 +139,8 @@ const U128 = struct {
pub fn mul(a: u64, b: u64) U128 {
const x = @as(u128, a) * b;
return .{
- .hi = @truncate(u64, x >> 64),
- .lo = @truncate(u64, x),
+ .hi = @as(u64, @truncate(x >> 64)),
+ .lo = @as(u64, @truncate(x)),
};
}
};
@@ -161,7 +161,7 @@ fn computeProductApprox(q: i64, w: u64, comptime precision: usize) U128 {
// 5^q < 2^64, then the multiplication always provides an exact value.
// That means whenever we need to round ties to even, we always have
// an exact value.
- const index = @intCast(usize, q - @intCast(i64, eisel_lemire_smallest_power_of_five));
+ const index = @as(usize, @intCast(q - @as(i64, @intCast(eisel_lemire_smallest_power_of_five))));
const pow5 = eisel_lemire_table_powers_of_five_128[index];
// Only need one multiplication as long as there is 1 zero but
diff --git a/lib/std/fmt/parse_float/convert_fast.zig b/lib/std/fmt/parse_float/convert_fast.zig
index 2124e436ab..a148d3946f 100644
--- a/lib/std/fmt/parse_float/convert_fast.zig
+++ b/lib/std/fmt/parse_float/convert_fast.zig
@@ -108,19 +108,19 @@ pub fn convertFast(comptime T: type, n: Number(T)) ?T {
var value: T = 0;
if (n.exponent <= info.max_exponent_fast_path) {
// normal fast path
- value = @floatFromInt(T, n.mantissa);
+ value = @as(T, @floatFromInt(n.mantissa));
value = if (n.exponent < 0)
- value / fastPow10(T, @intCast(usize, -n.exponent))
+ value / fastPow10(T, @as(usize, @intCast(-n.exponent)))
else
- value * fastPow10(T, @intCast(usize, n.exponent));
+ value * fastPow10(T, @as(usize, @intCast(n.exponent)));
} else {
// disguised fast path
const shift = n.exponent - info.max_exponent_fast_path;
- const mantissa = math.mul(MantissaT, n.mantissa, fastIntPow10(MantissaT, @intCast(usize, shift))) catch return null;
+ const mantissa = math.mul(MantissaT, n.mantissa, fastIntPow10(MantissaT, @as(usize, @intCast(shift)))) catch return null;
if (mantissa > info.max_mantissa_fast_path) {
return null;
}
- value = @floatFromInt(T, mantissa) * fastPow10(T, info.max_exponent_fast_path);
+ value = @as(T, @floatFromInt(mantissa)) * fastPow10(T, info.max_exponent_fast_path);
}
if (n.negative) {
diff --git a/lib/std/fmt/parse_float/convert_hex.zig b/lib/std/fmt/parse_float/convert_hex.zig
index 3b3f797216..815331347c 100644
--- a/lib/std/fmt/parse_float/convert_hex.zig
+++ b/lib/std/fmt/parse_float/convert_hex.zig
@@ -81,7 +81,7 @@ pub fn convertHex(comptime T: type, n_: Number(T)) T {
}
var bits = n.mantissa & ((1 << mantissa_bits) - 1);
- bits |= @intCast(MantissaT, (n.exponent - exp_bias) & ((1 << exp_bits) - 1)) << mantissa_bits;
+ bits |= @as(MantissaT, @intCast((n.exponent - exp_bias) & ((1 << exp_bits) - 1))) << mantissa_bits;
if (n.negative) {
bits |= 1 << (mantissa_bits + exp_bits);
}
diff --git a/lib/std/fmt/parse_float/convert_slow.zig b/lib/std/fmt/parse_float/convert_slow.zig
index 225a1e208c..53cb12ef13 100644
--- a/lib/std/fmt/parse_float/convert_slow.zig
+++ b/lib/std/fmt/parse_float/convert_slow.zig
@@ -48,13 +48,13 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
var exp2: i32 = 0;
// Shift right toward (1/2 .. 1]
while (d.decimal_point > 0) {
- const n = @intCast(usize, d.decimal_point);
+ const n = @as(usize, @intCast(d.decimal_point));
const shift = getShift(n);
d.rightShift(shift);
if (d.decimal_point < -Decimal(T).decimal_point_range) {
return BiasedFp(T).zero();
}
- exp2 += @intCast(i32, shift);
+ exp2 += @as(i32, @intCast(shift));
}
// Shift left toward (1/2 .. 1]
while (d.decimal_point <= 0) {
@@ -66,7 +66,7 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
else => 1,
};
} else {
- const n = @intCast(usize, -d.decimal_point);
+ const n = @as(usize, @intCast(-d.decimal_point));
break :blk getShift(n);
}
};
@@ -74,17 +74,17 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
if (d.decimal_point > Decimal(T).decimal_point_range) {
return BiasedFp(T).inf(T);
}
- exp2 -= @intCast(i32, shift);
+ exp2 -= @as(i32, @intCast(shift));
}
// We are now in the range [1/2 .. 1] but the binary format uses [1 .. 2]
exp2 -= 1;
while (min_exponent + 1 > exp2) {
- var n = @intCast(usize, (min_exponent + 1) - exp2);
+ var n = @as(usize, @intCast((min_exponent + 1) - exp2));
if (n > max_shift) {
n = max_shift;
}
d.rightShift(n);
- exp2 += @intCast(i32, n);
+ exp2 += @as(i32, @intCast(n));
}
if (exp2 - min_exponent >= infinite_power) {
return BiasedFp(T).inf(T);
diff --git a/lib/std/fmt/parse_float/decimal.zig b/lib/std/fmt/parse_float/decimal.zig
index 5bb5fa8d5e..f8d736a065 100644
--- a/lib/std/fmt/parse_float/decimal.zig
+++ b/lib/std/fmt/parse_float/decimal.zig
@@ -114,7 +114,7 @@ pub fn Decimal(comptime T: type) type {
return math.maxInt(MantissaT);
}
- const dp = @intCast(usize, self.decimal_point);
+ const dp = @as(usize, @intCast(self.decimal_point));
var n: MantissaT = 0;
var i: usize = 0;
@@ -155,7 +155,7 @@ pub fn Decimal(comptime T: type) type {
const quotient = n / 10;
const remainder = n - (10 * quotient);
if (write_index < max_digits) {
- self.digits[write_index] = @intCast(u8, remainder);
+ self.digits[write_index] = @as(u8, @intCast(remainder));
} else if (remainder > 0) {
self.truncated = true;
}
@@ -167,7 +167,7 @@ pub fn Decimal(comptime T: type) type {
const quotient = n / 10;
const remainder = n - (10 * quotient);
if (write_index < max_digits) {
- self.digits[write_index] = @intCast(u8, remainder);
+ self.digits[write_index] = @as(u8, @intCast(remainder));
} else if (remainder > 0) {
self.truncated = true;
}
@@ -178,7 +178,7 @@ pub fn Decimal(comptime T: type) type {
if (self.num_digits > max_digits) {
self.num_digits = max_digits;
}
- self.decimal_point += @intCast(i32, num_new_digits);
+ self.decimal_point += @as(i32, @intCast(num_new_digits));
self.trim();
}
@@ -202,7 +202,7 @@ pub fn Decimal(comptime T: type) type {
}
}
- self.decimal_point -= @intCast(i32, read_index) - 1;
+ self.decimal_point -= @as(i32, @intCast(read_index)) - 1;
if (self.decimal_point < -decimal_point_range) {
self.num_digits = 0;
self.decimal_point = 0;
@@ -212,14 +212,14 @@ pub fn Decimal(comptime T: type) type {
const mask = math.shl(MantissaT, 1, shift) - 1;
while (read_index < self.num_digits) {
- const new_digit = @intCast(u8, math.shr(MantissaT, n, shift));
+ const new_digit = @as(u8, @intCast(math.shr(MantissaT, n, shift)));
n = (10 * (n & mask)) + self.digits[read_index];
read_index += 1;
self.digits[write_index] = new_digit;
write_index += 1;
}
while (n > 0) {
- const new_digit = @intCast(u8, math.shr(MantissaT, n, shift));
+ const new_digit = @as(u8, @intCast(math.shr(MantissaT, n, shift)));
n = 10 * (n & mask);
if (write_index < max_digits) {
self.digits[write_index] = new_digit;
@@ -268,7 +268,7 @@ pub fn Decimal(comptime T: type) type {
while (stream.scanDigit(10)) |digit| {
d.tryAddDigit(digit);
}
- d.decimal_point = @intCast(i32, marker) - @intCast(i32, stream.offsetTrue());
+ d.decimal_point = @as(i32, @intCast(marker)) - @as(i32, @intCast(stream.offsetTrue()));
}
if (d.num_digits != 0) {
// Ignore trailing zeros if any
@@ -284,9 +284,9 @@ pub fn Decimal(comptime T: type) type {
i -= 1;
if (i == 0) break;
}
- d.decimal_point += @intCast(i32, n_trailing_zeros);
+ d.decimal_point += @as(i32, @intCast(n_trailing_zeros));
d.num_digits -= n_trailing_zeros;
- d.decimal_point += @intCast(i32, d.num_digits);
+ d.decimal_point += @as(i32, @intCast(d.num_digits));
if (d.num_digits > max_digits) {
d.truncated = true;
d.num_digits = max_digits;
diff --git a/lib/std/fmt/parse_float/parse.zig b/lib/std/fmt/parse_float/parse.zig
index 9f6e75b29a..a31df31312 100644
--- a/lib/std/fmt/parse_float/parse.zig
+++ b/lib/std/fmt/parse_float/parse.zig
@@ -21,7 +21,7 @@ fn parse8Digits(v_: u64) u64 {
v = (v * 10) + (v >> 8); // will not overflow, fits in 63 bits
const v1 = (v & mask) *% mul1;
const v2 = ((v >> 16) & mask) *% mul2;
- return @as(u64, @truncate(u32, (v1 +% v2) >> 32));
+ return @as(u64, @as(u32, @truncate((v1 +% v2) >> 32)));
}
/// Parse digits until a non-digit character is found.
@@ -106,7 +106,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
var mantissa: MantissaT = 0;
tryParseDigits(MantissaT, stream, &mantissa, info.base);
var int_end = stream.offsetTrue();
- var n_digits = @intCast(isize, stream.offsetTrue());
+ var n_digits = @as(isize, @intCast(stream.offsetTrue()));
// the base being 16 implies a 0x prefix, which shouldn't be included in the digit count
if (info.base == 16) n_digits -= 2;
@@ -117,8 +117,8 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
const marker = stream.offsetTrue();
tryParseDigits(MantissaT, stream, &mantissa, info.base);
const n_after_dot = stream.offsetTrue() - marker;
- exponent = -@intCast(i64, n_after_dot);
- n_digits += @intCast(isize, n_after_dot);
+ exponent = -@as(i64, @intCast(n_after_dot));
+ n_digits += @as(isize, @intCast(n_after_dot));
}
// adjust required shift to offset mantissa for base-16 (2^4)
@@ -163,7 +163,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
// '0' = '.' + 2
const next = stream.firstUnchecked();
if (next != '_') {
- n_digits -= @intCast(isize, next -| ('0' - 1));
+ n_digits -= @as(isize, @intCast(next -| ('0' - 1)));
} else {
stream.underscore_count += 1;
}
@@ -179,7 +179,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
exponent = blk: {
if (mantissa >= min_n_digit_int(MantissaT, info.max_mantissa_digits)) {
// big int
- break :blk @intCast(i64, int_end) - @intCast(i64, stream.offsetTrue());
+ break :blk @as(i64, @intCast(int_end)) - @as(i64, @intCast(stream.offsetTrue()));
} else {
// the next byte must be present and be '.'
// We know this is true because we had more than 19
@@ -190,7 +190,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
stream.advance(1);
var marker = stream.offsetTrue();
tryParseNDigits(MantissaT, stream, &mantissa, info.base, info.max_mantissa_digits);
- break :blk @intCast(i64, marker) - @intCast(i64, stream.offsetTrue());
+ break :blk @as(i64, @intCast(marker)) - @as(i64, @intCast(stream.offsetTrue()));
}
};
// add back the explicit part