-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversion to 64-bit float #21
Comments
The relevant code is here: https://github.com/rust-random/rand/blob/master/src/distributions/float.rs#L102 (except We implement three cases:
Yes, none of these are perfect (since values smaller than We also had an implementation using exactly 32/64 random bits, but ended up not using it: rust-random/rand#372 Yes, we (especially @pitdicker and @sicking) thought a lot about this. You think more of this should be in the book? |
They're totally fine (maybe the methods returning just 52 bits should be marked). I do the same. I'm not commenting that, I'm commenting the book. The phrase above in the book does not sound anything like whay you're describing. It sounds like the method I put a link to. |
In the book, I read:
"f64: we treat this as an approximation of the real numbers, and, by convention, restrict to the range 0 to 1 (if not otherwise specified). Note that this type has finite precision, so we use the coin-flipping method above (but with random bits instead of coins) until we get as much precision as the type can represent; however, since floating-point numbers are much more precise close to 0 than they are near 1, we typically simplify here and stop once we have enough precision to differentiate between 1 and the next smallest value representable (1 - ε/2)."
This looks like you're generating float values using the high-precision methods described here: http://prng.di.unimi.it/random_real.c
But when I look at the code (sorry, I don't speak Rust, so this might be wrong) looks like you're using the multiplication-free method that gives 52 bits of precision instead of 53. Is it so? In this case, maybe this should be specified in the book.
The text was updated successfully, but these errors were encountered: