authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-07 18:52:09-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-08 15:57:25-05:00
logaa0daea5415dd2a20e4d7c2fd047b7bcee6c9ea4
treeb8634d38380eb6fd32ca614678785f36167ca7b2
parenta2acc2787242fdee189ec4197c0dd847b8245139
signaturelock-open Commit is signed but in an unrecognized format.

update more of the std lib to use `@as`


28 files changed, 145 insertions(+), 145 deletions(-)

lib/std/bloom_filter.zig+8-8
...@@ -28,7 +28,7 @@ pub fn BloomFilter(...@@ -28,7 +28,7 @@ pub fn BloomFilter(
28 assert(n_items > 0);28 assert(n_items > 0);
29 assert(math.isPowerOfTwo(n_items));29 assert(math.isPowerOfTwo(n_items));
30 assert(K > 0);30 assert(K > 0);
31 const cellEmpty = if (Cell == bool) false else Cell(0);31 const cellEmpty = if (Cell == bool) false else @as(Cell, 0);
32 const cellMax = if (Cell == bool) true else math.maxInt(Cell);32 const cellMax = if (Cell == bool) true else math.maxInt(Cell);
33 const n_bytes = (n_items * comptime std.meta.bitCount(Cell)) / 8;33 const n_bytes = (n_items * comptime std.meta.bitCount(Cell)) / 8;
34 assert(n_bytes > 0);34 assert(n_bytes > 0);
...@@ -137,7 +137,7 @@ pub fn BloomFilter(...@@ -137,7 +137,7 @@ pub fn BloomFilter(
137 var i: usize = 0;137 var i: usize = 0;
138 while (i < n_items) : (i += 1) {138 while (i < n_items) : (i += 1) {
139 const cell = self.getCell(@intCast(Index, i));139 const cell = self.getCell(@intCast(Index, i));
140 n += if (if (Cell == bool) cell else cell > 0) Index(1) else Index(0);140 n += if (if (Cell == bool) cell else cell > 0) @as(Index, 1) else @as(Index, 0);
141 }141 }
142 }142 }
143 return n;143 return n;
...@@ -161,7 +161,7 @@ fn hashFunc(out: []u8, Ki: usize, in: []const u8) void {...@@ -161,7 +161,7 @@ fn hashFunc(out: []u8, Ki: usize, in: []const u8) void {
161161
162test "std.BloomFilter" {162test "std.BloomFilter" {
163 inline for ([_]type{ bool, u1, u2, u3, u4 }) |Cell| {163 inline for ([_]type{ bool, u1, u2, u3, u4 }) |Cell| {
164 const emptyCell = if (Cell == bool) false else Cell(0);164 const emptyCell = if (Cell == bool) false else @as(Cell, 0);
165 const BF = BloomFilter(128 * 8, 8, Cell, builtin.endian, hashFunc);165 const BF = BloomFilter(128 * 8, 8, Cell, builtin.endian, hashFunc);
166 var bf = BF{};166 var bf = BF{};
167 var i: usize = undefined;167 var i: usize = undefined;
...@@ -170,7 +170,7 @@ test "std.BloomFilter" {...@@ -170,7 +170,7 @@ test "std.BloomFilter" {
170 while (i < BF.items) : (i += 1) {170 while (i < BF.items) : (i += 1) {
171 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));171 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
172 }172 }
173 testing.expectEqual(BF.Index(0), bf.popCount());173 testing.expectEqual(@as(BF.Index, 0), bf.popCount());
174 testing.expectEqual(@as(f64, 0), bf.estimateItems());174 testing.expectEqual(@as(f64, 0), bf.estimateItems());
175 // fill in a few items175 // fill in a few items
176 bf.incrementCell(42);176 bf.incrementCell(42);
...@@ -196,7 +196,7 @@ test "std.BloomFilter" {...@@ -196,7 +196,7 @@ test "std.BloomFilter" {
196 while (i < BF.items) : (i += 1) {196 while (i < BF.items) : (i += 1) {
197 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));197 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
198 }198 }
199 testing.expectEqual(BF.Index(0), bf.popCount());199 testing.expectEqual(@as(BF.Index, 0), bf.popCount());
200 testing.expectEqual(@as(f64, 0), bf.estimateItems());200 testing.expectEqual(@as(f64, 0), bf.estimateItems());
201201
202 // Lets add a string202 // Lets add a string
...@@ -218,7 +218,7 @@ test "std.BloomFilter" {...@@ -218,7 +218,7 @@ test "std.BloomFilter" {
218 while (i < BF.items) : (i += 1) {218 while (i < BF.items) : (i += 1) {
219 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));219 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
220 }220 }
221 testing.expectEqual(BF.Index(0), bf.popCount());221 testing.expectEqual(@as(BF.Index, 0), bf.popCount());
222 testing.expectEqual(@as(f64, 0), bf.estimateItems());222 testing.expectEqual(@as(f64, 0), bf.estimateItems());
223223
224 comptime var teststrings = [_][]const u8{224 comptime var teststrings = [_][]const u8{
...@@ -246,12 +246,12 @@ test "std.BloomFilter" {...@@ -246,12 +246,12 @@ test "std.BloomFilter" {
246 inline for (teststrings) |str| {246 inline for (teststrings) |str| {
247 testing.expectEqual(true, larger_bf.contains(str));247 testing.expectEqual(true, larger_bf.contains(str));
248 }248 }
249 testing.expectEqual(u12(bf.popCount()) * (4096 / 1024), larger_bf.popCount());249 testing.expectEqual(@as(u12, bf.popCount()) * (4096 / 1024), larger_bf.popCount());
250250
251 const smaller_bf = bf.resize(64);251 const smaller_bf = bf.resize(64);
252 inline for (teststrings) |str| {252 inline for (teststrings) |str| {
253 testing.expectEqual(true, smaller_bf.contains(str));253 testing.expectEqual(true, smaller_bf.contains(str));
254 }254 }
255 testing.expect(bf.popCount() <= u10(smaller_bf.popCount()) * (1024 / 64));255 testing.expect(bf.popCount() <= @as(u10, smaller_bf.popCount()) * (1024 / 64));
256 }256 }
257}257}
lib/std/crypto/x25519.zig+23-23
...@@ -199,9 +199,9 @@ const Fe = struct {...@@ -199,9 +199,9 @@ const Fe = struct {
199 inline fn carryRound(c: []i64, t: []i64, comptime i: comptime_int, comptime shift: comptime_int, comptime mult: comptime_int) void {199 inline fn carryRound(c: []i64, t: []i64, comptime i: comptime_int, comptime shift: comptime_int, comptime mult: comptime_int) void {
200 const j = (i + 1) % 10;200 const j = (i + 1) % 10;
201201
202 c[i] = (t[i] + (i64(1) << shift)) >> (shift + 1);202 c[i] = (t[i] + (@as(i64, 1) << shift)) >> (shift + 1);
203 t[j] += c[i] * mult;203 t[j] += c[i] * mult;
204 t[i] -= c[i] * (i64(1) << (shift + 1));204 t[i] -= c[i] * (@as(i64, 1) << (shift + 1));
205 }205 }
206206
207 fn carry1(h: *Fe, t: []i64) void {207 fn carry1(h: *Fe, t: []i64) void {
...@@ -273,7 +273,7 @@ const Fe = struct {...@@ -273,7 +273,7 @@ const Fe = struct {
273 var t: [10]i64 = undefined;273 var t: [10]i64 = undefined;
274274
275 for (t[0..]) |_, i| {275 for (t[0..]) |_, i| {
276 t[i] = i64(f.b[i]) * g;276 t[i] = @as(i64, f.b[i]) * g;
277 }277 }
278278
279 carry1(h, t[0..]);279 carry1(h, t[0..]);
...@@ -305,16 +305,16 @@ const Fe = struct {...@@ -305,16 +305,16 @@ const Fe = struct {
305 // t's become h305 // t's become h
306 var t: [10]i64 = undefined;306 var t: [10]i64 = undefined;
307307
308 t[0] = f[0] * i64(g[0]) + F[1] * i64(G[9]) + f[2] * i64(G[8]) + F[3] * i64(G[7]) + f[4] * i64(G[6]) + F[5] * i64(G[5]) + f[6] * i64(G[4]) + F[7] * i64(G[3]) + f[8] * i64(G[2]) + F[9] * i64(G[1]);308 t[0] = f[0] * @as(i64, g[0]) + F[1] * @as(i64, G[9]) + f[2] * @as(i64, G[8]) + F[3] * @as(i64, G[7]) + f[4] * @as(i64, G[6]) + F[5] * @as(i64, G[5]) + f[6] * @as(i64, G[4]) + F[7] * @as(i64, G[3]) + f[8] * @as(i64, G[2]) + F[9] * @as(i64, G[1]);
309 t[1] = f[0] * i64(g[1]) + f[1] * i64(g[0]) + f[2] * i64(G[9]) + f[3] * i64(G[8]) + f[4] * i64(G[7]) + f[5] * i64(G[6]) + f[6] * i64(G[5]) + f[7] * i64(G[4]) + f[8] * i64(G[3]) + f[9] * i64(G[2]);309 t[1] = f[0] * @as(i64, g[1]) + f[1] * @as(i64, g[0]) + f[2] * @as(i64, G[9]) + f[3] * @as(i64, G[8]) + f[4] * @as(i64, G[7]) + f[5] * @as(i64, G[6]) + f[6] * @as(i64, G[5]) + f[7] * @as(i64, G[4]) + f[8] * @as(i64, G[3]) + f[9] * @as(i64, G[2]);
310 t[2] = f[0] * i64(g[2]) + F[1] * i64(g[1]) + f[2] * i64(g[0]) + F[3] * i64(G[9]) + f[4] * i64(G[8]) + F[5] * i64(G[7]) + f[6] * i64(G[6]) + F[7] * i64(G[5]) + f[8] * i64(G[4]) + F[9] * i64(G[3]);310 t[2] = f[0] * @as(i64, g[2]) + F[1] * @as(i64, g[1]) + f[2] * @as(i64, g[0]) + F[3] * @as(i64, G[9]) + f[4] * @as(i64, G[8]) + F[5] * @as(i64, G[7]) + f[6] * @as(i64, G[6]) + F[7] * @as(i64, G[5]) + f[8] * @as(i64, G[4]) + F[9] * @as(i64, G[3]);
311 t[3] = f[0] * i64(g[3]) + f[1] * i64(g[2]) + f[2] * i64(g[1]) + f[3] * i64(g[0]) + f[4] * i64(G[9]) + f[5] * i64(G[8]) + f[6] * i64(G[7]) + f[7] * i64(G[6]) + f[8] * i64(G[5]) + f[9] * i64(G[4]);311 t[3] = f[0] * @as(i64, g[3]) + f[1] * @as(i64, g[2]) + f[2] * @as(i64, g[1]) + f[3] * @as(i64, g[0]) + f[4] * @as(i64, G[9]) + f[5] * @as(i64, G[8]) + f[6] * @as(i64, G[7]) + f[7] * @as(i64, G[6]) + f[8] * @as(i64, G[5]) + f[9] * @as(i64, G[4]);
312 t[4] = f[0] * i64(g[4]) + F[1] * i64(g[3]) + f[2] * i64(g[2]) + F[3] * i64(g[1]) + f[4] * i64(g[0]) + F[5] * i64(G[9]) + f[6] * i64(G[8]) + F[7] * i64(G[7]) + f[8] * i64(G[6]) + F[9] * i64(G[5]);312 t[4] = f[0] * @as(i64, g[4]) + F[1] * @as(i64, g[3]) + f[2] * @as(i64, g[2]) + F[3] * @as(i64, g[1]) + f[4] * @as(i64, g[0]) + F[5] * @as(i64, G[9]) + f[6] * @as(i64, G[8]) + F[7] * @as(i64, G[7]) + f[8] * @as(i64, G[6]) + F[9] * @as(i64, G[5]);
313 t[5] = f[0] * i64(g[5]) + f[1] * i64(g[4]) + f[2] * i64(g[3]) + f[3] * i64(g[2]) + f[4] * i64(g[1]) + f[5] * i64(g[0]) + f[6] * i64(G[9]) + f[7] * i64(G[8]) + f[8] * i64(G[7]) + f[9] * i64(G[6]);313 t[5] = f[0] * @as(i64, g[5]) + f[1] * @as(i64, g[4]) + f[2] * @as(i64, g[3]) + f[3] * @as(i64, g[2]) + f[4] * @as(i64, g[1]) + f[5] * @as(i64, g[0]) + f[6] * @as(i64, G[9]) + f[7] * @as(i64, G[8]) + f[8] * @as(i64, G[7]) + f[9] * @as(i64, G[6]);
314 t[6] = f[0] * i64(g[6]) + F[1] * i64(g[5]) + f[2] * i64(g[4]) + F[3] * i64(g[3]) + f[4] * i64(g[2]) + F[5] * i64(g[1]) + f[6] * i64(g[0]) + F[7] * i64(G[9]) + f[8] * i64(G[8]) + F[9] * i64(G[7]);314 t[6] = f[0] * @as(i64, g[6]) + F[1] * @as(i64, g[5]) + f[2] * @as(i64, g[4]) + F[3] * @as(i64, g[3]) + f[4] * @as(i64, g[2]) + F[5] * @as(i64, g[1]) + f[6] * @as(i64, g[0]) + F[7] * @as(i64, G[9]) + f[8] * @as(i64, G[8]) + F[9] * @as(i64, G[7]);
315 t[7] = f[0] * i64(g[7]) + f[1] * i64(g[6]) + f[2] * i64(g[5]) + f[3] * i64(g[4]) + f[4] * i64(g[3]) + f[5] * i64(g[2]) + f[6] * i64(g[1]) + f[7] * i64(g[0]) + f[8] * i64(G[9]) + f[9] * i64(G[8]);315 t[7] = f[0] * @as(i64, g[7]) + f[1] * @as(i64, g[6]) + f[2] * @as(i64, g[5]) + f[3] * @as(i64, g[4]) + f[4] * @as(i64, g[3]) + f[5] * @as(i64, g[2]) + f[6] * @as(i64, g[1]) + f[7] * @as(i64, g[0]) + f[8] * @as(i64, G[9]) + f[9] * @as(i64, G[8]);
316 t[8] = f[0] * i64(g[8]) + F[1] * i64(g[7]) + f[2] * i64(g[6]) + F[3] * i64(g[5]) + f[4] * i64(g[4]) + F[5] * i64(g[3]) + f[6] * i64(g[2]) + F[7] * i64(g[1]) + f[8] * i64(g[0]) + F[9] * i64(G[9]);316 t[8] = f[0] * @as(i64, g[8]) + F[1] * @as(i64, g[7]) + f[2] * @as(i64, g[6]) + F[3] * @as(i64, g[5]) + f[4] * @as(i64, g[4]) + F[5] * @as(i64, g[3]) + f[6] * @as(i64, g[2]) + F[7] * @as(i64, g[1]) + f[8] * @as(i64, g[0]) + F[9] * @as(i64, G[9]);
317 t[9] = f[0] * i64(g[9]) + f[1] * i64(g[8]) + f[2] * i64(g[7]) + f[3] * i64(g[6]) + f[4] * i64(g[5]) + f[5] * i64(g[4]) + f[6] * i64(g[3]) + f[7] * i64(g[2]) + f[8] * i64(g[1]) + f[9] * i64(g[0]);317 t[9] = f[0] * @as(i64, g[9]) + f[1] * @as(i64, g[8]) + f[2] * @as(i64, g[7]) + f[3] * @as(i64, g[6]) + f[4] * @as(i64, g[5]) + f[5] * @as(i64, g[4]) + f[6] * @as(i64, g[3]) + f[7] * @as(i64, g[2]) + f[8] * @as(i64, g[1]) + f[9] * @as(i64, g[0]);
318318
319 carry2(h, t[0..]);319 carry2(h, t[0..]);
320 }320 }
...@@ -348,16 +348,16 @@ const Fe = struct {...@@ -348,16 +348,16 @@ const Fe = struct {
348348
349 var t: [10]i64 = undefined;349 var t: [10]i64 = undefined;
350350
351 t[0] = f0 * i64(f0) + f1_2 * i64(f9_38) + f2_2 * i64(f8_19) + f3_2 * i64(f7_38) + f4_2 * i64(f6_19) + f5 * i64(f5_38);351 t[0] = f0 * @as(i64, f0) + f1_2 * @as(i64, f9_38) + f2_2 * @as(i64, f8_19) + f3_2 * @as(i64, f7_38) + f4_2 * @as(i64, f6_19) + f5 * @as(i64, f5_38);
352 t[1] = f0_2 * i64(f1) + f2 * i64(f9_38) + f3_2 * i64(f8_19) + f4 * i64(f7_38) + f5_2 * i64(f6_19);352 t[1] = f0_2 * @as(i64, f1) + f2 * @as(i64, f9_38) + f3_2 * @as(i64, f8_19) + f4 * @as(i64, f7_38) + f5_2 * @as(i64, f6_19);
353 t[2] = f0_2 * i64(f2) + f1_2 * i64(f1) + f3_2 * i64(f9_38) + f4_2 * i64(f8_19) + f5_2 * i64(f7_38) + f6 * i64(f6_19);353 t[2] = f0_2 * @as(i64, f2) + f1_2 * @as(i64, f1) + f3_2 * @as(i64, f9_38) + f4_2 * @as(i64, f8_19) + f5_2 * @as(i64, f7_38) + f6 * @as(i64, f6_19);
354 t[3] = f0_2 * i64(f3) + f1_2 * i64(f2) + f4 * i64(f9_38) + f5_2 * i64(f8_19) + f6 * i64(f7_38);354 t[3] = f0_2 * @as(i64, f3) + f1_2 * @as(i64, f2) + f4 * @as(i64, f9_38) + f5_2 * @as(i64, f8_19) + f6 * @as(i64, f7_38);
355 t[4] = f0_2 * i64(f4) + f1_2 * i64(f3_2) + f2 * i64(f2) + f5_2 * i64(f9_38) + f6_2 * i64(f8_19) + f7 * i64(f7_38);355 t[4] = f0_2 * @as(i64, f4) + f1_2 * @as(i64, f3_2) + f2 * @as(i64, f2) + f5_2 * @as(i64, f9_38) + f6_2 * @as(i64, f8_19) + f7 * @as(i64, f7_38);
356 t[5] = f0_2 * i64(f5) + f1_2 * i64(f4) + f2_2 * i64(f3) + f6 * i64(f9_38) + f7_2 * i64(f8_19);356 t[5] = f0_2 * @as(i64, f5) + f1_2 * @as(i64, f4) + f2_2 * @as(i64, f3) + f6 * @as(i64, f9_38) + f7_2 * @as(i64, f8_19);
357 t[6] = f0_2 * i64(f6) + f1_2 * i64(f5_2) + f2_2 * i64(f4) + f3_2 * i64(f3) + f7_2 * i64(f9_38) + f8 * i64(f8_19);357 t[6] = f0_2 * @as(i64, f6) + f1_2 * @as(i64, f5_2) + f2_2 * @as(i64, f4) + f3_2 * @as(i64, f3) + f7_2 * @as(i64, f9_38) + f8 * @as(i64, f8_19);
358 t[7] = f0_2 * i64(f7) + f1_2 * i64(f6) + f2_2 * i64(f5) + f3_2 * i64(f4) + f8 * i64(f9_38);358 t[7] = f0_2 * @as(i64, f7) + f1_2 * @as(i64, f6) + f2_2 * @as(i64, f5) + f3_2 * @as(i64, f4) + f8 * @as(i64, f9_38);
359 t[8] = f0_2 * i64(f8) + f1_2 * i64(f7_2) + f2_2 * i64(f6) + f3_2 * i64(f5_2) + f4 * i64(f4) + f9 * i64(f9_38);359 t[8] = f0_2 * @as(i64, f8) + f1_2 * @as(i64, f7_2) + f2_2 * @as(i64, f6) + f3_2 * @as(i64, f5_2) + f4 * @as(i64, f4) + f9 * @as(i64, f9_38);
360 t[9] = f0_2 * i64(f9) + f1_2 * i64(f8) + f2_2 * i64(f7) + f3_2 * i64(f6) + f4 * i64(f5_2);360 t[9] = f0_2 * @as(i64, f9) + f1_2 * @as(i64, f8) + f2_2 * @as(i64, f7) + f3_2 * @as(i64, f6) + f4 * @as(i64, f5_2);
361361
362 carry2(h, t[0..]);362 carry2(h, t[0..]);
363 }363 }
lib/std/debug/leb128.zig+1-1
...@@ -101,7 +101,7 @@ pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T {...@@ -101,7 +101,7 @@ pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
101 return error.Overflow;101 return error.Overflow;
102102
103 var operand: UT = undefined;103 var operand: UT = undefined;
104 if (@shlWithOverflow(UT, UT(byte & 0x7f), @intCast(ShiftT, shift), &operand)) {104 if (@shlWithOverflow(UT, @as(UT, byte & 0x7f), @intCast(ShiftT, shift), &operand)) {
105 if (byte != 0x7f)105 if (byte != 0x7f)
106 return error.Overflow;106 return error.Overflow;
107 }107 }
lib/std/fmt.zig+11-11
...@@ -382,10 +382,10 @@ pub fn formatType(...@@ -382,10 +382,10 @@ pub fn formatType(
382 const info = @typeInfo(T).Union;382 const info = @typeInfo(T).Union;
383 if (info.tag_type) |UnionTagType| {383 if (info.tag_type) |UnionTagType| {
384 try output(context, "{ .");384 try output(context, "{ .");
385 try output(context, @tagName(UnionTagType(value)));385 try output(context, @tagName(@as(UnionTagType, value)));
386 try output(context, " = ");386 try output(context, " = ");
387 inline for (info.fields) |u_field| {387 inline for (info.fields) |u_field| {
388 if (@enumToInt(UnionTagType(value)) == u_field.enum_field.?.value) {388 if (@enumToInt(@as(UnionTagType, value)) == u_field.enum_field.?.value) {
389 try formatType(@field(value, u_field.name), "", options, context, Errors, output, max_depth - 1);389 try formatType(@field(value, u_field.name), "", options, context, Errors, output, max_depth - 1);
390 }390 }
391 }391 }
...@@ -503,7 +503,7 @@ pub fn formatIntValue(...@@ -503,7 +503,7 @@ pub fn formatIntValue(
503503
504 const int_value = if (@typeOf(value) == comptime_int) blk: {504 const int_value = if (@typeOf(value) == comptime_int) blk: {
505 const Int = math.IntFittingRange(value, value);505 const Int = math.IntFittingRange(value, value);
506 break :blk Int(value);506 break :blk @as(Int, value);
507 } else507 } else
508 value;508 value;
509509
...@@ -578,7 +578,7 @@ pub fn formatAsciiChar(...@@ -578,7 +578,7 @@ pub fn formatAsciiChar(
578 comptime Errors: type,578 comptime Errors: type,
579 output: fn (@typeOf(context), []const u8) Errors!void,579 output: fn (@typeOf(context), []const u8) Errors!void,
580) Errors!void {580) Errors!void {
581 return output(context, (*const [1]u8)(&c)[0..]);581 return output(context, @as(*const [1]u8, &c)[0..]);
582}582}
583583
584pub fn formatBuf(584pub fn formatBuf(
...@@ -998,7 +998,7 @@ fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) {...@@ -998,7 +998,7 @@ fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) {
998998
999pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {999pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
1000 if (!T.is_signed) return parseUnsigned(T, buf, radix);1000 if (!T.is_signed) return parseUnsigned(T, buf, radix);
1001 if (buf.len == 0) return T(0);1001 if (buf.len == 0) return @as(T, 0);
1002 if (buf[0] == '-') {1002 if (buf[0] == '-') {
1003 return math.negate(try parseUnsigned(T, buf[1..], radix));1003 return math.negate(try parseUnsigned(T, buf[1..], radix));
1004 } else if (buf[0] == '+') {1004 } else if (buf[0] == '+') {
...@@ -1325,8 +1325,8 @@ test "float.scientific" {...@@ -1325,8 +1325,8 @@ test "float.scientific" {
1325 // TODO https://github.com/ziglang/zig/issues/32891325 // TODO https://github.com/ziglang/zig/issues/3289
1326 return error.SkipZigTest;1326 return error.SkipZigTest;
1327 }1327 }
1328 try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34));1328 try testFmt("f32: 1.34000003e+00", "f32: {e}", @as(f32, 1.34));
1329 try testFmt("f32: 1.23400001e+01", "f32: {e}", f32(12.34));1329 try testFmt("f32: 1.23400001e+01", "f32: {e}", @as(f32, 12.34));
1330 try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10));1330 try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10));
1331 try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40));1331 try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40));
1332}1332}
...@@ -1365,12 +1365,12 @@ test "float.decimal" {...@@ -1365,12 +1365,12 @@ test "float.decimal" {
1365 return error.SkipZigTest;1365 return error.SkipZigTest;
1366 }1366 }
1367 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));1367 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));
1368 try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234));1368 try testFmt("f32: 1.1", "f32: {d:.1}", @as(f32, 1.1234));
1369 try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567));1369 try testFmt("f32: 1234.57", "f32: {d:.2}", @as(f32, 1234.567));
1370 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).1370 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
1371 // -11.12339... is rounded back up to -11.12341371 // -11.12339... is rounded back up to -11.1234
1372 try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234));1372 try testFmt("f32: -11.1234", "f32: {d:.4}", @as(f32, -11.1234));
1373 try testFmt("f32: 91.12345", "f32: {d:.5}", f32(91.12345));1373 try testFmt("f32: 91.12345", "f32: {d:.5}", @as(f32, 91.12345));
1374 try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235));1374 try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235));
1375 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0));1375 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0));
1376 try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700));1376 try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700));
lib/std/fmt/parse_float.zig+3-3
...@@ -375,7 +375,7 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {...@@ -375,7 +375,7 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
375 return switch (try parseRepr(s, &r)) {375 return switch (try parseRepr(s, &r)) {
376 ParseResult.Ok => convertRepr(T, r),376 ParseResult.Ok => convertRepr(T, r),
377 ParseResult.PlusZero => 0.0,377 ParseResult.PlusZero => 0.0,
378 ParseResult.MinusZero => -T(0.0),378 ParseResult.MinusZero => -@as(T, 0.0),
379 ParseResult.PlusInf => std.math.inf(T),379 ParseResult.PlusInf => std.math.inf(T),
380 ParseResult.MinusInf => -std.math.inf(T),380 ParseResult.MinusInf => -std.math.inf(T),
381 };381 };
...@@ -426,8 +426,8 @@ test "fmt.parseFloat" {...@@ -426,8 +426,8 @@ test "fmt.parseFloat" {
426 expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));426 expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
427427
428 expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));428 expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
429 expect(approxEq(T, try parseFloat(T, "-123142.1124"), T(-123142.1124), epsilon));429 expect(approxEq(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
430 expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), T(0.7062146892655368), epsilon));430 expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
431 }431 }
432 }432 }
433}433}
lib/std/heap.zig+2-2
...@@ -893,10 +893,10 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo...@@ -893,10 +893,10 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
893 if (mem.page_size << 2 > maxInt(usize)) return;893 if (mem.page_size << 2 > maxInt(usize)) return;
894894
895 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));895 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
896 const large_align = u29(mem.page_size << 2);896 const large_align = @as(u29, mem.page_size << 2);
897897
898 var align_mask: usize = undefined;898 var align_mask: usize = undefined;
899 _ = @shlWithOverflow(usize, ~@as(usize, 0), USizeShift(@ctz(u29, large_align)), &align_mask);899 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);
900900
901 var slice = try allocator.alignedAlloc(u8, large_align, 500);901 var slice = try allocator.alignedAlloc(u8, large_align, 500);
902 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));902 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
lib/std/io.zig+13-13
...@@ -355,19 +355,19 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {...@@ -355,19 +355,19 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
355355
356 out_bits.* = @as(usize, 0);356 out_bits.* = @as(usize, 0);
357 if (U == u0 or bits == 0) return 0;357 if (U == u0 or bits == 0) return 0;
358 var out_buffer = Buf(0);358 var out_buffer = @as(Buf, 0);
359359
360 if (self.bit_count > 0) {360 if (self.bit_count > 0) {
361 const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count;361 const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count;
362 const shift = u7_bit_count - n;362 const shift = u7_bit_count - n;
363 switch (endian) {363 switch (endian) {
364 builtin.Endian.Big => {364 builtin.Endian.Big => {
365 out_buffer = Buf(self.bit_buffer >> shift);365 out_buffer = @as(Buf, self.bit_buffer >> shift);
366 self.bit_buffer <<= n;366 self.bit_buffer <<= n;
367 },367 },
368 builtin.Endian.Little => {368 builtin.Endian.Little => {
369 const value = (self.bit_buffer << shift) >> shift;369 const value = (self.bit_buffer << shift) >> shift;
370 out_buffer = Buf(value);370 out_buffer = @as(Buf, value);
371 self.bit_buffer >>= n;371 self.bit_buffer >>= n;
372 },372 },
373 }373 }
...@@ -393,28 +393,28 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {...@@ -393,28 +393,28 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
393 if (n >= u8_bit_count) {393 if (n >= u8_bit_count) {
394 out_buffer <<= @intCast(u3, u8_bit_count - 1);394 out_buffer <<= @intCast(u3, u8_bit_count - 1);
395 out_buffer <<= 1;395 out_buffer <<= 1;
396 out_buffer |= Buf(next_byte);396 out_buffer |= @as(Buf, next_byte);
397 out_bits.* += u8_bit_count;397 out_bits.* += u8_bit_count;
398 continue;398 continue;
399 }399 }
400400
401 const shift = @intCast(u3, u8_bit_count - n);401 const shift = @intCast(u3, u8_bit_count - n);
402 out_buffer <<= @intCast(BufShift, n);402 out_buffer <<= @intCast(BufShift, n);
403 out_buffer |= Buf(next_byte >> shift);403 out_buffer |= @as(Buf, next_byte >> shift);
404 out_bits.* += n;404 out_bits.* += n;
405 self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1));405 self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1));
406 self.bit_count = shift;406 self.bit_count = shift;
407 },407 },
408 builtin.Endian.Little => {408 builtin.Endian.Little => {
409 if (n >= u8_bit_count) {409 if (n >= u8_bit_count) {
410 out_buffer |= Buf(next_byte) << @intCast(BufShift, out_bits.*);410 out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*);
411 out_bits.* += u8_bit_count;411 out_bits.* += u8_bit_count;
412 continue;412 continue;
413 }413 }
414414
415 const shift = @intCast(u3, u8_bit_count - n);415 const shift = @intCast(u3, u8_bit_count - n);
416 const value = (next_byte << shift) >> shift;416 const value = (next_byte << shift) >> shift;
417 out_buffer |= Buf(value) << @intCast(BufShift, out_bits.*);417 out_buffer |= @as(Buf, value) << @intCast(BufShift, out_bits.*);
418 out_bits.* += n;418 out_bits.* += n;
419 self.bit_buffer = @truncate(u7, next_byte >> @intCast(u3, n));419 self.bit_buffer = @truncate(u7, next_byte >> @intCast(u3, n));
420 self.bit_count = shift;420 self.bit_count = shift;
...@@ -949,14 +949,14 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -949,14 +949,14 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
949 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));949 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
950 }950 }
951951
952 var result = U(0);952 var result = @as(U, 0);
953 for (buffer) |byte, i| {953 for (buffer) |byte, i| {
954 switch (endian) {954 switch (endian) {
955 builtin.Endian.Big => {955 builtin.Endian.Big => {
956 result = (result << u8_bit_count) | byte;956 result = (result << u8_bit_count) | byte;
957 },957 },
958 builtin.Endian.Little => {958 builtin.Endian.Little => {
959 result |= U(byte) << @intCast(Log2U, u8_bit_count * i);959 result |= @as(U, byte) << @intCast(Log2U, u8_bit_count * i);
960 },960 },
961 }961 }
962 }962 }
...@@ -1050,7 +1050,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -1050,7 +1050,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
1050 return;1050 return;
1051 }1051 }
10521052
1053 ptr.* = OC(undefined); //make it non-null so the following .? is guaranteed safe1053 ptr.* = @as(OC, undefined); //make it non-null so the following .? is guaranteed safe
1054 const val_ptr = &ptr.*.?;1054 const val_ptr = &ptr.*.?;
1055 try self.deserializeInto(val_ptr);1055 try self.deserializeInto(val_ptr);
1056 },1056 },
...@@ -1154,7 +1154,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1154,7 +1154,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11541154
1155 switch (@typeId(T)) {1155 switch (@typeId(T)) {
1156 builtin.TypeId.Void => return,1156 builtin.TypeId.Void => return,
1157 builtin.TypeId.Bool => try self.serializeInt(u1(@boolToInt(value))),1157 builtin.TypeId.Bool => try self.serializeInt(@as(u1, @boolToInt(value))),
1158 builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value),1158 builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value),
1159 builtin.TypeId.Struct => {1159 builtin.TypeId.Struct => {
1160 const info = @typeInfo(T);1160 const info = @typeInfo(T);
...@@ -1197,10 +1197,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1197,10 +1197,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
1197 },1197 },
1198 builtin.TypeId.Optional => {1198 builtin.TypeId.Optional => {
1199 if (value == null) {1199 if (value == null) {
1200 try self.serializeInt(u1(@boolToInt(false)));1200 try self.serializeInt(@as(u1, @boolToInt(false)));
1201 return;1201 return;
1202 }1202 }
1203 try self.serializeInt(u1(@boolToInt(true)));1203 try self.serializeInt(@as(u1, @boolToInt(true)));
12041204
1205 const OC = comptime meta.Child(T);1205 const OC = comptime meta.Child(T);
1206 const val_ptr = &value.?;1206 const val_ptr = &value.?;
lib/std/io/test.zig+12-12
...@@ -226,18 +226,18 @@ test "BitOutStream" {...@@ -226,18 +226,18 @@ test "BitOutStream" {
226 const OutError = io.SliceOutStream.Error;226 const OutError = io.SliceOutStream.Error;
227 var bit_stream_be = io.BitOutStream(builtin.Endian.Big, OutError).init(&mem_out_be.stream);227 var bit_stream_be = io.BitOutStream(builtin.Endian.Big, OutError).init(&mem_out_be.stream);
228228
229 try bit_stream_be.writeBits(u2(1), 1);229 try bit_stream_be.writeBits(@as(u2, 1), 1);
230 try bit_stream_be.writeBits(u5(2), 2);230 try bit_stream_be.writeBits(@as(u5, 2), 2);
231 try bit_stream_be.writeBits(@as(u128, 3), 3);231 try bit_stream_be.writeBits(@as(u128, 3), 3);
232 try bit_stream_be.writeBits(@as(u8, 4), 4);232 try bit_stream_be.writeBits(@as(u8, 4), 4);
233 try bit_stream_be.writeBits(u9(5), 5);233 try bit_stream_be.writeBits(@as(u9, 5), 5);
234 try bit_stream_be.writeBits(u1(1), 1);234 try bit_stream_be.writeBits(@as(u1, 1), 1);
235235
236 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);236 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
237237
238 mem_out_be.pos = 0;238 mem_out_be.pos = 0;
239239
240 try bit_stream_be.writeBits(u15(0b110011010000101), 15);240 try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);
241 try bit_stream_be.flushBits();241 try bit_stream_be.flushBits();
242 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);242 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
243243
...@@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi...@@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
345 inline while (i <= max_test_bitsize) : (i += 1) {345 inline while (i <= max_test_bitsize) : (i += 1) {
346 const U = @IntType(false, i);346 const U = @IntType(false, i);
347 const S = @IntType(true, i);347 const S = @IntType(true, i);
348 try serializer.serializeInt(U(i));348 try serializer.serializeInt(@as(U, i));
349 if (i != 0) try serializer.serializeInt(S(-1)) else try serializer.serialize(S(0));349 if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0));
350 }350 }
351 try serializer.flush();351 try serializer.flush();
352352
...@@ -356,8 +356,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi...@@ -356,8 +356,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
356 const S = @IntType(true, i);356 const S = @IntType(true, i);
357 const x = try deserializer.deserializeInt(U);357 const x = try deserializer.deserializeInt(U);
358 const y = try deserializer.deserializeInt(S);358 const y = try deserializer.deserializeInt(S);
359 expect(x == U(i));359 expect(x == @as(U, i));
360 if (i != 0) expect(y == S(-1)) else expect(y == 0);360 if (i != 0) expect(y == @as(S, -1)) else expect(y == 0);
361 }361 }
362362
363 const u8_bit_count = comptime meta.bitCount(u8);363 const u8_bit_count = comptime meta.bitCount(u8);
...@@ -577,11 +577,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !v...@@ -577,11 +577,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !v
577 var in_stream = &in.stream;577 var in_stream = &in.stream;
578 var deserializer = io.Deserializer(endian, packing, InError).init(in_stream);578 var deserializer = io.Deserializer(endian, packing, InError).init(in_stream);
579579
580 try serializer.serialize(u14(3));580 try serializer.serialize(@as(u14, 3));
581 expectError(error.InvalidEnumTag, deserializer.deserialize(A));581 expectError(error.InvalidEnumTag, deserializer.deserialize(A));
582 out.pos = 0;582 out.pos = 0;
583 try serializer.serialize(u14(3));583 try serializer.serialize(@as(u14, 3));
584 try serializer.serialize(u14(88));584 try serializer.serialize(@as(u14, 88));
585 expectError(error.InvalidEnumTag, deserializer.deserialize(C));585 expectError(error.InvalidEnumTag, deserializer.deserialize(C));
586}586}
587587
lib/std/lazy_init.zig+1-1
...@@ -39,7 +39,7 @@ fn LazyInit(comptime T: type) type {...@@ -39,7 +39,7 @@ fn LazyInit(comptime T: type) type {
39 },39 },
40 2 => {40 2 => {
41 if (@sizeOf(T) == 0) {41 if (@sizeOf(T) == 0) {
42 return T(undefined);42 return @as(T, undefined);
43 } else {43 } else {
44 return &self.data;44 return &self.data;
45 }45 }
lib/std/math.zig+12-12
...@@ -543,8 +543,8 @@ test "math.absFloat" {...@@ -543,8 +543,8 @@ test "math.absFloat" {
543 comptime testAbsFloat();543 comptime testAbsFloat();
544}544}
545fn testAbsFloat() void {545fn testAbsFloat() void {
546 testing.expect(absFloat(f32(-10.05)) == 10.05);546 testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
547 testing.expect(absFloat(f32(10.05)) == 10.05);547 testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
548}548}
549549
550pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {550pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
...@@ -731,8 +731,8 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {...@@ -731,8 +731,8 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
731test "math.cast" {731test "math.cast" {
732 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));732 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
733 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));733 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
734 testing.expectError(error.Overflow, cast(u8, i8(-1)));734 testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
735 testing.expectError(error.Overflow, cast(u64, i8(-1)));735 testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
736736
737 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));737 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
738 testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8);738 testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8);
...@@ -786,9 +786,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T...@@ -786,9 +786,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
786 comptime assert(@typeId(T) == builtin.TypeId.Int);786 comptime assert(@typeId(T) == builtin.TypeId.Int);
787 comptime assert(!T.is_signed);787 comptime assert(!T.is_signed);
788 assert(value != 0);788 assert(value != 0);
789 comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1);789 comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
790 comptime const shiftType = std.math.Log2Int(promotedType);790 comptime const shiftType = std.math.Log2Int(PromotedType);
791 return promotedType(1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));791 return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
792}792}
793793
794/// Returns the next power of two (if the value is not already a power of two).794/// Returns the next power of two (if the value is not already a power of two).
...@@ -797,8 +797,8 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T...@@ -797,8 +797,8 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
797pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {797pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
798 comptime assert(@typeId(T) == builtin.TypeId.Int);798 comptime assert(@typeId(T) == builtin.TypeId.Int);
799 comptime assert(!T.is_signed);799 comptime assert(!T.is_signed);
800 comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1);800 comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
801 comptime const overflowBit = promotedType(1) << T.bit_count;801 comptime const overflowBit = @as(PromotedType, 1) << T.bit_count;
802 var x = ceilPowerOfTwoPromote(T, value);802 var x = ceilPowerOfTwoPromote(T, value);
803 if (overflowBit & x != 0) {803 if (overflowBit & x != 0) {
804 return error.Overflow;804 return error.Overflow;
...@@ -848,7 +848,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) {...@@ -848,7 +848,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
848pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {848pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
849 assert(x != 0);849 assert(x != 0);
850 const log2_val = log2_int(T, x);850 const log2_val = log2_int(T, x);
851 if (T(1) << log2_val == x)851 if (@as(T, 1) << log2_val == x)
852 return log2_val;852 return log2_val;
853 return log2_val + 1;853 return log2_val + 1;
854}854}
...@@ -870,8 +870,8 @@ pub fn lossyCast(comptime T: type, value: var) T {...@@ -870,8 +870,8 @@ pub fn lossyCast(comptime T: type, value: var) T {
870 switch (@typeInfo(@typeOf(value))) {870 switch (@typeInfo(@typeOf(value))) {
871 builtin.TypeId.Int => return @intToFloat(T, value),871 builtin.TypeId.Int => return @intToFloat(T, value),
872 builtin.TypeId.Float => return @floatCast(T, value),872 builtin.TypeId.Float => return @floatCast(T, value),
873 builtin.TypeId.ComptimeInt => return T(value),873 builtin.TypeId.ComptimeInt => return @as(T, value),
874 builtin.TypeId.ComptimeFloat => return T(value),874 builtin.TypeId.ComptimeFloat => return @as(T, value),
875 else => @compileError("bad type"),875 else => @compileError("bad type"),
876 }876 }
877}877}
lib/std/math/big/int.zig+10-10
...@@ -281,7 +281,7 @@ pub const Int = struct {...@@ -281,7 +281,7 @@ pub const Int = struct {
281 var w_value: UT = if (value < 0) @intCast(UT, -value) else @intCast(UT, value);281 var w_value: UT = if (value < 0) @intCast(UT, -value) else @intCast(UT, value);
282282
283 if (info.bits <= Limb.bit_count) {283 if (info.bits <= Limb.bit_count) {
284 self.limbs[0] = Limb(w_value);284 self.limbs[0] = @as(Limb, w_value);
285 self.metadata += 1;285 self.metadata += 1;
286 } else {286 } else {
287 var i: usize = 0;287 var i: usize = 0;
...@@ -453,7 +453,7 @@ pub const Int = struct {...@@ -453,7 +453,7 @@ pub const Int = struct {
453 for (self.limbs[0..self.len()]) |limb| {453 for (self.limbs[0..self.len()]) |limb| {
454 var shift: usize = 0;454 var shift: usize = 0;
455 while (shift < Limb.bit_count) : (shift += base_shift) {455 while (shift < Limb.bit_count) : (shift += base_shift) {
456 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & Limb(base - 1));456 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & @as(Limb, base - 1));
457 const ch = try digitToChar(r, base);457 const ch = try digitToChar(r, base);
458 try digits.append(ch);458 try digits.append(ch);
459 }459 }
...@@ -560,7 +560,7 @@ pub const Int = struct {...@@ -560,7 +560,7 @@ pub const Int = struct {
560 /// Returns -1, 0, 1 if a < b, a == b or a > b respectively.560 /// Returns -1, 0, 1 if a < b, a == b or a > b respectively.
561 pub fn cmp(a: Int, b: Int) i8 {561 pub fn cmp(a: Int, b: Int) i8 {
562 if (a.isPositive() != b.isPositive()) {562 if (a.isPositive() != b.isPositive()) {
563 return if (a.isPositive()) i8(1) else -1;563 return if (a.isPositive()) @as(i8, 1) else -1;
564 } else {564 } else {
565 const r = cmpAbs(a, b);565 const r = cmpAbs(a, b);
566 return if (a.isPositive()) r else -r;566 return if (a.isPositive()) r else -r;
...@@ -785,7 +785,7 @@ pub const Int = struct {...@@ -785,7 +785,7 @@ pub const Int = struct {
785 const c1: Limb = @boolToInt(@addWithOverflow(Limb, a, carry.*, &r1));785 const c1: Limb = @boolToInt(@addWithOverflow(Limb, a, carry.*, &r1));
786786
787 // r2 = b * c787 // r2 = b * c
788 const bc = DoubleLimb(math.mulWide(Limb, b, c));788 const bc = @as(DoubleLimb, math.mulWide(Limb, b, c));
789 const r2 = @truncate(Limb, bc);789 const r2 = @truncate(Limb, bc);
790 const c2 = @truncate(Limb, bc >> Limb.bit_count);790 const c2 = @truncate(Limb, bc >> Limb.bit_count);
791791
...@@ -1084,7 +1084,7 @@ pub const Int = struct {...@@ -1084,7 +1084,7 @@ pub const Int = struct {
1084 rem.* = 0;1084 rem.* = 0;
1085 for (a) |_, ri| {1085 for (a) |_, ri| {
1086 const i = a.len - ri - 1;1086 const i = a.len - ri - 1;
1087 const pdiv = ((DoubleLimb(rem.*) << Limb.bit_count) | a[i]);1087 const pdiv = ((@as(DoubleLimb, rem.*) << Limb.bit_count) | a[i]);
10881088
1089 if (pdiv == 0) {1089 if (pdiv == 0) {
1090 quo[i] = 0;1090 quo[i] = 0;
...@@ -1143,9 +1143,9 @@ pub const Int = struct {...@@ -1143,9 +1143,9 @@ pub const Int = struct {
1143 if (x.limbs[i] == y.limbs[t]) {1143 if (x.limbs[i] == y.limbs[t]) {
1144 q.limbs[i - t - 1] = maxInt(Limb);1144 q.limbs[i - t - 1] = maxInt(Limb);
1145 } else {1145 } else {
1146 const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]);1146 const num = (@as(DoubleLimb, x.limbs[i]) << Limb.bit_count) | @as(DoubleLimb, x.limbs[i - 1]);
1147 const z = @intCast(Limb, num / DoubleLimb(y.limbs[t]));1147 const z = @intCast(Limb, num / @as(DoubleLimb, y.limbs[t]));
1148 q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else Limb(z);1148 q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else @as(Limb, z);
1149 }1149 }
11501150
1151 // 3.21151 // 3.2
...@@ -1362,7 +1362,7 @@ test "big.int comptime_int set" {...@@ -1362,7 +1362,7 @@ test "big.int comptime_int set" {
13621362
1363 comptime var i: usize = 0;1363 comptime var i: usize = 0;
1364 inline while (i < s_limb_count) : (i += 1) {1364 inline while (i < s_limb_count) : (i += 1) {
1365 const result = Limb(s & maxInt(Limb));1365 const result = @as(Limb, s & maxInt(Limb));
1366 s >>= Limb.bit_count / 2;1366 s >>= Limb.bit_count / 2;
1367 s >>= Limb.bit_count / 2;1367 s >>= Limb.bit_count / 2;
1368 testing.expect(a.limbs[i] == result);1368 testing.expect(a.limbs[i] == result);
...@@ -1377,7 +1377,7 @@ test "big.int comptime_int set negative" {...@@ -1377,7 +1377,7 @@ test "big.int comptime_int set negative" {
1377}1377}
13781378
1379test "big.int int set unaligned small" {1379test "big.int int set unaligned small" {
1380 var a = try Int.initSet(al, u7(45));1380 var a = try Int.initSet(al, @as(u7, 45));
13811381
1382 testing.expect(a.limbs[0] == 45);1382 testing.expect(a.limbs[0] == 45);
1383 testing.expect(a.isPositive() == true);1383 testing.expect(a.isPositive() == true);
lib/std/math/complex.zig+4-4
...@@ -133,8 +133,8 @@ test "complex.div" {...@@ -133,8 +133,8 @@ test "complex.div" {
133 const b = Complex(f32).new(2, 7);133 const b = Complex(f32).new(2, 7);
134 const c = a.div(b);134 const c = a.div(b);
135135
136 testing.expect(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and136 testing.expect(math.approxEq(f32, c.re, @as(f32, 31) / 53, epsilon) and
137 math.approxEq(f32, c.im, f32(-29) / 53, epsilon));137 math.approxEq(f32, c.im, @as(f32, -29) / 53, epsilon));
138}138}
139139
140test "complex.conjugate" {140test "complex.conjugate" {
...@@ -148,8 +148,8 @@ test "complex.reciprocal" {...@@ -148,8 +148,8 @@ test "complex.reciprocal" {
148 const a = Complex(f32).new(5, 3);148 const a = Complex(f32).new(5, 3);
149 const c = a.reciprocal();149 const c = a.reciprocal();
150150
151 testing.expect(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and151 testing.expect(math.approxEq(f32, c.re, @as(f32, 5) / 34, epsilon) and
152 math.approxEq(f32, c.im, f32(-3) / 34, epsilon));152 math.approxEq(f32, c.im, @as(f32, -3) / 34, epsilon));
153}153}
154154
155test "complex.magnitude" {155test "complex.magnitude" {
lib/std/math/complex/acos.zig+1-1
...@@ -8,7 +8,7 @@ const Complex = cmath.Complex;...@@ -8,7 +8,7 @@ const Complex = cmath.Complex;
8pub fn acos(z: var) Complex(@typeOf(z.re)) {8pub fn acos(z: var) Complex(@typeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @typeOf(z.re);
10 const q = cmath.asin(z);10 const q = cmath.asin(z);
11 return Complex(T).new(T(math.pi) / 2 - q.re, -q.im);11 return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im);
12}12}
1313
14const epsilon = 0.0001;14const epsilon = 0.0001;
lib/std/math/complex/ldexp.zig+1-1
...@@ -65,7 +65,7 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {...@@ -65,7 +65,7 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
65fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {65fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
66 var ex_expt: i32 = undefined;66 var ex_expt: i32 = undefined;
67 const exp_x = frexp_exp64(z.re, &ex_expt);67 const exp_x = frexp_exp64(z.re, &ex_expt);
68 const exptf = i64(expt + ex_expt);68 const exptf = @as(i64, expt + ex_expt);
6969
70 const half_expt1 = @divTrunc(exptf, 2);70 const half_expt1 = @divTrunc(exptf, 2);
71 const scale1 = @bitCast(f64, (0x3ff + half_expt1) << 20);71 const scale1 = @bitCast(f64, (0x3ff + half_expt1) << 20);
lib/std/math/exp.zig+1-1
...@@ -134,7 +134,7 @@ fn exp64(x_: f64) f64 {...@@ -134,7 +134,7 @@ fn exp64(x_: f64) f64 {
134 }134 }
135 if (x < -708.39641853226410622) {135 if (x < -708.39641853226410622) {
136 // underflow if x != -inf136 // underflow if x != -inf
137 // math.forceEval(f32(-0x1.0p-149 / x));137 // math.forceEval(@as(f32, -0x1.0p-149 / x));
138 if (x < -745.13321910194110842) {138 if (x < -745.13321910194110842) {
139 return 0;139 return 0;
140 }140 }
lib/std/math/ln.zig+1-1
...@@ -34,7 +34,7 @@ pub fn ln(x: var) @typeOf(x) {...@@ -34,7 +34,7 @@ pub fn ln(x: var) @typeOf(x) {
34 return @typeOf(1)(math.floor(ln_64(@as(f64, x))));34 return @typeOf(1)(math.floor(ln_64(@as(f64, x))));
35 },35 },
36 TypeId.Int => {36 TypeId.Int => {
37 return T(math.floor(ln_64(@as(f64, x))));37 return @as(T, math.floor(ln_64(@as(f64, x))));
38 },38 },
39 else => @compileError("ln not implemented for " ++ @typeName(T)),39 else => @compileError("ln not implemented for " ++ @typeName(T)),
40 }40 }
lib/std/math/log.zig+2-2
...@@ -64,8 +64,8 @@ test "math.log float" {...@@ -64,8 +64,8 @@ test "math.log float" {
64}64}
6565
66test "math.log float_special" {66test "math.log float_special" {
67 expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));67 expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
68 expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974)));68 expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
6969
70 expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));70 expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
71 expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));71 expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
lib/std/math/log10.zig+1-1
...@@ -177,7 +177,7 @@ pub fn log10_64(x_: f64) f64 {...@@ -177,7 +177,7 @@ pub fn log10_64(x_: f64) f64 {
177}177}
178178
179test "math.log10" {179test "math.log10" {
180 testing.expect(log10(f32(0.2)) == log10_32(0.2));180 testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
181 testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));181 testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
182}182}
183183
lib/std/math/sqrt.zig+2-2
...@@ -15,7 +15,7 @@ const maxInt = std.math.maxInt;...@@ -15,7 +15,7 @@ const maxInt = std.math.maxInt;
15pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {15pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {
16 const T = @typeOf(x);16 const T = @typeOf(x);
17 switch (@typeId(T)) {17 switch (@typeId(T)) {
18 TypeId.ComptimeFloat => return T(@sqrt(f64, x)), // TODO upgrade to f12818 TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128
19 TypeId.Float => return @sqrt(T, x),19 TypeId.Float => return @sqrt(T, x),
20 TypeId.ComptimeInt => comptime {20 TypeId.ComptimeInt => comptime {
21 if (x > maxInt(u128)) {21 if (x > maxInt(u128)) {
...@@ -24,7 +24,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ...@@ -24,7 +24,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
24 if (x < 0) {24 if (x < 0) {
25 @compileError("sqrt on negative number");25 @compileError("sqrt on negative number");
26 }26 }
27 return T(sqrt_int(u128, x));27 return @as(T, sqrt_int(u128, x));
28 },28 },
29 TypeId.Int => return sqrt_int(T, x),29 TypeId.Int => return sqrt_int(T, x),
30 else => @compileError("sqrt not implemented for " ++ @typeName(T)),30 else => @compileError("sqrt not implemented for " ++ @typeName(T)),
lib/std/meta.zig+1-1
...@@ -341,7 +341,7 @@ test "std.meta.TagType" {...@@ -341,7 +341,7 @@ test "std.meta.TagType" {
341///Returns the active tag of a tagged union341///Returns the active tag of a tagged union
342pub fn activeTag(u: var) @TagType(@typeOf(u)) {342pub fn activeTag(u: var) @TagType(@typeOf(u)) {
343 const T = @typeOf(u);343 const T = @typeOf(u);
344 return @TagType(T)(u);344 return @as(@TagType(T), u);
345}345}
346346
347test "std.meta.activeTag" {347test "std.meta.activeTag" {
lib/std/net.zig+4-4
...@@ -117,7 +117,7 @@ pub const IpAddress = extern union {...@@ -117,7 +117,7 @@ pub const IpAddress = extern union {
117 ip_slice[10] = 0xff;117 ip_slice[10] = 0xff;
118 ip_slice[11] = 0xff;118 ip_slice[11] = 0xff;
119119
120 const ptr = @sliceToBytes((*const [1]u32)(&addr)[0..]);120 const ptr = @sliceToBytes(@as(*const [1]u32, &addr)[0..]);
121121
122 ip_slice[12] = ptr[0];122 ip_slice[12] = ptr[0];
123 ip_slice[13] = ptr[1];123 ip_slice[13] = ptr[1];
...@@ -161,7 +161,7 @@ pub const IpAddress = extern union {...@@ -161,7 +161,7 @@ pub const IpAddress = extern union {
161 .addr = undefined,161 .addr = undefined,
162 },162 },
163 };163 };
164 const out_ptr = @sliceToBytes((*[1]u32)(&result.in.addr)[0..]);164 const out_ptr = @sliceToBytes(@as(*[1]u32, &result.in.addr)[0..]);
165165
166 var x: u8 = 0;166 var x: u8 = 0;
167 var index: u8 = 0;167 var index: u8 = 0;
...@@ -271,7 +271,7 @@ pub const IpAddress = extern union {...@@ -271,7 +271,7 @@ pub const IpAddress = extern union {
271 },271 },
272 os.AF_INET6 => {272 os.AF_INET6 => {
273 const port = mem.bigToNative(u16, self.in6.port);273 const port = mem.bigToNative(u16, self.in6.port);
274 if (mem.eql(u8, self.in6.addr[0..12], [_]u8{0,0,0,0,0,0,0,0,0,0,0xff,0xff})) {274 if (mem.eql(u8, self.in6.addr[0..12], [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
275 try std.fmt.format(275 try std.fmt.format(
276 context,276 context,
277 Errors,277 Errors,
...@@ -1133,7 +1133,7 @@ fn resMSendRc(...@@ -1133,7 +1133,7 @@ fn resMSendRc(
1133 }1133 }
11341134
1135 // Wait for a response, or until time to retry1135 // Wait for a response, or until time to retry
1136 const clamped_timeout = std.math.min(u31(std.math.maxInt(u31)), t1 + retry_interval - t2);1136 const clamped_timeout = std.math.min(@as(u31, std.math.maxInt(u31)), t1 + retry_interval - t2);
1137 const nevents = os.poll(&pfd, clamped_timeout) catch 0;1137 const nevents = os.poll(&pfd, clamped_timeout) catch 0;
1138 if (nevents == 0) continue;1138 if (nevents == 0) continue;
11391139
lib/std/os/linux/test.zig+3-3
...@@ -72,7 +72,7 @@ test "statx" {...@@ -72,7 +72,7 @@ test "statx" {
72 expect(stat_buf.mode == statx_buf.mode);72 expect(stat_buf.mode == statx_buf.mode);
73 expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);73 expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
74 expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);74 expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
75 expect(@bitCast(u64, i64(stat_buf.size)) == statx_buf.size);75 expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
76 expect(@bitCast(u64, i64(stat_buf.blksize)) == statx_buf.blksize);76 expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
77 expect(@bitCast(u64, i64(stat_buf.blocks)) == statx_buf.blocks);77 expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
78}78}
lib/std/packed_int_array.zig+9-9
...@@ -193,7 +193,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,...@@ -193,7 +193,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,
193 ///Initialize a packed array using an unpacked array193 ///Initialize a packed array using an unpacked array
194 /// or, more likely, an array literal.194 /// or, more likely, an array literal.
195 pub fn init(ints: [int_count]Int) Self {195 pub fn init(ints: [int_count]Int) Self {
196 var self = Self(undefined);196 var self = @as(Self, undefined);
197 for (ints) |int, i| self.set(i, int);197 for (ints) |int, i| self.set(i, int);
198 return self;198 return self;
199 }199 }
...@@ -328,11 +328,11 @@ test "PackedIntArray" {...@@ -328,11 +328,11 @@ test "PackedIntArray" {
328 const expected_bytes = ((bits * int_count) + 7) / 8;328 const expected_bytes = ((bits * int_count) + 7) / 8;
329 testing.expect(@sizeOf(PackedArray) == expected_bytes);329 testing.expect(@sizeOf(PackedArray) == expected_bytes);
330330
331 var data = PackedArray(undefined);331 var data = @as(PackedArray, undefined);
332332
333 //write values, counting up333 //write values, counting up
334 var i = @as(usize, 0);334 var i = @as(usize, 0);
335 var count = I(0);335 var count = @as(I, 0);
336 while (i < data.len()) : (i += 1) {336 while (i < data.len()) : (i += 1) {
337 data.set(i, count);337 data.set(i, count);
338 if (bits > 0) count +%= 1;338 if (bits > 0) count +%= 1;
...@@ -376,7 +376,7 @@ test "PackedIntSlice" {...@@ -376,7 +376,7 @@ test "PackedIntSlice" {
376376
377 //write values, counting up377 //write values, counting up
378 var i = @as(usize, 0);378 var i = @as(usize, 0);
379 var count = I(0);379 var count = @as(I, 0);
380 while (i < data.len()) : (i += 1) {380 while (i < data.len()) : (i += 1) {
381 data.set(i, count);381 data.set(i, count);
382 if (bits > 0) count +%= 1;382 if (bits > 0) count +%= 1;
...@@ -402,7 +402,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {...@@ -402,7 +402,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
402 const Int = @IntType(false, bits);402 const Int = @IntType(false, bits);
403403
404 const PackedArray = PackedIntArray(Int, int_count);404 const PackedArray = PackedIntArray(Int, int_count);
405 var packed_array = PackedArray(undefined);405 var packed_array = @as(PackedArray, undefined);
406406
407 const limit = (1 << bits);407 const limit = (1 << bits);
408408
...@@ -463,7 +463,7 @@ test "PackedIntSlice accumulating bit offsets" {...@@ -463,7 +463,7 @@ test "PackedIntSlice accumulating bit offsets" {
463 // anything463 // anything
464 {464 {
465 const PackedArray = PackedIntArray(u3, 16);465 const PackedArray = PackedIntArray(u3, 16);
466 var packed_array = PackedArray(undefined);466 var packed_array = @as(PackedArray, undefined);
467467
468 var packed_slice = packed_array.slice(0, packed_array.len());468 var packed_slice = packed_array.slice(0, packed_array.len());
469 var i = @as(usize, 0);469 var i = @as(usize, 0);
...@@ -473,7 +473,7 @@ test "PackedIntSlice accumulating bit offsets" {...@@ -473,7 +473,7 @@ test "PackedIntSlice accumulating bit offsets" {
473 }473 }
474 {474 {
475 const PackedArray = PackedIntArray(u11, 88);475 const PackedArray = PackedIntArray(u11, 88);
476 var packed_array = PackedArray(undefined);476 var packed_array = @as(PackedArray, undefined);
477477
478 var packed_slice = packed_array.slice(0, packed_array.len());478 var packed_slice = packed_array.slice(0, packed_array.len());
479 var i = @as(usize, 0);479 var i = @as(usize, 0);
...@@ -518,8 +518,8 @@ test "PackedInt(Array/Slice) sliceCast" {...@@ -518,8 +518,8 @@ test "PackedInt(Array/Slice) sliceCast" {
518 i = 0;518 i = 0;
519 while (i < packed_slice_cast_3.len()) : (i += 1) {519 while (i < packed_slice_cast_3.len()) : (i += 1) {
520 const val = switch (builtin.endian) {520 const val = switch (builtin.endian) {
521 .Big => if (i % 2 == 0) u3(0b111) else u3(0b000),521 .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
522 .Little => if (i % 2 == 0) u3(0b111) else u3(0b000),522 .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
523 };523 };
524 testing.expect(packed_slice_cast_3.get(i) == val);524 testing.expect(packed_slice_cast_3.get(i) == val);
525 }525 }
lib/std/rand.zig+4-4
...@@ -93,13 +93,13 @@ pub const Random = struct {...@@ -93,13 +93,13 @@ pub const Random = struct {
93 // http://www.pcg-random.org/posts/bounded-rands.html93 // http://www.pcg-random.org/posts/bounded-rands.html
94 // "Lemire's (with an extra tweak from me)"94 // "Lemire's (with an extra tweak from me)"
95 var x: Small = r.int(Small);95 var x: Small = r.int(Small);
96 var m: Large = Large(x) * Large(less_than);96 var m: Large = @as(Large, x) * @as(Large, less_than);
97 var l: Small = @truncate(Small, m);97 var l: Small = @truncate(Small, m);
98 if (l < less_than) {98 if (l < less_than) {
99 // TODO: workaround for https://github.com/ziglang/zig/issues/177099 // TODO: workaround for https://github.com/ziglang/zig/issues/1770
100 // should be:100 // should be:
101 // var t: Small = -%less_than;101 // var t: Small = -%less_than;
102 var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), Small(less_than)));102 var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), @as(Small, less_than)));
103103
104 if (t >= less_than) {104 if (t >= less_than) {
105 t -= less_than;105 t -= less_than;
...@@ -109,7 +109,7 @@ pub const Random = struct {...@@ -109,7 +109,7 @@ pub const Random = struct {
109 }109 }
110 while (l < t) {110 while (l < t) {
111 x = r.int(Small);111 x = r.int(Small);
112 m = Large(x) * Large(less_than);112 m = @as(Large, x) * @as(Large, less_than);
113 l = @truncate(Small, m);113 l = @truncate(Small, m);
114 }114 }
115 }115 }
...@@ -286,7 +286,7 @@ pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {...@@ -286,7 +286,7 @@ pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
286 // adapted from:286 // adapted from:
287 // http://www.pcg-random.org/posts/bounded-rands.html287 // http://www.pcg-random.org/posts/bounded-rands.html
288 // "Integer Multiplication (Biased)"288 // "Integer Multiplication (Biased)"
289 var m: T2 = T2(random_int) * T2(less_than);289 var m: T2 = @as(T2, random_int) * @as(T2, less_than);
290 return @intCast(T, m >> T.bit_count);290 return @intCast(T, m >> T.bit_count);
291}291}
292292
lib/std/unicode.zig+8-8
...@@ -7,10 +7,10 @@ const mem = std.mem;...@@ -7,10 +7,10 @@ const mem = std.mem;
7/// Returns how many bytes the UTF-8 representation would require7/// Returns how many bytes the UTF-8 representation would require
8/// for the given codepoint.8/// for the given codepoint.
9pub fn utf8CodepointSequenceLength(c: u32) !u3 {9pub fn utf8CodepointSequenceLength(c: u32) !u3 {
10 if (c < 0x80) return u3(1);10 if (c < 0x80) return @as(u3, 1);
11 if (c < 0x800) return u3(2);11 if (c < 0x800) return @as(u3, 2);
12 if (c < 0x10000) return u3(3);12 if (c < 0x10000) return @as(u3, 3);
13 if (c < 0x110000) return u3(4);13 if (c < 0x110000) return @as(u3, 4);
14 return error.CodepointTooLarge;14 return error.CodepointTooLarge;
15}15}
1616
...@@ -18,10 +18,10 @@ pub fn utf8CodepointSequenceLength(c: u32) !u3 {...@@ -18,10 +18,10 @@ pub fn utf8CodepointSequenceLength(c: u32) !u3 {
18/// returns a number 1-4 indicating the total length of the codepoint in bytes.18/// returns a number 1-4 indicating the total length of the codepoint in bytes.
19/// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte.19/// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte.
20pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {20pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {
21 if (first_byte < 0b10000000) return u3(1);21 if (first_byte < 0b10000000) return @as(u3, 1);
22 if (first_byte & 0b11100000 == 0b11000000) return u3(2);22 if (first_byte & 0b11100000 == 0b11000000) return @as(u3, 2);
23 if (first_byte & 0b11110000 == 0b11100000) return u3(3);23 if (first_byte & 0b11110000 == 0b11100000) return @as(u3, 3);
24 if (first_byte & 0b11111000 == 0b11110000) return u3(4);24 if (first_byte & 0b11111000 == 0b11110000) return @as(u3, 4);
25 return error.Utf8InvalidStartByte;25 return error.Utf8InvalidStartByte;
26}26}
2727
src-self-hosted/stage1.zig+1-1
...@@ -224,7 +224,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {...@@ -224,7 +224,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
224 }224 }
225 if (flags.present("check")) {225 if (flags.present("check")) {
226 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);226 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
227 const code = if (anything_changed) u8(1) else u8(0);227 const code = if (anything_changed) @as(u8, 1) else @as(u8, 0);
228 process.exit(code);228 process.exit(code);
229 }229 }
230230
src-self-hosted/translate_c.zig+1-1
...@@ -123,7 +123,7 @@ const Context = struct {...@@ -123,7 +123,7 @@ const Context = struct {
123 fn locStr(c: *Context, loc: ZigClangSourceLocation) ![]u8 {123 fn locStr(c: *Context, loc: ZigClangSourceLocation) ![]u8 {
124 const spelling_loc = ZigClangSourceManager_getSpellingLoc(c.source_manager, loc);124 const spelling_loc = ZigClangSourceManager_getSpellingLoc(c.source_manager, loc);
125 const filename_c = ZigClangSourceManager_getFilename(c.source_manager, spelling_loc);125 const filename_c = ZigClangSourceManager_getFilename(c.source_manager, spelling_loc);
126 const filename = if (filename_c) |s| try c.str(s) else ([]const u8)("(no file)");126 const filename = if (filename_c) |s| try c.str(s) else @as([]const u8, "(no file)");
127127
128 const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc);128 const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc);
129 const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc);129 const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc);
test/compile_errors.zig+5-5
...@@ -1332,7 +1332,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1332,7 +1332,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1332 cases.add(1332 cases.add(
1333 "@bitCast with different sizes inside an expression",1333 "@bitCast with different sizes inside an expression",
1334 \\export fn entry() void {1334 \\export fn entry() void {
1335 \\ var foo = (@bitCast(u8, f32(1.0)) == 0xf);1335 \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
1336 \\}1336 \\}
1337 ,1337 ,
1338 "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4",1338 "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4",
...@@ -2120,13 +2120,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2120,13 +2120,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2120 cases.add(2120 cases.add(
2121 "@floatToInt comptime safety",2121 "@floatToInt comptime safety",
2122 \\comptime {2122 \\comptime {
2123 \\ _ = @floatToInt(i8, f32(-129.1));2123 \\ _ = @floatToInt(i8, @as(f32, -129.1));
2124 \\}2124 \\}
2125 \\comptime {2125 \\comptime {
2126 \\ _ = @floatToInt(u8, f32(-1.1));2126 \\ _ = @floatToInt(u8, @as(f32, -1.1));
2127 \\}2127 \\}
2128 \\comptime {2128 \\comptime {
2129 \\ _ = @floatToInt(u8, f32(256.1));2129 \\ _ = @floatToInt(u8, @as(f32, 256.1));
2130 \\}2130 \\}
2131 ,2131 ,
2132 "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'",2132 "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'",
...@@ -3888,7 +3888,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3888,7 +3888,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3888 \\const lit_int_x = 1 / 0;3888 \\const lit_int_x = 1 / 0;
3889 \\const lit_float_x = 1.0 / 0.0;3889 \\const lit_float_x = 1.0 / 0.0;
3890 \\const int_x = @as(u32, 1) / @as(u32, 0);3890 \\const int_x = @as(u32, 1) / @as(u32, 0);
3891 \\const float_x = f32(1.0) / f32(0.0);3891 \\const float_x = @as(f32, 1.0) / @as(f32, 0.0);
3892 \\3892 \\
3893 \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }3893 \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }
3894 \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); }3894 \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); }