authorgravatar for tgschultz@gmail.comtgschultz <tgschultz@gmail.com> 2018-06-27 11:30:15-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-27 12:30:15-04:00
log3e94347e6152dd9a88f4bceb46bbc245ed7cef98
treeb58eddbcf200ac3ee8c5ebb2bf89d45aa0236061
parent1b4bae6d69937043add14c0dac357c1a1b05f037

Fix up some std.rand syntax #1161 (#1162)

* Fix old syntax in rand Ziggurat somehow did not get updated to latest syntax * Fix broken float casts f32 float casts somehow not updated to latest syntax

2 files changed, 8 insertions(+), 4 deletions(-)

std/rand/index.zig+2-2
...@@ -116,7 +116,7 @@ pub const Random = struct {...@@ -116,7 +116,7 @@ pub const Random = struct {
116 pub fn floatNorm(r: *Random, comptime T: type) T {116 pub fn floatNorm(r: *Random, comptime T: type) T {
117 const value = ziggurat.next_f64(r, ziggurat.NormDist);117 const value = ziggurat.next_f64(r, ziggurat.NormDist);
118 switch (T) {118 switch (T) {
119 f32 => return f32(value),119 f32 => return @floatCast(f32, value),
120 f64 => return value,120 f64 => return value,
121 else => @compileError("unknown floating point type"),121 else => @compileError("unknown floating point type"),
122 }122 }
...@@ -128,7 +128,7 @@ pub const Random = struct {...@@ -128,7 +128,7 @@ pub const Random = struct {
128 pub fn floatExp(r: *Random, comptime T: type) T {128 pub fn floatExp(r: *Random, comptime T: type) T {
129 const value = ziggurat.next_f64(r, ziggurat.ExpDist);129 const value = ziggurat.next_f64(r, ziggurat.ExpDist);
130 switch (T) {130 switch (T) {
131 f32 => return f32(value),131 f32 => return @floatCast(f32, value),
132 f64 => return value,132 f64 => return value,
133 else => @compileError("unknown floating point type"),133 else => @compileError("unknown floating point type"),
134 }134 }
std/rand/ziggurat.zig+6-2
...@@ -84,12 +84,12 @@ fn ZigTableGen(...@@ -84,12 +84,12 @@ fn ZigTableGen(
8484
85 for (tables.x[2..256]) |*entry, i| {85 for (tables.x[2..256]) |*entry, i| {
86 const last = tables.x[2 + i - 1];86 const last = tables.x[2 + i - 1];
87 *entry = f_inv(v / last + f(last));87 entry.* = f_inv(v / last + f(last));
88 }88 }
89 tables.x[256] = 0;89 tables.x[256] = 0;
9090
91 for (tables.f[0..]) |*entry, i| {91 for (tables.f[0..]) |*entry, i| {
92 *entry = f(tables.x[i]);92 entry.* = f(tables.x[i]);
93 }93 }
9494
95 return tables;95 return tables;
...@@ -160,3 +160,7 @@ test "ziggurant exp dist sanity" {...@@ -160,3 +160,7 @@ test "ziggurant exp dist sanity" {
160 _ = prng.random.floatExp(f64);160 _ = prng.random.floatExp(f64);
161 }161 }
162}162}
163
164test "ziggurat table gen" {
165 const table = NormDist;
166}