github.com/kdevb0x/go@v0.0.0-20180115030120-39687051e9e7/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 TestLargeTanNovec(t *testing.T) {
   110  	if !HasVX {
   111  		t.Skipf("no vector support")
   112  	}
   113  	large := float64(100000 * Pi)
   114  	for i := 0; i < len(vf); i++ {
   115  		f1 := tanLarge[i]
   116  		f2 := TanNovec(vf[i] + large)
   117  		if !close(f1, f2) {
   118  			t.Errorf("Tan(%g) = %g, want %g", vf[i]+large, f2, f1)
   119  		}
   120  	}
   121  }
   122  
   123  func TestTanNovec(t *testing.T) {
   124  	if !HasVX {
   125  		t.Skipf("no vector support")
   126  	}
   127  	for i := 0; i < len(vf); i++ {
   128  		if f := TanNovec(vf[i]); !veryclose(tan[i], f) {
   129  			t.Errorf("Tan(%g) = %g, want %g", vf[i], f, tan[i])
   130  		}
   131  	}
   132  	// same special cases as Sin
   133  	for i := 0; i < len(vfsinSC); i++ {
   134  		if f := TanNovec(vfsinSC[i]); !alike(sinSC[i], f) {
   135  			t.Errorf("Tan(%g) = %g, want %g", vfsinSC[i], f, sinSC[i])
   136  		}
   137  	}
   138  }
   139  
   140  func TestTanhNovec(t *testing.T) {
   141  	if !HasVX {
   142  		t.Skipf("no vector support")
   143  	}
   144  	for i := 0; i < len(vf); i++ {
   145  		if f := TanhNoVec(vf[i]); !veryclose(tanh[i], f) {
   146  			t.Errorf("Tanh(%g) = %g, want %g", vf[i], f, tanh[i])
   147  		}
   148  	}
   149  	for i := 0; i < len(vftanhSC); i++ {
   150  		if f := TanhNoVec(vftanhSC[i]); !alike(tanhSC[i], f) {
   151  			t.Errorf("Tanh(%g) = %g, want %g", vftanhSC[i], f, tanhSC[i])
   152  		}
   153  	}
   154  
   155  }
   156  
   157  func TestLog10Novec(t *testing.T) {
   158  	if !HasVX {
   159  		t.Skipf("no vector support")
   160  	}
   161  	for i := 0; i < len(vf); i++ {
   162  		a := Abs(vf[i])
   163  		if f := Log10NoVec(a); !veryclose(log10[i], f) {
   164  			t.Errorf("Log10(%g) = %g, want %g", a, f, log10[i])
   165  		}
   166  	}
   167  	if f := Log10NoVec(E); f != Log10E {
   168  		t.Errorf("Log10(%g) = %g, want %g", E, f, Log10E)
   169  	}
   170  	for i := 0; i < len(vflogSC); i++ {
   171  		if f := Log10NoVec(vflogSC[i]); !alike(logSC[i], f) {
   172  			t.Errorf("Log10(%g) = %g, want %g", vflogSC[i], f, logSC[i])
   173  		}
   174  	}
   175  }
   176  
   177  func TestLog1pNovec(t *testing.T) {
   178  	if !HasVX {
   179  		t.Skipf("no vector support")
   180  	}
   181  	for i := 0; i < len(vf); i++ {
   182  		a := vf[i] / 100
   183  		if f := Log1pNovec(a); !veryclose(log1p[i], f) {
   184  			t.Errorf("Log1p(%g) = %g, want %g", a, f, log1p[i])
   185  		}
   186  	}
   187  	a := 9.0
   188  	if f := Log1pNovec(a); f != Ln10 {
   189  		t.Errorf("Log1p(%g) = %g, want %g", a, f, Ln10)
   190  	}
   191  	for i := 0; i < len(vflogSC); i++ {
   192  		if f := Log1pNovec(vflog1pSC[i]); !alike(log1pSC[i], f) {
   193  			t.Errorf("Log1p(%g) = %g, want %g", vflog1pSC[i], f, log1pSC[i])
   194  		}
   195  	}
   196  }
   197  
   198  func TestAtanhNovec(t *testing.T) {
   199  	if !HasVX {
   200  		t.Skipf("no vector support")
   201  	}
   202  	for i := 0; i < len(vf); i++ {
   203  		a := vf[i] / 10
   204  		if f := AtanhNovec(a); !veryclose(atanh[i], f) {
   205  			t.Errorf("Atanh(%g) = %g, want %g", a, f, atanh[i])
   206  		}
   207  	}
   208  	for i := 0; i < len(vfatanhSC); i++ {
   209  		if f := AtanhNovec(vfatanhSC[i]); !alike(atanhSC[i], f) {
   210  			t.Errorf("Atanh(%g) = %g, want %g", vfatanhSC[i], f, atanhSC[i])
   211  		}
   212  	}
   213  }
   214  
   215  func TestAcosNovec(t *testing.T) {
   216  	if !HasVX {
   217  		t.Skipf("no vector support")
   218  	}
   219  	for i := 0; i < len(vf); i++ {
   220  		a := vf[i] / 10
   221  		if f := AcosNovec(a); !close(acos[i], f) {
   222  			t.Errorf("Acos(%g) = %g, want %g", a, f, acos[i])
   223  		}
   224  	}
   225  	for i := 0; i < len(vfacosSC); i++ {
   226  		if f := AcosNovec(vfacosSC[i]); !alike(acosSC[i], f) {
   227  			t.Errorf("Acos(%g) = %g, want %g", vfacosSC[i], f, acosSC[i])
   228  		}
   229  	}
   230  }
   231  
   232  func TestAsinNovec(t *testing.T) {
   233  	if !HasVX {
   234  		t.Skipf("no vector support")
   235  	}
   236  	for i := 0; i < len(vf); i++ {
   237  		a := vf[i] / 10
   238  		if f := AsinNovec(a); !veryclose(asin[i], f) {
   239  			t.Errorf("Asin(%g) = %g, want %g", a, f, asin[i])
   240  		}
   241  	}
   242  	for i := 0; i < len(vfasinSC); i++ {
   243  		if f := AsinNovec(vfasinSC[i]); !alike(asinSC[i], f) {
   244  			t.Errorf("Asin(%g) = %g, want %g", vfasinSC[i], f, asinSC[i])
   245  		}
   246  	}
   247  }
   248  
   249  func TestAcoshNovec(t *testing.T) {
   250  	if !HasVX {
   251  		t.Skipf("no vector support")
   252  	}
   253  	for i := 0; i < len(vf); i++ {
   254  		a := 1 + Abs(vf[i])
   255  		if f := AcoshNovec(a); !veryclose(acosh[i], f) {
   256  			t.Errorf("Acosh(%g) = %g, want %g", a, f, acosh[i])
   257  		}
   258  	}
   259  	for i := 0; i < len(vfacoshSC); i++ {
   260  		if f := AcoshNovec(vfacoshSC[i]); !alike(acoshSC[i], f) {
   261  			t.Errorf("Acosh(%g) = %g, want %g", vfacoshSC[i], f, acoshSC[i])
   262  		}
   263  	}
   264  }
   265  
   266  func TestAsinhNovec(t *testing.T) {
   267  	if !HasVX {
   268  		t.Skipf("no vector support")
   269  	}
   270  	for i := 0; i < len(vf); i++ {
   271  		if f := AsinhNovec(vf[i]); !veryclose(asinh[i], f) {
   272  			t.Errorf("Asinh(%g) = %g, want %g", vf[i], f, asinh[i])
   273  		}
   274  	}
   275  	for i := 0; i < len(vfasinhSC); i++ {
   276  		if f := AsinhNovec(vfasinhSC[i]); !alike(asinhSC[i], f) {
   277  			t.Errorf("Asinh(%g) = %g, want %g", vfasinhSC[i], f, asinhSC[i])
   278  		}
   279  	}
   280  }
   281  
   282  func TestErfNovec(t *testing.T) {
   283  	if !HasVX {
   284  		t.Skipf("no vector support")
   285  	}
   286  	for i := 0; i < len(vf); i++ {
   287  		a := vf[i] / 10
   288  		if f := ErfNovec(a); !veryclose(erf[i], f) {
   289  			t.Errorf("Erf(%g) = %g, want %g", a, f, erf[i])
   290  		}
   291  	}
   292  	for i := 0; i < len(vferfSC); i++ {
   293  		if f := ErfNovec(vferfSC[i]); !alike(erfSC[i], f) {
   294  			t.Errorf("Erf(%g) = %g, want %g", vferfSC[i], f, erfSC[i])
   295  		}
   296  	}
   297  }
   298  
   299  func TestErfcNovec(t *testing.T) {
   300  	if !HasVX {
   301  		t.Skipf("no vector support")
   302  	}
   303  	for i := 0; i < len(vf); i++ {
   304  		a := vf[i] / 10
   305  		if f := ErfcNovec(a); !veryclose(erfc[i], f) {
   306  			t.Errorf("Erfc(%g) = %g, want %g", a, f, erfc[i])
   307  		}
   308  	}
   309  	for i := 0; i < len(vferfcSC); i++ {
   310  		if f := ErfcNovec(vferfcSC[i]); !alike(erfcSC[i], f) {
   311  			t.Errorf("Erfc(%g) = %g, want %g", vferfcSC[i], f, erfcSC[i])
   312  		}
   313  	}
   314  }
   315  
   316  func TestAtanNovec(t *testing.T) {
   317  	if !HasVX {
   318  		t.Skipf("no vector support")
   319  	}
   320  	for i := 0; i < len(vf); i++ {
   321  		if f := AtanNovec(vf[i]); !veryclose(atan[i], f) {
   322  			t.Errorf("Atan(%g) = %g, want %g", vf[i], f, atan[i])
   323  		}
   324  	}
   325  	for i := 0; i < len(vfatanSC); i++ {
   326  		if f := AtanNovec(vfatanSC[i]); !alike(atanSC[i], f) {
   327  			t.Errorf("Atan(%g) = %g, want %g", vfatanSC[i], f, atanSC[i])
   328  		}
   329  	}
   330  }
   331  
   332  func TestAtan2Novec(t *testing.T) {
   333  	if !HasVX {
   334  		t.Skipf("no vector support")
   335  	}
   336  	for i := 0; i < len(vf); i++ {
   337  		if f := Atan2Novec(10, vf[i]); !veryclose(atan2[i], f) {
   338  			t.Errorf("Atan2(10, %g) = %g, want %g", vf[i], f, atan2[i])
   339  		}
   340  	}
   341  	for i := 0; i < len(vfatan2SC); i++ {
   342  		if f := Atan2Novec(vfatan2SC[i][0], vfatan2SC[i][1]); !alike(atan2SC[i], f) {
   343  			t.Errorf("Atan2(%g, %g) = %g, want %g", vfatan2SC[i][0], vfatan2SC[i][1], f, atan2SC[i])
   344  		}
   345  	}
   346  }
   347  
   348  func TestCbrtNovec(t *testing.T) {
   349  	if !HasVX {
   350  		t.Skipf("no vector support")
   351  	}
   352  	for i := 0; i < len(vf); i++ {
   353  		if f := CbrtNovec(vf[i]); !veryclose(cbrt[i], f) {
   354  			t.Errorf("Cbrt(%g) = %g, want %g", vf[i], f, cbrt[i])
   355  		}
   356  	}
   357  	for i := 0; i < len(vfcbrtSC); i++ {
   358  		if f := CbrtNovec(vfcbrtSC[i]); !alike(cbrtSC[i], f) {
   359  			t.Errorf("Cbrt(%g) = %g, want %g", vfcbrtSC[i], f, cbrtSC[i])
   360  		}
   361  	}
   362  }
   363  
   364  func TestLogNovec(t *testing.T) {
   365  	if !HasVX {
   366  		t.Skipf("no vector support")
   367  	}
   368  	for i := 0; i < len(vf); i++ {
   369  		a := Abs(vf[i])
   370  		if f := LogNovec(a); log[i] != f {
   371  			t.Errorf("Log(%g) = %g, want %g", a, f, log[i])
   372  		}
   373  	}
   374  	if f := LogNovec(10); f != Ln10 {
   375  		t.Errorf("Log(%g) = %g, want %g", 10.0, f, Ln10)
   376  	}
   377  	for i := 0; i < len(vflogSC); i++ {
   378  		if f := LogNovec(vflogSC[i]); !alike(logSC[i], f) {
   379  			t.Errorf("Log(%g) = %g, want %g", vflogSC[i], f, logSC[i])
   380  		}
   381  	}
   382  }
   383  
   384  func TestExpNovec(t *testing.T) {
   385  	if !HasVX {
   386  		t.Skipf("no vector support")
   387  	}
   388  	testExpNovec(t, Exp, "Exp")
   389  	testExpNovec(t, ExpGo, "ExpGo")
   390  }
   391  
   392  func testExpNovec(t *testing.T, Exp func(float64) float64, name string) {
   393  	for i := 0; i < len(vf); i++ {
   394  		if f := ExpNovec(vf[i]); !veryclose(exp[i], f) {
   395  			t.Errorf("%s(%g) = %g, want %g", name, vf[i], f, exp[i])
   396  		}
   397  	}
   398  	for i := 0; i < len(vfexpSC); i++ {
   399  		if f := ExpNovec(vfexpSC[i]); !alike(expSC[i], f) {
   400  			t.Errorf("%s(%g) = %g, want %g", name, vfexpSC[i], f, expSC[i])
   401  		}
   402  	}
   403  }
   404  
   405  func TestExpm1Novec(t *testing.T) {
   406  	if !HasVX {
   407  		t.Skipf("no vector support")
   408  	}
   409  	for i := 0; i < len(vf); i++ {
   410  		a := vf[i] / 100
   411  		if f := Expm1Novec(a); !veryclose(expm1[i], f) {
   412  			t.Errorf("Expm1(%g) = %g, want %g", a, f, expm1[i])
   413  		}
   414  	}
   415  	for i := 0; i < len(vf); i++ {
   416  		a := vf[i] * 10
   417  		if f := Expm1Novec(a); !close(expm1Large[i], f) {
   418  			t.Errorf("Expm1(%g) = %g, want %g", a, f, expm1Large[i])
   419  		}
   420  	}
   421  	for i := 0; i < len(vfexpm1SC); i++ {
   422  		if f := Expm1Novec(vfexpm1SC[i]); !alike(expm1SC[i], f) {
   423  			t.Errorf("Expm1(%g) = %g, want %g", vfexpm1SC[i], f, expm1SC[i])
   424  		}
   425  	}
   426  }
   427  
   428  func TestPowNovec(t *testing.T) {
   429  	if !HasVX {
   430  		t.Skipf("no vector support")
   431  	}
   432  	for i := 0; i < len(vf); i++ {
   433  		if f := PowNovec(10, vf[i]); !close(pow[i], f) {
   434  			t.Errorf("Pow(10, %g) = %g, want %g", vf[i], f, pow[i])
   435  		}
   436  	}
   437  	for i := 0; i < len(vfpowSC); i++ {
   438  		if f := PowNovec(vfpowSC[i][0], vfpowSC[i][1]); !alike(powSC[i], f) {
   439  			t.Errorf("Pow(%g, %g) = %g, want %g", vfpowSC[i][0], vfpowSC[i][1], f, powSC[i])
   440  		}
   441  	}
   442  }