blob: 9ccc82424f77eef82a890c45936a63c2db8e3342 [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
Stephan Pleinesf63bde82024-01-13 15:59:33 -08004namespace frc971::control_loops {
Austin Schuhe6e7ea52019-01-13 17:26:36 -08005
6// Computes the factorial of n
7constexpr double Factorial(int n) {
8 if (n <= 1) {
9 return 1.0;
10 } else {
11 return Factorial(n - 1) * n;
12 }
13}
14
15// Computes the binomial coefficients. n choose k.
16constexpr double Binomial(int n, int k) {
17 return Factorial(n) / (Factorial(k) * Factorial(n - k));
18}
19
Stephan Pleinesf63bde82024-01-13 15:59:33 -080020} // namespace frc971::control_loops
Austin Schuhe6e7ea52019-01-13 17:26:36 -080021
22#endif // FRC971_CONTROL_LOOPS_BINOMIAL_H_