File tree 1 file changed +6
-0
lines changed
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -255,6 +255,9 @@ pub const Random = struct {
255
255
// represent every possible value in the available range.
256
256
switch (T ) {
257
257
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.
258
261
const rand = r .int (u64 );
259
262
var rand_lz = @clz (u64 , rand | 0x7FFFFF );
260
263
if (rand_lz == 41 ) {
@@ -269,6 +272,9 @@ pub const Random = struct {
269
272
return @bitCast (f32 , exponent | mantissa );
270
273
},
271
274
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.
272
278
const rand = r .int (u64 );
273
279
var rand_lz : u64 = @clz (u64 , rand | 0xFFFFFFFFFFFFF );
274
280
if (rand_lz == 12 ) {
You can’t perform that action at this time.
0 commit comments