mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/probability] Avoid too long loop in calculation
Change-Id: I33e60aa51aaff44b73bf0a810fdaf6369f653b19
This commit is contained in:
@@ -14,6 +14,10 @@ float Law::cumulativeDistributiveFunctionAtAbscissa(float x) const {
|
||||
float result = 0.0f;
|
||||
for (int k = 0; k <=end; k++) {
|
||||
result += evaluateAtAbscissa(k);
|
||||
/* Avoid too long loop */
|
||||
if (result > k_maxProbability || k > k_maxNumberOfOperations) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -39,6 +43,10 @@ float Law::finiteIntegralBetweenAbscissas(float a, float b) const {
|
||||
float result = 0.0f;
|
||||
for (int k = start; k <=end; k++) {
|
||||
result += evaluateAtAbscissa(k);
|
||||
/* Avoid too long loop */
|
||||
if (result > k_maxProbability || k-start > k_maxNumberOfOperations) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
virtual float rightIntegralInverseForProbability(float * probability);
|
||||
protected:
|
||||
constexpr static int k_maxNumberOfOperations = 1000000;
|
||||
constexpr static float k_maxProbability = 0.9995f;
|
||||
constexpr static float k_displayTopMarginRatio = 0.05f;
|
||||
constexpr static float k_displayBottomMarginRatio = 0.2f;
|
||||
constexpr static float k_displayLeftMarginRatio = 0.05f;
|
||||
|
||||
Reference in New Issue
Block a user