File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -165,9 +165,16 @@ module Gen = struct
165165
166166 let bool st = RS. bool st
167167
168- let float st =
169- exp (RS. float st 15. *. (if RS. float st 1. < 0.5 then 1. else - 1. ))
170- *. (if RS. float st 1. < 0.5 then 1. else - 1. )
168+ let float st = (* switch to [bits64] once lower bound reaches 4.14 *)
169+ (* Technically we could write [15] but this is clearer *)
170+ let four_bits_mask = 0b1111 in
171+ (* Top 4 bits *)
172+ let left = Int64. (shift_left (of_int (RS. bits st land four_bits_mask)) 60 ) in
173+ (* Middle 30 bits *)
174+ let middle = Int64. (shift_left (of_int (RS. bits st)) 30 ) in
175+ (* Bottom 30 bits *)
176+ let right = Int64. of_int (RS. bits st) in
177+ Int64. (float_of_bits (logor left (logor middle right)))
171178
172179 let pfloat st = abs_float (float st)
173180 let nfloat st = -. (pfloat st)
Original file line number Diff line number Diff line change @@ -397,10 +397,16 @@ module Gen = struct
397397 then Tree. Tree (true , Seq. return false_gen)
398398 else false_gen
399399
400- let float : float t = fun st ->
401- let x = exp (RS. float st 15. *. (if RS. bool st then 1. else - 1. ))
402- *. (if RS. bool st then 1. else - 1. )
403- in
400+ let float : float t = fun st -> (* switch to [bits64] once lower bound reaches 4.14 *)
401+ (* Technically we could write [15] but this is clearer *)
402+ let four_bits_mask = 0b1111 in
403+ (* Top 4 bits *)
404+ let left = Int64. (shift_left (of_int (RS. bits st land four_bits_mask)) 60 ) in
405+ (* Middle 30 bits *)
406+ let middle = Int64. (shift_left (of_int (RS. bits st)) 30 ) in
407+ (* Bottom 30 bits *)
408+ let right = Int64. of_int (RS. bits st) in
409+ let x = Int64. (float_of_bits (logor left (logor middle right))) in
404410 let shrink a = fun () -> Shrink. float_towards 0. a () in
405411 Tree. make_primitive shrink x
406412
You can’t perform that action at this time.
0 commit comments