Skip to content

Commit fdbabfd

Browse files
Merge pull request #19 from wreulicke/feature/use-log10
Fix bugs around Log10RootFunction
2 parents 3031c71 + 140e296 commit fdbabfd

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

limit/functions/log10_root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ var log10RootLookup []int
1212
func Log10RootFunction(baseline int) func(estimatedLimit int) int {
1313
return func(estimatedLimit int) int {
1414
if estimatedLimit < len(log10RootLookup) {
15-
return max(baseline, log10RootLookup[estimatedLimit])
15+
return baseline + log10RootLookup[estimatedLimit]
1616
}
17-
return max(baseline, int(math.Sqrt(float64(estimatedLimit))))
17+
return baseline + int(math.Log10(float64(estimatedLimit)))
1818
}
1919
}
2020

@@ -24,8 +24,8 @@ func Log10RootFunction(baseline int) func(estimatedLimit int) int {
2424
func Log10RootFloatFunction(baseline float64) func(estimatedLimit float64) float64 {
2525
return func(estimatedLimit float64) float64 {
2626
if int(estimatedLimit) < len(log10RootLookup) {
27-
return math.Max(baseline, float64(log10RootLookup[int(estimatedLimit)]))
27+
return baseline + float64(log10RootLookup[int(estimatedLimit)])
2828
}
29-
return math.Max(baseline, math.Sqrt(estimatedLimit))
29+
return baseline + math.Log10(estimatedLimit)
3030
}
3131
}

limit/functions/log10_root_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ func TestLog10RootFunction(t *testing.T) {
1212
t.Run("ZeroIndex", func(t2 *testing.T) {
1313
t2.Parallel()
1414
f := Log10RootFunction(4)
15-
assert.Equal(t2, 4, f(0))
15+
assert.Equal(t2, 5, f(0))
1616
})
1717

1818
t.Run("MaxIndex", func(t2 *testing.T) {
1919
t2.Parallel()
2020
f := Log10RootFunction(4)
21-
assert.Equal(t2, 31, f(1000))
21+
assert.Equal(t2, 7, f(1000))
2222
})
2323

2424
t.Run("OutOfLookupRange", func(t2 *testing.T) {
2525
t2.Parallel()
2626
f := Log10RootFunction(4)
27-
assert.Equal(t2, 50, f(2500))
27+
assert.Equal(t2, 7, f(2500))
2828
})
2929
}
3030

@@ -34,18 +34,18 @@ func TestLog10RootFloatFunction(t *testing.T) {
3434
t.Run("ZeroIndex", func(t2 *testing.T) {
3535
t2.Parallel()
3636
f := Log10RootFloatFunction(4)
37-
assert.Equal(t2, 4.0, f(0))
37+
assert.Equal(t2, 5.0, f(0))
3838
})
3939

4040
t.Run("MaxIndex", func(t2 *testing.T) {
4141
t2.Parallel()
4242
f := Log10RootFloatFunction(4)
43-
assert.InDelta(t2, 31.623, f(1000), 0.001)
43+
assert.InDelta(t2, 7.0, f(1000), 0.001)
4444
})
4545

4646
t.Run("OutOfLookupRange", func(t2 *testing.T) {
4747
t2.Parallel()
4848
f := Log10RootFloatFunction(4)
49-
assert.Equal(t2, 50.0, f(2500))
49+
assert.Equal(t2, 7.3979400086720375, f(2500))
5050
})
5151
}

0 commit comments

Comments
 (0)