lib/number.js
/**
* FUNCTION: binomcoef( n, k )
*	Computes the binomial coefficient of two numeric values.
*
* @param {Number} n - input value
* @param {Number} k - second input value
* @returns {Number} function value
*/
binomcoef( n, k )
Computes the binomial coefficient of two numeric values.
binomcoef ( n k ) Computes the binomial coefficient of two numeric values .
function binomcoef( n, k ) {
	var res, j;
	if ( isInteger( n ) && isInteger( k ) ) {
		if ( n < 0 ) {
			res = binomcoef( -n + k - 1, k );
			if ( isodd( k ) ) {
				res = -res;
			}
			return res;
		}
		if( n < k ) {
			return 0;
		}
		if ( n - k < k ) {
			k = n - k;
		}
		if (k <	 0) {
			return 0;
		} else if (k === 0) {
			return 1;
		} else {
			res = n;
			for( j = 2; j <= k; j++ ) {
				res *= ( n - j + 1 ) / j;
			}
			return !isInteger( res ) ? round( res ) : res;
		}
	} else {
		res = - log( n + 1 ) - betaln( n - k + 1, k + 1 );
		return exp( res );
	}
} 
function binomcoef ( n , k ) { var res , j ; if ( isInteger ( n ) && isInteger ( k ) ) { if ( n < 0 ) { res = binomcoef ( - n + k - 1 , k ) ; if ( isodd ( k ) ) { res = - res ; } return res ; } if ( n < k ) { return 0 ; } if ( n - k < k ) { k = n - k ; } if ( k < 0 ) { return 0 ; } else if ( k === 0 ) { return 1 ; } else { res = n ; for ( j = 2 ; j <= k ; j ++ ) { res *= ( n - j + 1 ) / j ; } return ! isInteger ( res ) ? round ( res ) : res ; } } else { res = - log ( n + 1 ) - betaln ( n - k + 1 , k + 1 ) ; return exp ( res ) ; } }
FUNCTION: binomcoef( n, k )
Computes the binomial coefficient of two numeric values.
FUNCTION : binomcoef ( n k ) Computes the binomial coefficient of two numeric values .
// use recursive definition // correct for rounding errors // generalized version for real numbers // end FUNCTION binomcoef()