[apps] In Probability: fix bug when a = 0 and b = 1E-43 < FLT_EPSILON

Change-Id: Ib4fd405178fa0d7e8571f2da14e177fe67e3c96d
This commit is contained in:
Émilie Feral
2017-12-05 12:10:10 +01:00
parent ed1521cfd7
commit b7a74c2c46
2 changed files with 8 additions and 6 deletions

View File

@@ -1,4 +1,6 @@
#include "uniform_law.h"
#include <cmath>
#include <float.h>
#include <assert.h>
namespace Probability {
@@ -40,14 +42,14 @@ I18n::Message UniformLaw::parameterDefinitionAtIndex(int index) {
float UniformLaw::xMin() {
assert(m_parameter2 >= m_parameter1);
if (m_parameter1 == m_parameter2) {
if (m_parameter2 - m_parameter1 < FLT_EPSILON) {
return m_parameter1 - 1.0f;
}
return m_parameter1 - 0.6f*(m_parameter2 - m_parameter1);
}
float UniformLaw::xMax() {
if (m_parameter1 == m_parameter2) {
if (m_parameter2 - m_parameter1 < FLT_EPSILON) {
return m_parameter1 + 1.0f;
}
return m_parameter2 + 0.6f*(m_parameter2 - m_parameter1);
@@ -58,15 +60,15 @@ float UniformLaw::yMin() {
}
float UniformLaw::yMax() {
float result = m_parameter1 == m_parameter2 ? k_diracMaximum : 1.0f/(m_parameter2-m_parameter1);
if (result <= 0.0f) {
float result = m_parameter2 - m_parameter1 < FLT_EPSILON ? k_diracMaximum : 1.0f/(m_parameter2-m_parameter1);
if (result <= 0.0f || std::isnan(result) || std::isinf(result)) {
result = 1.0f;
}
return result*(1.0f+ k_displayTopMarginRatio);
}
float UniformLaw::evaluateAtAbscissa(float t) const {
if (m_parameter1 == m_parameter2) {
if (m_parameter2 - m_parameter1 < FLT_EPSILON) {
if (m_parameter1 - k_diracWidth<= t && t <= m_parameter2 + k_diracWidth) {
return 2.0f*k_diracMaximum;
}

View File

@@ -24,7 +24,7 @@ public:
double cumulativeDistributiveInverseForProbability(double * probability) override;
private:
constexpr static float k_diracMaximum = 10.0f;
constexpr static float k_diracWidth = 0.001f;
constexpr static float k_diracWidth = 0.005f;
};
}