% p_binomial( K, m, p) - binomial probability
%
function b = p_binomial( K, m, p)

global octave;

b = 1;

if( m > K)
  error( 'm <= K required.');
end

if( K == 0)	% degenerate case
  return;
end

if( m > 0)
  b = prod( p*ones(1,m));
end

if( K-m > 0)
  b = b * prod( (1-p)*ones(1,K-m));
end

if( octave)
  b = b * bincoeff(K,m);
else
  b = b * nchoosek(K,m);
end
