Crystallography/Mathematics/GammaFunction.cs
/// <summary>
/// Returns a factorial of an integer number (n!)
/// </summary>
/// <param name="n">The value to be factorialized</param>
/// <returns>The double precision result</returns>
Returns a factorial of an integer number (n!)
Returns a factorial of an integer number ( n! )
public static double Factorial(int n)
        {
            int ntop = 4;
            double[] a = new double[32];
            a[0] = 1.0; a[1] = 1.0; a[2] = 2.0; a[3] = 6.0; a[4] = 24.0;
            int j;
            if (n < 0)
                throw new ArgumentException("Factorial expects a positive argument", "n");
            if (n > 32)
                return Math.Exp(GammaLn(n + 1.0));
            while (ntop < n)
            {
                j = ntop++;
                a[ntop] = a[j] * ntop;
            }
            return a[n];
        }
public static double Factorial ( int n ) { int ntop = 4 ; double [ ] a = new double [ 32 ] ; a [ 0 ] = 1.0 ; a [ 1 ] = 1.0 ; a [ 2 ] = 2.0 ; a [ 3 ] = 6.0 ; a [ 4 ] = 24.0 ; int j ; if ( n < 0 ) throw new ArgumentException ( " " , " " ) ; if ( n > 32 ) return Math . Exp ( GammaLn ( n + 1.0 ) ) ; while ( ntop < n ) { j = ntop ++ ; a [ ntop ] = a [ j ] * ntop ; } return a [ n ] ; }
Returns a factorial of an integer number (n!)
Returns a factorial of an integer number ( n! )
// TODO: check
The double precision result
The double precision result
n
int
The value to be factorialized
The value to be factorialized