Fawkes API
Fawkes Development Version
binomial_coefficient.h
1
2
/***************************************************************************
3
* binomial_coefficient.h - function for computing the binomial coefficient
4
*
5
* Generated: Sun Nov 04 17:29:46 2007
6
* Copyright 2007 Martin Liebenberg
7
*
8
****************************************************************************/
9
10
/* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version. A runtime exception applies to
14
* this software (see LICENSE.GPL_WRE file mentioned below for details).
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Library General Public License for more details.
20
*
21
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22
*/
23
24
#ifndef _UTILS_MATH_BINOMIAL_COEFFICIENT_H_
25
#define _UTILS_MATH_BINOMIAL_COEFFICIENT_H_
26
27
namespace
fawkes
{
28
29
/** @class BinomialCoefficient <utils/math/binomial_coefficient.h>
30
* Contains method to compute the binomial coefficient.
31
*
32
* @author Martin Liebenberg
33
*/
34
35
class
BinomialCoefficient
36
{
37
public
:
38
/** Calculates the binomial coefficient.
39
* @param n upper value
40
* @param k lower value
41
* @return the binomial coefficient of n and k
42
*/
43
static
inline
unsigned
int
44
binoc
(
unsigned
int
n,
unsigned
int
k)
45
{
46
unsigned
int
result;
47
if
(k == 0)
48
return
1;
49
if
(2 * k > n)
50
result =
binoc
(n, n - k);
51
else
{
52
result = n;
53
for
(
unsigned
int
i = 2; i <= k; i++) {
54
result = result * ((n + 1 - i) / i);
55
}
56
}
57
return
result;
58
}
59
};
60
61
}
// end namespace fawkes
62
63
#endif
fawkes
fawkes::BinomialCoefficient::binoc
static unsigned int binoc(unsigned int n, unsigned int k)
Calculates the binomial coefficient.
Definition:
binomial_coefficient.h:48
src
libs
utils
math
binomial_coefficient.h
Generated by
1.8.16