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

random.tcc: binomial_distribution: mitigate undocumented behaviour #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libstdc++-v3/include/bits/random.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// sqrt(pi / 2)
const double __spi_2 = 1.2533141373155002512078826424055226L;
_M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
_M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
_M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4. * _M_t * __1p));
Copy link
Author

@Pignotto Pignotto Jan 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular, for values of _M_t that overflow to 0 by the 4* multiplication, the operator()(_UniformRandomNumberGenerator& __urng, const param_type& __param) hangs in an infinite loop as noted and described on https://stackoverflow.com/q/75179395/15114624

_M_c = 2 * _M_d1 / __np;
_M_a1 = std::exp(_M_c) * _M_s1 * __spi_2;
const double __a12 = _M_a1 + _M_s2 * __spi_2;
Expand Down