commit 3e94347e6152dd9a88f4bceb46bbc245ed7cef98 (tree)
parent 1b4bae6d69937043add14c0dac357c1a1b05f037
Author: tgschultz <tgschultz@gmail.com>
Date: Wed, 27 Jun 2018 11:30:15 -0500
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
Diffstat:
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/std/rand/index.zig b/std/rand/index.zig
@@ -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"),
}
diff --git a/std/rand/ziggurat.zig b/std/rand/ziggurat.zig
@@ -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;
+}