Skip to content

Commit 7dba763

Browse files
committed
Rewrite explanatory comments
1 parent 86b091e commit 7dba763

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/std/rand.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ pub const Random = struct {
255255
// represent every possible value in the available range.
256256
switch (T) {
257257
f32 => {
258+
// Use 23 random bits for the mantissa, and the rest for the exponent.
259+
// If all 41 bits are zero, generate additional random bits, until a
260+
// set bit is found, or 126 bits have been generated.
258261
const rand = r.int(u64);
259262
var rand_lz = @clz(u64, rand | 0x7FFFFF);
260263
if (rand_lz == 41) {
@@ -269,6 +272,9 @@ pub const Random = struct {
269272
return @bitCast(f32, exponent | mantissa);
270273
},
271274
f64 => {
275+
// Use 52 random bits for the mantissa, and the rest for the exponent.
276+
// If all 12 bits are zero, generate additional random bits, until a
277+
// set bit is found, or 1022 bits have been generated.
272278
const rand = r.int(u64);
273279
var rand_lz: u64 = @clz(u64, rand | 0xFFFFFFFFFFFFF);
274280
if (rand_lz == 12) {

0 commit comments

Comments
 (0)