/** * GAMMA FUNCTION * gamma function for approximating factorials. * @param z Only works for 1 <= z <= 142 but also defined for non integers. * @returns approximation to (z-1)! * @author Roedy Green */ static double gamma(double z) { return Math.exp( -z ) * Math.pow( z, z - 0.5 ) * Math.sqrt( 2 * Math.PI ) * ( 1 + 1 / ( 12 * z ) + 1 / ( 288 * z * z ) - 139 / ( 51840 * z * z * z ) - 571 / ( 2488320 * z * z * z * z )); }