Commit 3e94347e61

tgschultz <tgschultz@gmail.com>
2018-06-27 18:30:15
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
1 parent 1b4bae6
Changed files (2)
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"),
         }
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;
+}