(self, n, log=True)
Caclulates (or approximates) the (log of the) factorial n!. The function applies Stirling's approximation if n>20.

        @param n: computes factorial of n
        @param log: whether or not to return the (natural) logarithm of the factorial
Caclulates (or approximates) the (log of the) factorial n!. The function applies Stirling's approximation if n>20.
Caclulates ( or approximates ) the ( log of the ) factorial n! . The function applies Stirling s approximation if n > 20 .
def factorial(self, n, log=True):
        """
        Caclulates (or approximates) the (log of the) factorial n!. The function applies Stirling's approximation if n>20.

        @param n: computes factorial of n
        @param log: whether or not to return the (natural) logarithm of the factorial
        """
        f = _np.float64(0)
        n_ = _np.float64(n)
        if n > 20: # use Stirling's approximation
            try:
                f = n_ * _np.log(n_)-n_ + 0.5 * _np.log(2.0*_np.pi*n_)+1.0/(12.0*n_)-1/(360.0*n_**3.0)
            except Warning as w:
                Log.add('Factorial calculation for n = ' + str(n)+ ': ' + str(w), severity=Severity.WARNING)

        else:
            f = _np.log(_np.math.factorial(n))

        if log:
            return f
        else:
            return _np.exp(f)
def factorial ( self , n , log = True ) : f = _np . float64 ( 0 ) n_ = _np . float64 ( n ) if n > 20 : # use Stirling's approximation try : f = n_ * _np . log ( n_ ) - n_ + 0.5 * _np . log ( 2.0 * _np . pi * n_ ) + 1.0 / ( 12.0 * n_ ) - 1 / ( 360.0 * n_ ** 3.0 ) except Warning as w : Log . add ( 'Factorial calculation for n = ' + str ( n ) + ': ' + str ( w ) , severity = Severity . WARNING ) else : f = _np . log ( _np . math . factorial ( n ) ) if log : return f else : return _np . exp ( f )