Skip to content
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

[BUG] next_float and next_double return values in range [0,1] #2400

Open
ChuckHastings opened this issue Jul 30, 2024 · 1 comment
Open

[BUG] next_float and next_double return values in range [0,1] #2400

ChuckHastings opened this issue Jul 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ChuckHastings
Copy link
Contributor

Describe the bug
The code that implements next_float and next_double that occurs here:

can generate the value 0 (when val is 0) and the value 1. The value 1 is more subtle, but occurs when the floating point representation of val and the floating point representation of (1U << 24) or (1LU << 53) [for doubles] are equivalent.

The consequence of this is that usual assumptions about using random floating point values to compute with are violated.

Note that #493 includes some discussion on this item. I suspect the issue is worse than just a discrepancy between Philox and PCG.

Steps/Code to reproduce bug
I was able to reproduce the error in a simple CUDA program to that converted

uint32_t num_u{0xffffff};
uint32_t denom_u{0x1000000};

to floating point values and computed the division, and the corresponding uint64_t values the same way.

Expected behavior
The standard is for floating point values to be uniformly distributed between [0, 1).

Environment details (please complete the following information):
Should fail on all. I tested on this configuration:

  • Environment location: Bare-metal
  • Method of RAFT install: conda

Additional context
Seems like directly constructing the bit pattern for the floating point value might be better than relying on division.

@ChuckHastings ChuckHastings added the bug Something isn't working label Jul 30, 2024
@ChuckHastings
Copy link
Contributor Author

https://mina86.com/2016/random-reals/ does a nice job of explaining the flaw and suggests a bit-masking solution to creating the value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant