This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.
pubfnnext_f64(random: Random, comptimetables: ZigTable) f64 {
while (true) {
// We manually construct a float from parts as we can avoid an extra random lookup here by
// using the unused exponent for the lookup table entry.
constbits = random.int(u64);
consti = @as(usize, @as(u8, @truncate(bits)));
constu = blk: {
if (tables.is_symmetric) {
// Generate a value in the range [2, 4) and scale into [-1, 1)constrepr = ((0x3ff + 1) << 52) | (bits >> 12);
break :blk@as(f64, @bitCast(repr)) - 3.0;
} else {
// Generate a value in the range [1, 2) and scale into (0, 1)constrepr = (0x3ff << 52) | (bits >> 12);
break :blk@as(f64, @bitCast(repr)) - (1.0 - math.floatEps(f64) / 2.0);
}
};
constx = u * tables.x[i];
consttest_x = if (tables.is_symmetric) @abs(x) elsex;
// equivalent to |u| < tables.x[i+1] / tables.x[i] (or u < tables.x[i+1] / tables.x[i])if (test_x < tables.x[i + 1]) {
returnx;
}
if (i == 0) {
returntables.zero_case(random, u);
}
// equivalent to f1 + DRanU() * (f0 - f1) < 1if (tables.f[i + 1] + (tables.f[i] - tables.f[i + 1]) * random.float(f64) < tables.pdf(x)) {
returnx;
}
}
}