Files
spark/src/lib/utils/MathUtils.cc
T

25 lines
660 B
C++

#include "MathUtils.h"
namespace bts {
template <uint32_t N>
inline constexpr uint32_t MathUtils::factorial() {
return N * factorial<N - 1>();
}
template <>
inline constexpr uint32_t MathUtils::factorial<0>() {
return 1;
}
template <uint32_t N, uint32_t A>
inline constexpr uint32_t MathUtils::choose() {
// This actually involves more multiplication ops than the non-constexpr
// overload of 'choose.' The former performs N-A multiplications (the minimum
// possible), while the latter (this method) performs 'N + (N-A) + A = 2N'
// multiplications
return factorial<N>() / (factorial<N - A>() * factorial<A>());
}
} // namespace bts