| Home | Libraries | People | FAQ | More

#### Double Factorial

    #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.

##### Accuracy

The implementation uses a trivial adaptation of the factorial function, so error rates should be no more than a couple of epsilon higher.

##### Testing

The spot tests for the double factorial use data generated by functions.wolfram.com.

##### Implementation

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)