func Limit()

in processor/lsmintervalprocessor/internal/data/expo/scale.go [141:163]


func Limit(maxBuckets int, scale Scale, arel, brel pmetric.ExponentialHistogramDataPointBuckets) Scale {
	a, b := Abs(arel), Abs(brel)

	lo := min(a.Lower(), b.Lower())
	up := max(a.Upper(), b.Upper())

	// Skip leading and trailing zeros.
	for lo < up && a.Abs(lo) == 0 && b.Abs(lo) == 0 {
		lo++
	}
	for lo < up-1 && a.Abs(up-1) == 0 && b.Abs(up-1) == 0 {
		up--
	}

	// Keep downscaling until the number of buckets is within the limit.
	for up-lo > maxBuckets {
		lo /= 2
		up /= 2
		scale--
	}

	return scale
}