Skip to content

Commit 0d79c40

Browse files
authored
binomial_distribution: mitigate undocumented 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
1 parent 046dc9d commit 0d79c40

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libstdc++-v3/include/bits/random.tcc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
15001500
// sqrt(pi / 2)
15011501
const double __spi_2 = 1.2533141373155002512078826424055226L;
15021502
_M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1503-
_M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
1503+
_M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4. * _M_t * __1p));
15041504
_M_c = 2 * _M_d1 / __np;
15051505
_M_a1 = std::exp(_M_c) * _M_s1 * __spi_2;
15061506
const double __a12 = _M_a1 + _M_s2 * __spi_2;

0 commit comments

Comments
 (0)