summaryrefslogtreecommitdiff
path: root/libgo/go/math/all_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/math/all_test.go')
-rw-r--r--libgo/go/math/all_test.go90
1 files changed, 85 insertions, 5 deletions
diff --git a/libgo/go/math/all_test.go b/libgo/go/math/all_test.go
index 763efb2e647..e18e45e0202 100644
--- a/libgo/go/math/all_test.go
+++ b/libgo/go/math/all_test.go
@@ -946,16 +946,20 @@ var expSC = []float64{
var vfexpm1SC = []float64{
Inf(-1),
+ -710,
Copysign(0, -1),
0,
+ 710,
Inf(1),
NaN(),
}
var expm1SC = []float64{
-1,
+ -1,
Copysign(0, -1),
0,
Inf(1),
+ Inf(1),
NaN(),
}
@@ -991,6 +995,24 @@ var vffdimSC = [][2]float64{
{NaN(), Inf(1)},
{NaN(), NaN()},
}
+var nan = Float64frombits(0xFFF8000000000000) // SSE2 DIVSD 0/0
+var vffdim2SC = [][2]float64{
+ {Inf(-1), Inf(-1)},
+ {Inf(-1), Inf(1)},
+ {Inf(-1), nan},
+ {Copysign(0, -1), Copysign(0, -1)},
+ {Copysign(0, -1), 0},
+ {0, Copysign(0, -1)},
+ {0, 0},
+ {Inf(1), Inf(-1)},
+ {Inf(1), Inf(1)},
+ {Inf(1), nan},
+ {nan, Inf(-1)},
+ {nan, Copysign(0, -1)},
+ {nan, 0},
+ {nan, Inf(1)},
+ {nan, nan},
+}
var fdimSC = []float64{
NaN(),
0,
@@ -1708,8 +1730,10 @@ func tolerance(a, b, e float64) bool {
d = -d
}
- if a != 0 {
- e = e * a
+ // note: b is correct (expected) value, a is actual value.
+ // make error tolerance a fraction of b, not a.
+ if b != 0 {
+ e = e * b
if e < 0 {
e = -e
}
@@ -2015,6 +2039,11 @@ func TestDim(t *testing.T) {
t.Errorf("Dim(%g, %g) = %g, want %g", vffdimSC[i][0], vffdimSC[i][1], f, fdimSC[i])
}
}
+ for i := 0; i < len(vffdim2SC); i++ {
+ if f := Dim(vffdim2SC[i][0], vffdim2SC[i][1]); !alike(fdimSC[i], f) {
+ t.Errorf("Dim(%g, %g) = %g, want %g", vffdim2SC[i][0], vffdim2SC[i][1], f, fdimSC[i])
+ }
+ }
}
func TestFloor(t *testing.T) {
@@ -2041,6 +2070,11 @@ func TestMax(t *testing.T) {
t.Errorf("Max(%g, %g) = %g, want %g", vffdimSC[i][0], vffdimSC[i][1], f, fmaxSC[i])
}
}
+ for i := 0; i < len(vffdim2SC); i++ {
+ if f := Max(vffdim2SC[i][0], vffdim2SC[i][1]); !alike(fmaxSC[i], f) {
+ t.Errorf("Max(%g, %g) = %g, want %g", vffdim2SC[i][0], vffdim2SC[i][1], f, fmaxSC[i])
+ }
+ }
}
func TestMin(t *testing.T) {
@@ -2054,6 +2088,11 @@ func TestMin(t *testing.T) {
t.Errorf("Min(%g, %g) = %g, want %g", vffdimSC[i][0], vffdimSC[i][1], f, fminSC[i])
}
}
+ for i := 0; i < len(vffdim2SC); i++ {
+ if f := Min(vffdim2SC[i][0], vffdim2SC[i][1]); !alike(fminSC[i], f) {
+ t.Errorf("Min(%g, %g) = %g, want %g", vffdim2SC[i][0], vffdim2SC[i][1], f, fminSC[i])
+ }
+ }
}
func TestMod(t *testing.T) {
@@ -2606,7 +2645,7 @@ func TestLargeTan(t *testing.T) {
// Check that math constants are accepted by compiler
// and have right value (assumes strconv.ParseFloat works).
-// http://code.google.com/p/go/issues/detail?id=201
+// https://golang.org/issue/201
type floatTest struct {
val interface{}
@@ -2944,15 +2983,56 @@ func BenchmarkSinh(b *testing.B) {
}
}
+var Global float64
+
func BenchmarkSqrt(b *testing.B) {
+ x, y := 0.0, 10.0
+ for i := 0; i < b.N; i++ {
+ x += Sqrt(y)
+ }
+ Global = x
+}
+
+func BenchmarkSqrtIndirect(b *testing.B) {
+ x, y := 0.0, 10.0
+ f := Sqrt
for i := 0; i < b.N; i++ {
- Sqrt(10)
+ x += f(y)
}
+ Global = x
}
func BenchmarkSqrtGo(b *testing.B) {
+ x, y := 0.0, 10.0
+ for i := 0; i < b.N; i++ {
+ x += SqrtGo(y)
+ }
+ Global = x
+}
+
+func isPrime(i int) bool {
+ // Yes, this is a dumb way to write this code,
+ // but calling Sqrt repeatedly in this way demonstrates
+ // the benefit of using a direct SQRT instruction on systems
+ // that have one, whereas the obvious loop seems not to
+ // demonstrate such a benefit.
+ for j := 2; float64(j) <= Sqrt(float64(i)); j++ {
+ if i%j == 0 {
+ return false
+ }
+ }
+ return true
+}
+
+func BenchmarkSqrtPrime(b *testing.B) {
+ any := false
for i := 0; i < b.N; i++ {
- SqrtGo(10)
+ if isPrime(100003) {
+ any = true
+ }
+ }
+ if any {
+ Global = 1
}
}