Subject: [Boost-bugs] [Boost C++ Libraries] #10241: Please relax template constraints of boost::math::binomial_coefficient
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-07-24 15:46:22
#10241: Please relax template constraints of boost::math::binomial_coefficient
------------------------------+--------------------------
Reporter: der-storch-85@⦠| Owner: johnmaddock
Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: math
Version: Boost 1.55.0 | Severity: Optimization
Keywords: |
------------------------------+--------------------------
boost::math::binomial_coefficient may up to now only be used with floating
point types. See also ticket #3100.
This constraint has two problems:
It yields in inaccurate calculations, i. e.
{{{
static_cast<long long
unsigned>(boost::math::binomial_coefficient<double>(60, 30));
}}}
is
118264581564861408
but should be
118264581564861424.
(long long unsigned and double are both 8 byte on my machine.)
And it does not make sense for very large or arbitrary-precision integer
types: boost::math::binomial_coefficient<boost::multiprecision::cpp_int>
would work great if you let it do so.
At the moment it is not possible just to release integer types as template
argument, you have to add an extra implementation, i. e. this one with
unsigned k and n as input:
{{{
Inttype result = 1;
k = std::min(k, n-k);
for (unsigned i = 1; i < k+1; ++i)
{
result *= Inttype(n-k+i);
result /= Inttype(i);
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/10241> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC