Skip to content

Commit a08f551

Browse files
committed
BUG fix for IsLastValue. Closes #39
1 parent e5ad62c commit a08f551

File tree

4 files changed

+155
-2
lines changed

4 files changed

+155
-2
lines changed

src/HdrHistogram.UnitTests/HdrHistogram.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
<EmbeddedResource Include="Resources\jHiccup-2.0.7S.logV2.hlog" />
124124
<EmbeddedResource Include="Resources\ycsb.logV1.hlog" />
125125
<EmbeddedResource Include="Resources\tagged-Log.logV2.hlog" />
126+
<EmbeddedResource Include="Resources\IsLastValueBug.hgrm" />
126127
</ItemGroup>
127128
<ItemGroup>
128129
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj">

src/HdrHistogram.UnitTests/HgrmPercentileDistrubutionOutputTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,35 @@ public void PercentileDistrubution_csv_output_is_in_correct_format(
4949

5050
Assert.AreEqual(expected, actual);
5151
}
52+
53+
[Test] //BUG https://github.com/HdrHistogram/HdrHistogram.NET/issues/39
54+
public void OnlySingleValueFlaggedAsLastValue()
55+
{
56+
var expected = GetEmbeddedFileText("IsLastValueBug.hgrm");
57+
58+
var histogram = new LongHistogram(highestTrackableValue: 36000000000, numberOfSignificantValueDigits:3);
59+
histogram.RecordValueWithCount(1L, 7604459);
60+
histogram.RecordValueWithCount(383, 2395524);
61+
histogram.RecordValueWithCount(453, 2);
62+
histogram.RecordValueWithCount(511, 2);
63+
histogram.RecordValueWithCount(537, 3);
64+
histogram.RecordValueWithCount(672, 1);
65+
histogram.RecordValueWithCount(777, 1);
66+
histogram.RecordValueWithCount(18143, 1);
67+
histogram.RecordValueWithCount(208127, 1);
68+
histogram.RecordValueWithCount(224639, 1);
69+
histogram.RecordValueWithCount(229759, 1);
70+
histogram.RecordValueWithCount(230271, 1);
71+
histogram.RecordValueWithCount(258943, 1);
72+
histogram.RecordValueWithCount(275711, 1);
73+
histogram.RecordValueWithCount(282111, 1);
74+
75+
var writer = new StringWriter();
76+
histogram.OutputPercentileDistribution(writer);
77+
var actual = writer.ToString();
78+
79+
Assert.AreEqual(expected, actual);
80+
}
5281

