Calculating Factorials using Stirling Approximation | Function for calculating factorial ; value of natural e ; evaluating factorial using stirling approximation ; Driver Code
< ? php function stirlingFactorial ( $ n ) { if ( $ n == 1 ) return 1 ; $ z ; $ e = 2.71 ; $ z = sqrt ( 2 * 3.14 * $ n ) * pow ( ( $ n / $ e ) , $ n ) ; return floor ( $ z ) ; } echo stirlingFactorial ( 1 ) , " STRNEWLINE " ; echo stirlingFactorial ( 2 ) , " STRNEWLINE " ; echo stirlingFactorial ( 3 ) , " STRNEWLINE " ; echo stirlingFactorial ( 4 ) , " STRNEWLINE " ; echo stirlingFactorial ( 5 ) , " STRNEWLINE " ; echo stirlingFactorial ( 6 ) , " ▁ STRNEWLINE " ; echo stirlingFactorial ( 7 ) , " ▁ STRNEWLINE " ; ? >