-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ivy: add an operator, rand, for floating-point random numbers
APL (or maybe just Dyalog) uses ?0 for a float in the range [0,1), which we could do but it's clunky. We also can't just do ?1.0 because numbers are reduced before hitting the operator: 0.5 becomes rational 1/2 and 1.0 becomes integer one. Instead, we add a new operator, rand, that behaves exactly like the roll operator ? but ranges over all floats in [0, n) instead of just integers. To get high-precision random floats, we create two integers with the size of the mantissa and divide them, rand()/2^floatPrec, to get a high-precision mantissa, then scale it appropriately. I doubt it's mathematically perfect but it seems pretty good; I included a test to show that it gives mean and standard deviations as expected. Fixes #167
- Loading branch information
Showing
5 changed files
with
184 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters