PSCF v1.1
Static Public Member Functions | List of all members
Util::Binomial Class Reference

Class for binomial coefficients (all static members) More...

#include <Binomial.h>

Static Public Member Functions

static void setup (int nMax)
 Precompute all combinations C(n, m) up to n = nMax. More...
 
static void clear ()
 Release all static memory. More...
 
static int coeff (int n, int m)
 Return coefficient "n choose m", or C(n, m) = n!/(m!(n-m)!). More...
 

Detailed Description

Class for binomial coefficients (all static members)

Definition at line 27 of file Binomial.h.

Member Function Documentation

◆ setup()

void Util::Binomial::setup ( int  nMax)
static

Precompute all combinations C(n, m) up to n = nMax.

Algorithm: Construct rows [0,...,nMax] of Pascal's triangle.

Parameters
nMaxmaximum value of n to precompute.

Definition at line 17 of file Binomial.cpp.

References Util::GArray< Data >::resize(), and UTIL_CHECK.

Referenced by coeff(), and Util::Polynomial< T >::shift().

◆ clear()

void Util::Binomial::clear ( )
static

Release all static memory.

Definition at line 47 of file Binomial.cpp.

References Util::GArray< Data >::capacity(), and Util::GArray< Data >::deallocate().

◆ coeff()

int Util::Binomial::coeff ( int  n,
int  m 
)
static

Return coefficient "n choose m", or C(n, m) = n!/(m!(n-m)!).

Algorithm: Returns precomputed value C(n,m) if already known. Otherwise, calls setup(n) to computes and stores values of C(n', m) for all n' <= n, then returns desired value.

Parameters
nlarger integer (overall power in binomial)
mparameter in range [0,n]

Definition at line 55 of file Binomial.cpp.

References setup(), and UTIL_CHECK.

Referenced by Util::Polynomial< T >::shift().


The documentation for this class was generated from the following files: