...
Source file
src/runtime/fastlog2_test.go
Documentation: runtime
1
2
3
4
5 package runtime_test
6
7 import (
8 "math"
9 "runtime"
10 "testing"
11 )
12
13 func TestFastLog2(t *testing.T) {
14
15
16 const randomBitCount = 26
17 var e float64
18
19 inc := 1
20 if testing.Short() {
21
22 inc = 1 << 16
23 }
24 for i := 1; i < 1<<randomBitCount; i += inc {
25 l, fl := math.Log2(float64(i)), runtime.Fastlog2(float64(i))
26 d := l - fl
27 e += d * d
28 }
29 e = math.Sqrt(e)
30
31 if e > 1.0 {
32 t.Fatalf("imprecision on fastlog2 implementation, want <=1.0, got %f", e)
33 }
34 }
35
View as plain text