github.com/fenixara/go@v0.0.0-20170127160404-96ea0918e670/src/math/arith_s390x_test.go (about) 1 // Copyright 2016 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. 4 5 // Tests whether the non vector routines are working, even when the tests are run on a 6 // vector-capable machine. 7 package math_test 8 9 import ( 10 . "math" 11 "testing" 12 ) 13 14 func TestCosNovec(t *testing.T) { 15 if !HasVX { 16 t.Skipf("no vector support") 17 } 18 for i := 0; i < len(vf); i++ { 19 if f := CosNoVec(vf[i]); !veryclose(cos[i], f) { 20 t.Errorf("Cos(%g) = %g, want %g", vf[i], f, cos[i]) 21 } 22 } 23 for i := 0; i < len(vfcosSC); i++ { 24 if f := CosNoVec(vfcosSC[i]); !alike(cosSC[i], f) { 25 t.Errorf("Cos(%g) = %g, want %g", vfcosSC[i], f, cosSC[i]) 26 } 27 } 28 } 29 30 func TestCoshNovec(t *testing.T) { 31 if !HasVX { 32 t.Skipf("no vector support") 33 } 34 for i := 0; i < len(vf); i++ { 35 if f := CoshNoVec(vf[i]); !close(cosh[i], f) { 36 t.Errorf("Cosh(%g) = %g, want %g", vf[i], f, cosh[i]) 37 } 38 } 39 for i := 0; i < len(vfcoshSC); i++ { 40 if f := CoshNoVec(vfcoshSC[i]); !alike(coshSC[i], f) { 41 t.Errorf("Cosh(%g) = %g, want %g", vfcoshSC[i], f, coshSC[i]) 42 } 43 } 44 } 45 func TestSinNovec(t *testing.T) { 46 if !HasVX { 47 t.Skipf("no vector support") 48 } 49 for i := 0; i < len(vf); i++ { 50 if f := SinNoVec(vf[i]); !veryclose(sin[i], f) { 51 t.Errorf("Sin(%g) = %g, want %g", vf[i], f, sin[i]) 52 } 53 } 54 for i := 0; i < len(vfsinSC); i++ { 55 if f := SinNoVec(vfsinSC[i]); !alike(sinSC[i], f) { 56 t.Errorf("Sin(%g) = %g, want %g", vfsinSC[i], f, sinSC[i]) 57 } 58 } 59 } 60 61 func TestSinhNovec(t *testing.T) { 62 if !HasVX { 63 t.Skipf("no vector support") 64 } 65 for i := 0; i < len(vf); i++ { 66 if f := SinhNoVec(vf[i]); !close(sinh[i], f) { 67 t.Errorf("Sinh(%g) = %g, want %g", vf[i], f, sinh[i]) 68 } 69 } 70 for i := 0; i < len(vfsinhSC); i++ { 71 if f := SinhNoVec(vfsinhSC[i]); !alike(sinhSC[i], f) { 72 t.Errorf("Sinh(%g) = %g, want %g", vfsinhSC[i], f, sinhSC[i]) 73 } 74 } 75 } 76 77 // Check that math functions of high angle values 78 // return accurate results. [Since (vf[i] + large) - large != vf[i], 79 // testing for Trig(vf[i] + large) == Trig(vf[i]), where large is 80 // a multiple of 2*Pi, is misleading.] 81 func TestLargeCosNovec(t *testing.T) { 82 if !HasVX { 83 t.Skipf("no vector support") 84 } 85 large := float64(100000 * Pi) 86 for i := 0; i < len(vf); i++ { 87 f1 := cosLarge[i] 88 f2 := CosNoVec(vf[i] + large) 89 if !close(f1, f2) { 90 t.Errorf("Cos(%g) = %g, want %g", vf[i]+large, f2, f1) 91 } 92 } 93 } 94 95 func TestLargeSinNovec(t *testing.T) { 96 if !HasVX { 97 t.Skipf("no vector support") 98 } 99 large := float64(100000 * Pi) 100 for i := 0; i < len(vf); i++ { 101 f1 := sinLarge[i] 102 f2 := SinNoVec(vf[i] + large) 103 if !close(f1, f2) { 104 t.Errorf("Sin(%g) = %g, want %g", vf[i]+large, f2, f1) 105 } 106 } 107 } 108 109 func TestTanhNovec(t *testing.T) { 110 if !HasVX { 111 t.Skipf("no vector support") 112 } 113 for i := 0; i < len(vf); i++ { 114 if f := TanhNoVec(vf[i]); !veryclose(tanh[i], f) { 115 t.Errorf("Tanh(%g) = %g, want %g", vf[i], f, tanh[i]) 116 } 117 } 118 for i := 0; i < len(vftanhSC); i++ { 119 if f := TanhNoVec(vftanhSC[i]); !alike(tanhSC[i], f) { 120 t.Errorf("Tanh(%g) = %g, want %g", vftanhSC[i], f, tanhSC[i]) 121 } 122 } 123 124 } 125 126 func TestLog10Novec(t *testing.T) { 127 if !HasVX { 128 t.Skipf("no vector support") 129 } 130 for i := 0; i < len(vf); i++ { 131 a := Abs(vf[i]) 132 if f := Log10NoVec(a); !veryclose(log10[i], f) { 133 t.Errorf("Log10(%g) = %g, want %g", a, f, log10[i]) 134 } 135 } 136 if f := Log10NoVec(E); f != Log10E { 137 t.Errorf("Log10(%g) = %g, want %g", E, f, Log10E) 138 } 139 for i := 0; i < len(vflogSC); i++ { 140 if f := Log10NoVec(vflogSC[i]); !alike(logSC[i], f) { 141 t.Errorf("Log10(%g) = %g, want %g", vflogSC[i], f, logSC[i]) 142 } 143 } 144 }