-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document float/double algorithms #640
Comments
Yes, please add. Baffling to have a prng library with no way of generating floats. |
Hi! Where can I find the snippets? |
From https://fast-check.dev/docs/core-blocks/arbitraries/primitives/number/#float: fc.noBias(fc.integer({ min: 0, max: (1 << 24) - 1 }).map((v) => v / (1 << 24)));
// generate a in range [0 (included), (1 << 24) - 1 (included)] then compute "a / (1 << 24)" From https://fast-check.dev/docs/core-blocks/arbitraries/primitives/number/#double: fc.noBias(
fc
.tuple(fc.integer({ min: 0, max: (1 << 26) - 1 }), fc.integer({ min: 0, max: (1 << 27) - 1 }))
.map((v) => (v[0] * Math.pow(2, 27) + v[1]) * Math.pow(2, -53)),
);
// generate a in range [0 (included), (1 << 26) - 1 (included)]
// generate b in range [0 (included), (1 << 27) - 1 (included)]
// then compute "(a * Math.pow(2, 27) + b) * Math.pow(2, -53)" |
Thanks! I'm just doing But get I installed with pnpm and can see the |
No need to use fast-check if the only thing you need is to generate random floating point value. My example with fast-check was just a quick extract of a code doing the conversion of an integer value to a floating point one. Regarding |
Thanks for the clarification. I had tried that int method and it worked.
and that seemed to work just fine too. |
Documentation of pure-rand updated at: #715 |
How to generate floats or doubles out of an integer value?
Note: We have snippets doing so in fast-check
The text was updated successfully, but these errors were encountered: