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
This commit is contained in:
tgschultz 2018-06-27 11:30:15 -05:00 committed by Andrew Kelley
parent 1b4bae6d69
commit 3e94347e61
2 changed files with 8 additions and 4 deletions

View File

@ -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"),
}
@ -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"),
}

View File

@ -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;
@ -160,3 +160,7 @@ test "ziggurant exp dist sanity" {
_ = prng.random.floatExp(f64);
}
}
test "ziggurat table gen" {
const table = NormDist;
}