SootLib
Loading...
Searching...
No Matches
binomial.h
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <exception>
12
23
24double binomial_coefficient(unsigned r, unsigned k) {
25 constexpr double factorials[] = {
26 1.0,
27 1.0,
28 2.0,
29 6.0,
30 24.0,
31 120.0,
32 720.0,
33 5040.0,
34 40320.0,
35 362880.0,
36 3628800.0,
37 39916800.0,
38 479001600.0,
39 6227020800.0,
40 87178291200.0,
41 1307674368000.0,
42 20922789888000.0,
43 355687428096000.0,
44 6402373705728000.0,
45 121645100408832000.0,
46 0.243290200817664e19,
47 0.5109094217170944e20,
48 0.112400072777760768e22,
49 0.2585201673888497664e23,
50 0.62044840173323943936e24,
51 0.15511210043330985984e26,
52 0.403291461126605635584e27,
53 0.10888869450418352160768e29,
54 0.304888344611713860501504e30,
55 0.8841761993739701954543616e31,
56 0.26525285981219105863630848e33,
57 0.822283865417792281772556288e34,
58 0.26313083693369353016721801216e36,
59 0.868331761881188649551819440128e37,
60 0.29523279903960414084761860964352e39,
61 };
62
63 if (r >= 35 || k >= 35 || (r - k) >= 35)
64 throw std::runtime_error("binomial coefficient parameters out of bounds");
65
66 return factorials[r] / (factorials[k] * factorials[r - k]);
67}
double binomial_coefficient(unsigned r, unsigned k)
Definition: binomial.h:24