blob: 4f4c4dcca57ebcc3bc51fd0d2fc45b243da4fa3f [file] [log] [blame]
Austin Schuhe6e7ea52019-01-13 17:26:36 -08001#ifndef FRC971_CONTROL_LOOPS_BINOMIAL_H_
2#define FRC971_CONTROL_LOOPS_BINOMIAL_H_
3
4namespace frc971 {
5namespace control_loops {
6
7// Computes the factorial of n
8constexpr double Factorial(int n) {
9 if (n <= 1) {
10 return 1.0;
11 } else {
12 return Factorial(n - 1) * n;
13 }
14}
15
16// Computes the binomial coefficients. n choose k.
17constexpr double Binomial(int n, int k) {
18 return Factorial(n) / (Factorial(k) * Factorial(n - k));
19}
20
21} // namespace control_loops
22} // namespace frc971
23
24#endif // FRC971_CONTROL_LOOPS_BINOMIAL_H_