docs: public double sum(final float b)
    {
      if (b < min) {
        return 0;
      }
      if (b >= max) {
        return count;
      }
  
      int index = Arrays.binarySearch(positions, 0, binCount, b);
      boolean exactMatch = index >= 0;
      index = exactMatch ? index : -(index + 1);
  
      // we want positions[index] <= b < positions[index+1]
      if (!exactMatch) {
        index--;
      }
  
      final boolean outerLeft = index < 0;
      final boolean outerRight = index >= (binCount - 1);
  
      final long m0 = outerLeft ? 0 : (bins[index] & COUNT_BITS);
      final long m1 = outerRight ? 0 : (bins[index + 1] & COUNT_BITS);
      final double p0 = outerLeft ? min : positions[index];
      final double p1 = outerRight ? max : positions[index + 1];
      final boolean exact0 = (!outerLeft && (bins[index] & APPROX_FLAG_BIT) == 0);
      final boolean exact1 = (!outerRight && (bins[index + 1] & APPROX_FLAG_BIT) == 0);
  
      // handle case when p0 = p1, which happens if the first bin = min or the last bin = max
      final double l = (p1 == p0) ? 0 : (b - p0) / (p1 - p0);
  
      // don't include exact counts in the trapezoid calculation
      long tm0 = m0;
      long tm1 = m1;
      if (exact0) {
        tm0 = 0;
      }
      if (exact1) {
        tm1 = 0;
      }
      final double mb = tm0 + (tm1 - tm0) * l;
      double s = 0.5 * (tm0 + mb) * l;
  
      for (int i = 0; i < index; ++i) {
        s += (bins[i] & COUNT_BITS);
      }
  
      // add full bin count if left bin count is exact
      if (exact0) {
        return (s + m0);
      } else {
        // otherwise add only the left half of the bin
        return (s + 0.5 * m0);
      }
    }