2017-03-02 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgo / go / runtime / fastlog2_test.go
blob6e9fcd4d45ea2ef8e76aee4a5d641c54b0abf5e1
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build ignore
7 package runtime_test
9 import (
10 "math"
11 "runtime"
12 "testing"
15 func TestFastLog2(t *testing.T) {
16 // Compute the euclidean distance between math.Log2 and the FastLog2
17 // implementation over the range of interest for heap sampling.
18 const randomBitCount = 26
19 var e float64
21 inc := 1
22 if testing.Short() {
23 // Check 1K total values, down from 64M.
24 inc = 1 << 16
26 for i := 1; i < 1<<randomBitCount; i += inc {
27 l, fl := math.Log2(float64(i)), runtime.Fastlog2(float64(i))
28 d := l - fl
29 e += d * d
31 e = math.Sqrt(e)
33 if e > 1.0 {
34 t.Fatalf("imprecision on fastlog2 implementation, want <=1.0, got %f", e)