@@ -25,7 +25,7 @@ auto n(double v, double a) { return a * (pow((1 + 1 / a), v) - 1); }
25
25
// - v: value in register
26
26
// - a: a scaling value for the logarithm based on Morris's paper
27
27
// It returns a new value for v
28
- auto increment (double v, double a) {
28
+ auto increment (int v, double a) {
29
29
// delta is the probability of incrementing our counter
30
30
const auto delta = 1 / (n (v + 1 , a) - n (v, a));
31
31
return (drand () <= delta) ? v + 1 : v;
@@ -35,7 +35,7 @@ auto increment(double v, double a) {
35
35
// - n_items: number of items to count and loop over
36
36
// - a: a scaling value for the logarithm based on Morris's paper
37
37
// It returns n(v,a), the approximate count
38
- auto approximate_count (int n_items, int a) {
38
+ auto approximate_count (int n_items, double a) {
39
39
auto v = 0 ;
40
40
for (auto i = 0 ; i < n_items; ++i)
41
41
v = increment (v, a);
@@ -55,7 +55,7 @@ auto test_approximate_count(
55
55
for (auto i = 0 ; i < n_trials; ++i)
56
56
sum += approximate_count (n_items, a);
57
57
const auto avg = sum / n_trials;
58
- return ( avg - n_items) / n_items < threshold ? " pass" : " fail" ;
58
+ return std::abs (( avg - n_items) / n_items) < threshold ? " pass" : " fail" ;
59
59
}
60
60
61
61
int main () {
0 commit comments