From 9869e7a5152cc8e4e2a410c20820992d8bbcd405 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Fri, 10 Jul 2020 07:08:07 -0400 Subject: [PATCH] Fix binomial_coefficient forwarding policy This addresses an issue where unintended double-promotion could occur. See #398. --- include/boost/math/special_functions/binomial.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/boost/math/special_functions/binomial.hpp b/include/boost/math/special_functions/binomial.hpp index 9a24fc15b..2bbc1fb25 100644 --- a/include/boost/math/special_functions/binomial.hpp +++ b/include/boost/math/special_functions/binomial.hpp @@ -63,7 +63,13 @@ T binomial_coefficient(unsigned n, unsigned k, const Policy& pol) template <> inline float binomial_coefficient >(unsigned n, unsigned k, const policies::policy<>& pol) { - return policies::checked_narrowing_cast >(binomial_coefficient(n, k, pol), "boost::math::binomial_coefficient<%1%>(unsigned,unsigned)"); + typedef policies::normalise< + policies::policy<>, + policies::promote_float, + policies::promote_double, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + return policies::checked_narrowing_cast(binomial_coefficient(n, k, forwarding_policy()), "boost::math::binomial_coefficient<%1%>(unsigned,unsigned)"); } template