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

Conversation

Pignotto
Copy link

In param_type::_M_initialize(): Change integer literal to corresponding floating-point literal in multiplication by _M_t to avoid unsigned overflow and consequent chain of unpredicted behaviour

In param_type::_M_initialize(): Change integer literal to corresponding floating-point literal in multiplication by _M_t to avoid unsigned overflow and consequent chain of unpredicted behaviour
@@ -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

@Pignotto Pignotto changed the title binomial_distribution: mitigate undocumented behaviour random.tcc: binomial_distribution: mitigate undocumented behaviour Jan 21, 2023
@MLopez-Ibanez
Copy link

This is a read-only mirror that is not managed by GCC developers.

Pull requests in this read-only mirror will be ignored forever.

If you wish to contribute to GCC please read: https://gcc.gnu.org/wiki/GettingStarted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants