- /* Approximate ratio of requests below "lower" */
- cdtime_t lower_bin_boundary = lower_bin * lc->bin_width;
-
- /* When bin width is 0.125 (for example), then bin 0 stores
- * values for interval [0, 0.124) (excluding).
- * With lower = 0.100, the ratio should be 0.099 / 0.125.
- * I.e. ratio = 0.100 - 0.000 - 0.001
- */
- double ratio = (double)(lower - lower_bin_boundary - DOUBLE_TO_CDTIME_T(0.001))
- / (double)lc->bin_width;
- sum -= ratio * lc->histogram[lower_bin];
+ if (lower) {
+ /* Approximate ratio of requests in lower_bin, that fall between
+ * lower_bin_boundary and lower. This ratio is then subtracted from sum to
+ * increase accuracy. */
+ cdtime_t lower_bin_boundary = lower_bin * lc->bin_width;
+ assert (lower > lower_bin_boundary);
+ double lower_ratio = (double)(lower - lower_bin_boundary - 1) / ((double) lc->bin_width);
+ sum -= lower_ratio * lc->histogram[lower_bin];
+ }