Skip to content

Commit

Permalink
Fix up some std.rand syntax #1161 (#1162)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tgschultz authored and andrewrk committed Jun 27, 2018
1 parent 1b4bae6 commit 3e94347
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions std/rand/index.zig
Expand Up @@ -116,7 +116,7 @@ pub const Random = struct {
pub fn floatNorm(r: *Random, comptime T: type) T {
const value = ziggurat.next_f64(r, ziggurat.NormDist);
switch (T) {
f32 => return f32(value),
f32 => return @floatCast(f32, value),
f64 => return value,
else => @compileError("unknown floating point type"),
}
Expand All @@ -128,7 +128,7 @@ pub const Random = struct {
pub fn floatExp(r: *Random, comptime T: type) T {
const value = ziggurat.next_f64(r, ziggurat.ExpDist);
switch (T) {
f32 => return f32(value),
f32 => return @floatCast(f32, value),
f64 => return value,
else => @compileError("unknown floating point type"),
}
Expand Down
8 changes: 6 additions & 2 deletions std/rand/ziggurat.zig
Expand Up @@ -84,12 +84,12 @@ fn ZigTableGen(

for (tables.x[2..256]) |*entry, i| {
const last = tables.x[2 + i - 1];
*entry = f_inv(v / last + f(last));
entry.* = f_inv(v / last + f(last));
}
tables.x[256] = 0;

for (tables.f[0..]) |*entry, i| {
*entry = f(tables.x[i]);
entry.* = f(tables.x[i]);
}

return tables;
Expand Down Expand Up @@ -160,3 +160,7 @@ test "ziggurant exp dist sanity" {
_ = prng.random.floatExp(f64);
}
}

test "ziggurat table gen" {
const table = NormDist;
}

0 comments on commit 3e94347

Please sign in to comment.