5382
private Stream GetEmbeddedFileStream(string filename)
5483
{
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
 Value Percentile TotalCount 1/(1-Percentile)
2+
3+
1.000 0.000000000000 7604459 1.00
4+
1.000 0.100000000000 7604459 1.11
5+
1.000 0.200000000000 7604459 1.25
6+
1.000 0.300000000000 7604459 1.43
7+
1.000 0.400000000000 7604459 1.67
8+
1.000 0.500000000000 7604459 2.00
9+
1.000 0.550000000000 7604459 2.22
10+
1.000 0.600000000000 7604459 2.50
11+
1.000 0.650000000000 7604459 2.86
12+
1.000 0.700000000000 7604459 3.33
13+
1.000 0.750000000000 7604459 4.00
14+
383.000 0.775000000000 9999983 4.44
15+
383.000 0.800000000000 9999983 5.00
16+
383.000 0.825000000000 9999983 5.71
17+
383.000 0.850000000000 9999983 6.67
18+
383.000 0.875000000000 9999983 8.00
19+
383.000 0.887500000000 9999983 8.89
20+
383.000 0.900000000000 9999983 10.00
21+
383.000 0.912500000000 9999983 11.43
22+
383.000 0.925000000000 9999983 13.33
23+
383.000 0.937500000000 9999983 16.00
24+
383.000 0.943750000000 9999983 17.78
25+
383.000 0.950000000000 9999983 20.00
26+
383.000 0.956250000000 9999983 22.86
27+
383.000 0.962500000000 9999983 26.67
28+
383.000 0.968750000000 9999983 32.00
29+
383.000 0.971875000000 9999983 35.56
30+
383.000 0.975000000000 9999983 40.00
31+
383.000 0.978125000000 9999983 45.71
32+
383.000 0.981250000000 9999983 53.33
33+
383.000 0.984375000000 9999983 64.00
34+
383.000 0.985937500000 9999983 71.11
35+
383.000 0.987500000000 9999983 80.00
36+
383.000 0.989062500000 9999983 91.43
37+
383.000 0.990625000000 9999983 106.67
38+
383.000 0.992187500000 9999983 128.00
39+
383.000 0.992968750000 9999983 142.22
40+
383.000 0.993750000000 9999983 160.00
41+
383.000 0.994531250000 9999983 182.86
42+
383.000 0.995312500000 9999983 213.33
43+
383.000 0.996093750000 9999983 256.00
44+
383.000 0.996484375000 9999983 284.44
45+
383.000 0.996875000000 9999983 320.00
46+
383.000 0.997265625000 9999983 365.71
47+
383.000 0.997656250000 9999983 426.67
48+
383.000 0.998046875000 9999983 512.00
49+
383.000 0.998242187500 9999983 568.89
50+
383.000 0.998437500000 9999983 640.00
51+
383.000 0.998632812500 9999983 731.43
52+
383.000 0.998828125000 9999983 853.33
53+
383.000 0.999023437500 9999983 1024.00
54+
383.000 0.999121093750 9999983 1137.78
55+
383.000 0.999218750000 9999983 1280.00
56+
383.000 0.999316406250 9999983 1462.86
57+
383.000 0.999414062500 9999983 1706.67
58+
383.000 0.999511718750 9999983 2048.00
59+
383.000 0.999560546875 9999983 2275.56
60+
383.000 0.999609375000 9999983 2560.00
61+
383.000 0.999658203125 9999983 2925.71
62+
383.000 0.999707031250 9999983 3413.33
63+
383.000 0.999755859375 9999983 4096.00
64+
383.000 0.999780273438 9999983 4551.11
65+
383.000 0.999804687500 9999983 5120.00
66+
383.000 0.999829101563 9999983 5851.43
67+
383.000 0.999853515625 9999983 6826.67
68+
383.000 0.999877929688 9999983 8192.00
69+
383.000 0.999890136719 9999983 9102.22
70+
383.000 0.999902343750 9999983 10240.00
71+
383.000 0.999914550781 9999983 11702.86
72+
383.000 0.999926757813 9999983 13653.33
73+
383.000 0.999938964844 9999983 16384.00
74+
383.000 0.999945068359 9999983 18204.44
75+
383.000 0.999951171875 9999983 20480.00
76+
383.000 0.999957275391 9999983 23405.71
77+
383.000 0.999963378906 9999983 27306.67
78+
383.000 0.999969482422 9999983 32768.00
79+
383.000 0.999972534180 9999983 36408.89
80+
383.000 0.999975585938 9999983 40960.00
81+
383.000 0.999978637695 9999983 46811.43
82+
383.000 0.999981689453 9999983 54613.33
83+
383.000 0.999984741211 9999983 65536.00
84+
383.000 0.999986267090 9999983 72817.78
85+
383.000 0.999987792969 9999983 81920.00
86+
383.000 0.999989318848 9999983 93622.86
87+
383.000 0.999990844727 9999983 109226.67
88+
383.000 0.999992370605 9999983 131072.00
89+
383.000 0.999993133545 9999983 145635.56
90+
383.000 0.999993896484 9999983 163840.00
91+
383.000 0.999994659424 9999983 187245.71
92+
383.000 0.999995422363 9999983 218453.33
93+
383.000 0.999996185303 9999983 262144.00
94+
383.000 0.999996566772 9999983 291271.11
95+
383.000 0.999996948242 9999983 327680.00
96+
383.000 0.999997329712 9999983 374491.43
97+
383.000 0.999997711182 9999983 436906.67
98+
383.000 0.999998092651 9999983 524288.00
99+
383.000 0.999998283386 9999983 582542.22
100+
453.000 0.999998474121 9999985 655360.00
101+
511.000 0.999998664856 9999987 748982.86
102+
537.000 0.999998855591 9999990 873813.33
103+
672.000 0.999999046326 9999991 1048576.00
104+
777.000 0.999999141693 9999992 1165084.44
105+
18143.000 0.999999237061 9999993 1310720.00
106+
208127.000 0.999999332428 9999994 1497965.71
107+
224639.000 0.999999427795 9999995 1747626.67
108+
229759.000 0.999999523163 9999996 2097152.00
109+
229759.000 0.999999570847 9999996 2330168.89
110+
230271.000 0.999999618530 9999997 2621440.00
111+
230271.000 0.999999666214 9999997 2995931.43
112+
258943.000 0.999999713898 9999998 3495253.33
113+
258943.000 0.999999761581 9999998 4194304.00
114+
258943.000 0.999999785423 9999998 4660337.78
115+
275711.000 0.999999809265 9999999 5242880.00
116+
275711.000 0.999999833107 9999999 5991862.86
117+
275711.000 0.999999856949 9999999 6990506.67
118+
275711.000 0.999999880791 9999999 8388608.00
119+
275711.000 0.999999892712 9999999 9320675.55
120+
282111.000 0.999999904633 10000000 10485760.00
121+
282111.000 1.000000000000 10000000
122+
#[Mean = 92.682, StdDeviation = 262.259]
123+
#[Max = 282111.000, Total count = 10000000]
124+
#[Buckets = 26, SubBuckets = 2048]

src/HdrHistogram/Iteration/HistogramIterationValue.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public sealed class HistogramIterationValue
6363
/// <returns>Returns <c>true</c> if it is the last value, else <c>false</c>.</returns>
6464
public bool IsLastValue()
6565
{
66-
//return PercentileLevelIteratedTo == 100.0D;
67-
return Math.Abs(PercentileLevelIteratedTo - 100.0D) < 0.0001;
66+
return Math.Abs(PercentileLevelIteratedTo - 100.0D) < double.Epsilon;
6867
}
6968

7069
// Set is all-or-nothing to avoid the potential for accidental omission of some values...

0 commit comments

Comments
 (0)