export function exponentialRange()

in glean/src/histogram/exponential.ts [28:55]


export function exponentialRange(min: number, max: number, bucketCount: number): number[] {
  const logMax = Math.log(max);

  const ranges: number[] = [];
  let current = min;
  if (current === 0) {
    current = 1;
  }

  ranges.push(0);
  ranges.push(current);

  for (let i = 2; i < bucketCount; i++) {
    const logCurrent = Math.log(current);
    const logRatio = (logMax - logCurrent) / (bucketCount - i);
    const logNext = logCurrent + logRatio;
    const nextValue = Math.round(Math.exp(logNext));

    if (nextValue > current) {
      current = nextValue;
    } else {
      current += 1;
    }
    ranges.push(current);
  }

  return ranges;
}