Opened 8 years ago

#10241 new Feature Requests

Please relax template constraints of boost::math::binomial_coefficient

Reported by: der-storch-85@… Owned by: John Maddock
Milestone: To Be Determined Component: math
Version: Boost 1.55.0 Severity: Optimization
Keywords: Cc:

Description

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);
}

Change History (0)

Note: See TracTickets for help on using tickets.