question: public static double lnFactorial ( int x ) { if ( x < 0 ) throw new IllegalArgumentException ( "Invalid input to factorial: " + x ) ; else if ( x > 32 ) return lnGamma ( x + 1 ) ; else { int l = factorialsBuffer . size ( ) ; for ( int i = l ; i <= x ; i ++ ) { factorialsBuffer . add ( log ( i ) + factorialsBuffer . get ( i - 1 ) ) ; } return factorialsBuffer . get ( x ) ; } }
target:  Get the log of the factorial of a number. Upto 32, the factorial is exact. After that, the gamma function is used because the numbers can't be represented anyway.