-
-
Couldn't load subscription status.
- Fork 476
UniformFloat: allow inclusion of high in all cases #1462
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
Conversation
|
I should add that there is still a loop in |
I don't like this argument, because when calculating probabilities with real numbers, there is no difference between I agree we should fix #1462.
I think you meant |
With real numbers, both
Meanwhile, we still provide
I think you meant #1299? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks
|
I am now reasonably convinced that there are no Definition: Assumption:
Case 1: Case 2: In fact, I believe case 2 can only happen where the division causes a loss of precision (i.e. increases the exponent since (We could thus potentially replace the loop with a single-step if, and I think we could remove it entirely for |
CHANGELOG.mdentrySummary
Fix #1299 by removing logic specific to ensuring that we emulate a closed range by excluding
highfrom the result.Motivation
Fix #1299.
Additional motivation: floating-point types are approximations of continuous (real) numbers. Although one might expect that
rng.gen_range(0f32..1f32)is strictly less than1f32, it can also be seen as an approximation of the real range[0, 1)which includes values whose nearest approximation underf32is1f32.In general, one can always expect that floating-point numbers may round up/down to the nearest representable value, hence this change is not expected to affect many users.
sample_singlewas changed (see below) as a simplification, and to match the new behaviour ofnew.Details
Specific to floats (i.e.
UniformFloat),newsetsscale = high - low(unchanged) then ensures thatlow + scale * max_rand <= high(previously: ensure< high)new_inclusivesetsscale = (high - low) / (1 - ε)then ensures thatlow + scale * max_rand <= high(unchanged)sample_singleis now equivalent tosample_single_inclusive(previously: use rejection sampling to ensuresample < high)sample_single_inclusiveis unchanged: it yieldslow + (high-low) * Standard.samgle(rng)Note:
newattempts to ensure thathighmay be yielded;sample_single_inclusivedoes not. This has not changed, but is a little surprising.