[apps/statistics] Fix bar width computation

There was a float -> double conversion lack of precision, which resulted
in akward results
Scenario:
Data
V N    Then display the histogram: the second bar is [1.9;2[ but
1 1    contains the 2 value
2 1
This commit is contained in:
Léa Saviot
2020-02-10 13:53:29 +01:00
parent 922d3cc0c6
commit c9f83f6e7e

View File

@@ -247,9 +247,14 @@ void HistogramController::initBarParameters() {
assert(selectedSeriesIndex() >= 0 && m_store->sumOfOccurrences(selectedSeriesIndex()) > 0);
preinitXRangeParameters();
m_store->setFirstDrawnBarAbscissa(m_store->xMin());
float barWidth = m_store->xGridUnit();
if (barWidth <= 0.0f) {
barWidth = 1.0f;
double barWidth = m_store->xGridUnit();
if (barWidth <= 0.0) {
barWidth = 1.0;
} else {
// Truncate the bar width, as we convert from float to double
const double precision = 7; // TODO factorize? This is an experimental value, the same as in Expression;;Epsilon<float>()
const double logBarWidth = std::floor(std::log10(barWidth));
barWidth = ((int)(barWidth * std::pow(10.0, precision - logBarWidth))) * std::pow(10.0, -precision + logBarWidth);
}
m_store->setBarWidth(barWidth);
}