🫚 Makes combinatorial a constant expression

This commit is contained in:
Rune Harlyk
2024-11-09 16:03:14 +01:00
committed by Rune Harlyk
parent 7046957669
commit ea42cc0aac
2 changed files with 30 additions and 13 deletions
+12
View File
@@ -69,4 +69,16 @@ inline bool arrayEqual(const float arr1[4][4], const float arr2[4][4], float eps
return true;
}
static constexpr float combinatorial_constexpr(const int n, int k) {
if (k < 0 || k > n) return 0.0f;
if (k == 0 || k == n) return 1.0f;
k = (k < (n - k)) ? k : (n - k);
float result = 1.0f;
for (int i = 0; i < k; ++i) {
result *= (n - i);
result /= (i + 1);
}
return result;
}
#endif