Calculating Factorials using Stirling Approximation | Function for calculating factorial ; value of natural e ; evaluating factorial using stirling approximation ; Driver Code
function stirlingFactorial ( n ) { if ( n == 1 ) return 1 ; let z ; let e = 2.71 ; z = Math . sqrt ( 2 * 3.14 * n ) * Math . pow ( ( n / e ) , n ) ; return Math . floor ( z ) ; } document . write ( stirlingFactorial ( 1 ) + " " ) ; document . write ( stirlingFactorial ( 2 ) + " " ) ; document . write ( stirlingFactorial ( 3 ) + " " ) ; document . write ( stirlingFactorial ( 4 ) + " " ) ; document . write ( stirlingFactorial ( 5 ) + " " ) ; document . write ( stirlingFactorial ( 6 ) + " " ) ; document . write ( stirlingFactorial ( 7 ) + " " ) ;