We're updating the issue view to help you get more done. 

Include a float generator

Description

There seems to be a demand for a general float generator.

One of the bigger issues with a float generator is shrinking, which is not straightforward. intially considered including a small implementation, using fmap to coerce a ratio into a float:

1 2 3 4 (def float (gen/fmap float gen/ratio)) (gen/sample float 20) ;; => (0.0 0.0 -1.0 0.0 -1.0 0.75 0.5 0.8 -2.0 -0.5714286 2.6666667 -2.0 ;; -0.46153846 -0.125 -12.0 -1.75 -2.4 0.41666666 0.64285713 -1.125)

The Haskell implementation is performing float shrinking through fractions.

implemented a bigdec generator using ideas from data.generators, but mentioned that manipulating the long and int bits would be more performant. However, such shrinking would require good knowledge on how IEEE 754 works, in order to avoid bugs whenever shrinking is performed.

A slower, but more understandable and portable double generator was also suggested, again by . The implementation of said generator could be found at https://gist.github.com/cemerick/7599452

Original issue - GitHub #36

Environment

None

Status

Assignee

Reid Draper

Reporter

hyPiRion

Labels

None

Approval

None

Patch

None

Priority

Minor