From b75f4873828203704f2878b4173202f4fbe712af Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Tue, 2 Dec 2025 12:39:27 +0100 Subject: [PATCH 1/2] Add reproducer test set --- test/Jamfile.v2 | 1 + test/github_issue_150.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/github_issue_150.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index ff83427a9..17157527d 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -88,6 +88,7 @@ run test_comp_xoshiro128f.cpp ; run github_issue_133.cpp ; run github_issue_147.cpp ; +run github_issue_150.cpp ; run niederreiter_base2_validate.cpp /boost/test//boost_unit_test_framework ; run sobol_validate.cpp /boost/test//boost_unit_test_framework ; diff --git a/test/github_issue_150.cpp b/test/github_issue_150.cpp new file mode 100644 index 000000000..d0fe2b716 --- /dev/null +++ b/test/github_issue_150.cpp @@ -0,0 +1,25 @@ +/* +* Copyright Matt Borland 2025. + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id$ + */ + +#include +#include +#include +#include + +int main() +{ + std::mt19937_64 gen; + boost::random::binomial_distribution dist; + + BOOST_TEST(dist(gen) >= 0); + + return boost::report_errors(); +} From 88d6840a19455fe0e6ecd18fb8be48e4de2cf420 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Tue, 2 Dec 2025 12:39:36 +0100 Subject: [PATCH 2/2] Cast arguments prior to taking abs --- include/boost/random/binomial_distribution.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/random/binomial_distribution.hpp b/include/boost/random/binomial_distribution.hpp index 78d1a123a..a98d53b51 100644 --- a/include/boost/random/binomial_distribution.hpp +++ b/include/boost/random/binomial_distribution.hpp @@ -321,7 +321,7 @@ class binomial_distribution { IntType k = static_cast(floor((2*_u.btrd.a/us + _u.btrd.b)*u + _u.btrd.c)); if(k < 0 || k > _t) continue; v = v*_u.btrd.alpha/(_u.btrd.a/(us*us) + _u.btrd.b); - RealType km = abs(k - m); + RealType km = abs(static_cast(k) - static_cast(m)); if(km <= 15) { RealType f = 1; if(m < k) {