Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions HdrHistogram.UnitTests/HistogramTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,27 @@ public void GetPercentileAtOrBelowValue_NegativeValue_ReturnsZero()
histogram.GetPercentileAtOrBelowValue(long.MinValue).Should().Be(0.0);
}

[Fact]
public void SizeOfEquivalentValueRangeDoesNotOverflow()
{
var histogram = Create(long.MaxValue, DefaultSignificantFigures);

for (int i = 0; i < 8; i++)
{
histogram.RecordValue(1);
}

histogram.RecordValue((1L << 41) + 1);

histogram.RecordValue((1L << 50) + 1);

var p90 = histogram.GetValueAtPercentile(90);

p90.Should().BeGreaterThan((1L << 41) + 1);
histogram.SizeOfEquivalentValueRange((1L << 41) + 1).Should().Be((1L << 31));
p90.Should().Be((1L << 41) + (1L << 31) - 1);
}

private void CreateAndAdd(HistogramBase source)
{
source.RecordValueWithCount(1, 100);
Expand Down
2 changes: 1 addition & 1 deletion HdrHistogram/HistogramBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public long SizeOfEquivalentValueRange(long value)
bucketIndex++;
}

var distanceToNextValue = 1 << (_unitMagnitude + bucketIndex);
var distanceToNextValue = 1L << (_unitMagnitude + bucketIndex);
return distanceToNextValue;
}

Expand Down