Skip to content

Commit d0492d2

Browse files
committed
[statistics] Lower sumOfValuesBetween precision
1 parent ab7fe3f commit d0492d2

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

apps/statistics/store.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,20 +471,23 @@ bool Store::updateSeries(int series, bool delayUpdate) {
471471
}
472472

473473
double Store::sumOfValuesBetween(int series, double x1, double x2, bool strictUpperBound) const {
474-
/* Use roughly_equal to handle impossible double representations such as
475-
* 12.11 being 12.109999999999999 or 12.110000000000001. */
476474
if (!seriesIsValid(series)) {
477475
return NAN;
478476
}
477+
/* Use roughly_equal to handle impossible double representations such as
478+
* 12.11 being 12.109999999999999 or 12.110000000000001. The precision we use
479+
* must be higher than 1e-14 (max number of significant digits) but having it
480+
* higher than DBL_EPSILON wouldn't be effective. */
481+
constexpr static double k_precision = 1e-15;
479482
double result = 0;
480483
int numberOfPairs = numberOfPairsOfSeries(series);
481484
for (int k = 0; k < numberOfPairs; k++) {
482485
int sortedIndex = valueIndexAtSortedIndex(series, k);
483486
double value = get(series, 0, sortedIndex);
484-
if (value > x2 || (strictUpperBound && Poincare::Helpers::RelativelyEqual<double>(value, x2, DBL_EPSILON))) {
487+
if (value > x2 || (strictUpperBound && Poincare::Helpers::RelativelyEqual<double>(value, x2, k_precision))) {
485488
break;
486489
}
487-
if (value >= x1 || Poincare::Helpers::RelativelyEqual<double>(value, x1, DBL_EPSILON)) {
490+
if (value >= x1 || Poincare::Helpers::RelativelyEqual<double>(value, x1, k_precision)) {
488491
result += get(series, 1, sortedIndex);
489492
}
490493
}

0 commit comments

Comments
 (0)