-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<random>: Fix discrete_distribution result out of range #1025
<random>: Fix discrete_distribution result out of range #1025
Conversation
Mathematically, _Par0._Pcdf.back() should be one. However, when it is actually slightly smaller than one due to rounding error, there is a small probability that _Px > _Par0._Pcdf.back() and the original code returns the invalid value of _Par0._Pcdf.size().
Question: do we add a (randomized?) test for low probability For this particular bug, the probability of returning an invalid result on each call is on the order of |
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.
Related: Should we consider making _Pcdf
an element shorter - leaving the final element as an implicit 1
- when we next break ABI?
It would be nice to have at least a simple regression test with the repro from the issue. I wouldn't refuse a randomized test, but it seems like that test wouldn't provide much additional marginal coverage. (If you do choose to write a randomized test it needs to dump enough info to reproduce errors when found a la:
|
Use _Prev_iter Co-authored-by: Casey Carter <cartec69@gmail.com>
This comment has been minimized.
This comment has been minimized.
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.
Just a couple of style issues.
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.
Thanks! This looks great; I'll go ahead and push changes for a couple of conventions that we follow.
tests/std/tests/GH_001017_discrete_distribution_out_of_range/bad_random_engine.hpp
Outdated
Show resolved
Hide resolved
tests/std/tests/GH_001017_discrete_distribution_out_of_range/bad_random_engine.hpp
Outdated
Show resolved
Hide resolved
Thanks for the bugfix, @statementreply! |
Mathematically, `_Par0._Pcdf.back()` should be one. However, when it is actually slightly smaller than one due to rounding error, there is a small probability that `_Px > _Par0._Pcdf.back()` and the original code returns the invalid value of `_Par0._Pcdf.size()`.
Fix #1017.
Mathematically,
_Par0._Pcdf.back()
should be one. However, when it is actually slightly smaller than one due to rounding error, there is a small probability that_Px > _Par0._Pcdf.back()
, and the original code returns the invalid value of_Par0._Pcdf.size()
.