-
-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
UniformFloat: allow inclusion of high in all cases #1462
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.md
entrySummary
Fix #1299 by removing logic specific to ensuring that we emulate a closed range by excluding
high
from 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 underf32
is1f32
.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_single
was changed (see below) as a simplification, and to match the new behaviour ofnew
.Details
Specific to floats (i.e.
UniformFloat
),new
setsscale = high - low
(unchanged) then ensures thatlow + scale * max_rand <= high
(previously: ensure< high
)new_inclusive
setsscale = (high - low) / (1 - ε)
then ensures thatlow + scale * max_rand <= high
(unchanged)sample_single
is now equivalent tosample_single_inclusive
(previously: use rejection sampling to ensuresample < high
)sample_single_inclusive
is unchanged: it yieldslow + (high-low) * Standard.samgle(rng)
Note:
new
attempts to ensure thathigh
may be yielded;sample_single_inclusive
does not. This has not changed, but is a little surprising.