Austin Schuh | e6e7ea5 | 2019-01-13 17:26:36 -0800 | [diff] [blame] | 1 | #ifndef FRC971_CONTROL_LOOPS_BINOMIAL_H_ |
| 2 | #define FRC971_CONTROL_LOOPS_BINOMIAL_H_ |
| 3 | |
| 4 | namespace frc971 { |
| 5 | namespace control_loops { |
| 6 | |
| 7 | // Computes the factorial of n |
| 8 | constexpr 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. |
| 17 | constexpr 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_ |