...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
#include <boost/math/special_functions/factorials.hpp>
namespace boost{ namespace math{ template <class T> T double_factorial(unsigned i); template <class T, class Policy> T double_factorial(unsigned i, const Policy&); }} // namespaces
Returns i!!
.
The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.
May return the result of overflow_error if the result is too large to represent in type T. The implementation is designed to be optimised for small i where table lookup of i! is possible.
The implementation uses a trivial adaptation of the factorial function, so error rates should be no more than a couple of epsilon higher.
The spot tests for the double factorial use data generated by functions.wolfram.com.
The double factorial is implemented in terms of the factorial and gamma functions using the relations:
(2n)!! = 2n * n!
(2n+1)!! = (2n+1)! / (2n n!)
and
(2n-1)!! = Γ((2n+1)/2) * 2n / sqrt(pi)