From fc94b49ada9a4d522bdd620d2dc2a54e450bbbab Mon Sep 17 00:00:00 2001 From: Dongryeol Lee Date: Thu, 14 Aug 2008 17:55:22 +0000 Subject: [PATCH] Bug fix for math::BinomialCoefficient(n, k); the previous implementation returned 1 for negative k values, which is not correct (should be zero. --- fastlib2/fastlib/math/discrete.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastlib2/fastlib/math/discrete.cc b/fastlib2/fastlib/math/discrete.cc index a9ea1121f7..cfeed86175 100644 --- a/fastlib2/fastlib/math/discrete.cc +++ b/fastlib2/fastlib/math/discrete.cc @@ -15,8 +15,9 @@ double math::BinomialCoefficient(int n, int k) { double nchsk = 1; int i; - if(k > n) + if(k > n || k < 0) { return 0; + } if(k < n_k) { k = n_k;