Skip to content

Commit

Permalink
binomial_distribution: mitigate undocumented behaviour
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Pignotto authored Jan 21, 2023
1 parent 046dc9d commit 0d79c40
Showing 1 changed file with 1 addition and 1 deletion.
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));
_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

0 comments on commit 0d79c40

Please sign in to comment.