-
Notifications
You must be signed in to change notification settings - Fork 6
/
size_errol.zig
40 lines (33 loc) · 1.04 KB
/
size_errol.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut();
var buf: [10000]u8 = undefined;
inline for (.{ f128, f80, c_longdouble, f64, f32, f16 }) |T| {
var g = RandomGenerator(T).init(0);
const f = g.next() orelse unreachable;
const c = try std.fmt.bufPrint(&buf, "{}", .{@as(T, f)});
_ = try stdout.write(c);
_ = try stdout.write(" :" ++ @typeName(T) ++ "\n");
}
}
pub fn RandomGenerator(comptime F: type) type {
return struct {
const I = std.meta.Int(.unsigned, @bitSizeOf(F));
rng: std.Random.DefaultPrng,
pub fn init(seed: anytype) @This() {
return .{
.rng = std.Random.DefaultPrng.init(seed),
};
}
pub fn next(g: *@This()) ?F {
return @bitCast(g.rng.random().int(I));
}
};
}
pub fn panic(format: []const u8, trace: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn {
_ = format;
_ = trace;
_ = ret_addr;
@setCold(true);
while (true) {}
}