This function computes the double factorial value for a positive integer argument using arbitrary-precision.
The double factorial of N is defined as the product of every positive integer greater than of equal to 1 with the same parity as N in the range from 1 up to and including N. The parity simply refers to whether an integer is an odd number or an even number.
If (N) is even, then the double factorial is the product of 2 and all the other even integers up to (N). If (N) is odd, then the double factorial is the product of 1 and all the other odd integers up to (N). See the examples below.
The double factorial values of 0 and −1 are equated to 1 by definition, but double factorial values for integers that are less than −1 are not defined.
The function returns FALSE on ERROR if (N) is non-numeric or (N < −1).
Below is the PHP source code for a function to compute the arbitrary-precision double factorial.
Double-Click to select ALL code
Double-Click to select ALL code
The above equation is really two equations in one.
For even numbers:
For odd numbers:
Combined equation that will handle both even and odd numbers:
This is the equation implemented by the function.
Below is a table of double factorials for N = −1 to N = 100, followed by the PHP source code used to compute it. The table was computed using the above double factorial function.