PSCF v1.1
Binomial.h
1#ifndef UTIL_BINOMIAL_H
2#define UTIL_BINOMIAL_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/containers/GArray.h> // base class
12#include <util/math/Rational.h> // default template argument
13#include <util/containers/Array.h> // function argument
14#include <util/global.h>
15
16
17#include <iostream>
18
19namespace Util
20{
21
27 class Binomial
28 {
29
30 public:
31
39 static void setup(int nMax);
40
44 static void clear();
45
56 static int coeff(int n, int m);
57
58 private:
59
63 static GArray<int> coeffs_;
64
68 static int maxN_;
69
73 Binomial();
74
75 };
76
77}
78#endif
Class for binomial coefficients (all static members)
Definition: Binomial.h:28
static void setup(int nMax)
Precompute all combinations C(n, m) up to n = nMax.
Definition: Binomial.cpp:17
static int coeff(int n, int m)
Return coefficient "n choose m", or C(n, m) = n!/(m!(n-m)!).
Definition: Binomial.cpp:55
static void clear()
Release all static memory.
Definition: Binomial.cpp:47
An automatically growable array, analogous to a std::vector.
Definition: GArray.h:34
File containing preprocessor macros for error handling.
Utility classes for scientific computation.
Definition: accumulators.mod:1