math: add functions; update tests and special cases
Added special cases to comments for asin.go and fabs.go.
Added Trunc() to floor.go and floor_386.s. Fixed formatting
error in hypot_386.s Added new functions Acosh, Asinh,
Atanh, Copysign, Erf, Erfc, Expm1, and Log1p. Added
386 FPU version of Fmod. Added tests, benchmarks, and
precision to expected results in all_test.go. Edited
makefile so it all compiles.
R=rsc
CC=golang-dev
https://golang.org/cl/195052
diff --git a/src/pkg/math/all_test.go b/src/pkg/math/all_test.go
index 9490e06..59fdd9e 100644
--- a/src/pkg/math/all_test.go
+++ b/src/pkg/math/all_test.go
@@ -22,41 +22,83 @@
1.8253080916808550e+00,
-8.6859247685756013e+00,
}
+// The expected results below were computed by the high precision calculators
+// at http://keisan.casio.com/. More exact input values (array vf[], above)
+// were obtained by printing them with "%.26f". The answers were calculated
+// to 26 digits (by using the "Digit number" drop-down control of each
+// calculator). Twenty-six digits were chosen so that the answers would be
+// accurate even for a float128 type.
var acos = []float64{
- 1.0496193546107222e+00,
- 6.858401281366443e-01,
- 1.598487871457716e+00,
- 2.095619936147586e+00,
- 2.7053008467824158e-01,
- 1.2738121680361776e+00,
- 1.0205369421140630e+00,
- 1.2945003481781246e+00,
- 1.3872364345374451e+00,
- 2.6231510803970464e+00,
+ 1.0496193546107222142571536e+00,
+ 6.8584012813664425171660692e-01,
+ 1.5984878714577160325521819e+00,
+ 2.0956199361475859327461799e+00,
+ 2.7053008467824138592616927e-01,
+ 1.2738121680361776018155625e+00,
+ 1.0205369421140629186287407e+00,
+ 1.2945003481781246062157835e+00,
+ 1.3872364345374451433846657e+00,
+ 2.6231510803970463967294145e+00,
+}
+var acosh = []float64{
+ 2.4743347004159012494457618e+00,
+ 2.8576385344292769649802701e+00,
+ 7.2796961502981066190593175e-01,
+ 2.4796794418831451156471977e+00,
+ 3.0552020742306061857212962e+00,
+ 2.044238592688586588942468e+00,
+ 2.5158701513104513595766636e+00,
+ 1.99050839282411638174299e+00,
+ 1.6988625798424034227205445e+00,
+ 2.9611454842470387925531875e+00,
}
var asin = []float64{
- 5.2117697218417440e-01,
- 8.8495619865825236e-01,
- -2.7691544662819413e-02,
- -5.2482360935268932e-01,
- 1.3002662421166553e+00,
- 2.9698415875871901e-01,
- 5.5025938468083364e-01,
- 2.7629597861677200e-01,
- 1.8355989225745148e-01,
- -1.0523547536021498e+00,
+ 5.2117697218417440497416805e-01,
+ 8.8495619865825236751471477e-01,
+ -02.769154466281941332086016e-02,
+ -5.2482360935268931351485822e-01,
+ 1.3002662421166552333051524e+00,
+ 2.9698415875871901741575922e-01,
+ 5.5025938468083370060258102e-01,
+ 2.7629597861677201301553823e-01,
+ 1.83559892257451475846656e-01,
+ -1.0523547536021497774980928e+00,
+}
+var asinh = []float64{
+ 2.3083139124923523427628243e+00,
+ 2.743551594301593620039021e+00,
+ -2.7345908534880091229413487e-01,
+ -2.3145157644718338650499085e+00,
+ 2.9613652154015058521951083e+00,
+ 1.7949041616585821933067568e+00,
+ 2.3564032905983506405561554e+00,
+ 1.7287118790768438878045346e+00,
+ 1.3626658083714826013073193e+00,
+ -2.8581483626513914445234004e+00,
}
var atan = []float64{
- 1.3725902621296217e+00,
- 1.4422906096452980e+00,
- -2.7011324359471755e-01,
- -1.3738077684543379e+00,
- 1.4673921193587666e+00,
- 1.2415173565870167e+00,
- 1.3818396865615167e+00,
- 1.2194305844639670e+00,
- 1.0696031952318783e+00,
- -1.4561721938838085e+00,
+ 1.372590262129621651920085e+00,
+ 1.442290609645298083020664e+00,
+ -2.7011324359471758245192595e-01,
+ -1.3738077684543379452781531e+00,
+ 1.4673921193587666049154681e+00,
+ 1.2415173565870168649117764e+00,
+ 1.3818396865615168979966498e+00,
+ 1.2194305844639670701091426e+00,
+ 1.0696031952318783760193244e+00,
+ -1.4561721938838084990898679e+00,
+}
+var atanh = []float64{
+ 5.4651163712251938116878204e-01,
+ 1.0299474112843111224914709e+00,
+ -2.7695084420740135145234906e-02,
+ -5.5072096119207195480202529e-01,
+ 1.9943940993171843235906642e+00,
+ 3.01448604578089708203017e-01,
+ 5.8033427206942188834370595e-01,
+ 2.7987997499441511013958297e-01,
+ 1.8459947964298794318714228e-01,
+ -1.3273186910532645867272502e+00,
}
var ceil = []float64{
5.0000000000000000e+00,
@@ -70,17 +112,89 @@
2.0000000000000000e+00,
-8.0000000000000000e+00,
}
+var copysign = []float64{
+ -4.9790119248836735e+00,
+ -7.7388724745781045e+00,
+ -2.7688005719200159e-01,
+ -5.0106036182710749e+00,
+ -9.6362937071984173e+00,
+ -2.9263772392439646e+00,
+ -5.2290834314593066e+00,
+ -2.7279399104360102e+00,
+ -1.8253080916808550e+00,
+ -8.6859247685756013e+00,
+}
+var cos = []float64{
+ 2.634752140995199110787593e-01,
+ 1.148551260848219865642039e-01,
+ 9.6191297325640768154550453e-01,
+ 2.938141150061714816890637e-01,
+ -9.777138189897924126294461e-01,
+ -9.7693041344303219127199518e-01,
+ 4.940088096948647263961162e-01,
+ -9.1565869021018925545016502e-01,
+ -2.517729313893103197176091e-01,
+ -7.39241351595676573201918e-01,
+}
+var cosh = []float64{
+ 7.2668796942212842775517446e+01,
+ 1.1479413465659254502011135e+03,
+ 1.0385767908766418550935495e+00,
+ 7.5000957789658051428857788e+01,
+ 7.655246669605357888468613e+03,
+ 9.3567491758321272072888257e+00,
+ 9.331351599270605471131735e+01,
+ 7.6833430994624643209296404e+00,
+ 3.1829371625150718153881164e+00,
+ 2.9595059261916188501640911e+03,
+}
+var erf = []float64{
+ 5.1865354817738701906913566e-01,
+ 7.2623875834137295116929844e-01,
+ -3.123458688281309990629839e-02,
+ -5.2143121110253302920437013e-01,
+ 8.2704742671312902508629582e-01,
+ 3.2101767558376376743993945e-01,
+ 5.403990312223245516066252e-01,
+ 3.0034702916738588551174831e-01,
+ 2.0369924417882241241559589e-01,
+ -7.8069386968009226729944677e-01,
+}
+var erfc = []float64{
+ 4.8134645182261298093086434e-01,
+ 2.7376124165862704883070156e-01,
+ 1.0312345868828130999062984e+00,
+ 1.5214312111025330292043701e+00,
+ 1.7295257328687097491370418e-01,
+ 6.7898232441623623256006055e-01,
+ 4.596009687776754483933748e-01,
+ 6.9965297083261411448825169e-01,
+ 7.9630075582117758758440411e-01,
+ 1.7806938696800922672994468e+00,
+}
var exp = []float64{
- 1.4533071302642137e+02,
- 2.2958822575694450e+03,
- 7.5814542574851666e-01,
- 6.6668778421791010e-03,
- 1.5310493273896035e+04,
- 1.8659907517999329e+01,
- 1.8662167355098713e+02,
- 1.5301332413189379e+01,
- 6.2047063430646876e+00,
- 1.6894712385826522e-04,
+ 1.4533071302642137507696589e+02,
+ 2.2958822575694449002537581e+03,
+ 7.5814542574851666582042306e-01,
+ 6.6668778421791005061482264e-03,
+ 1.5310493273896033740861206e+04,
+ 1.8659907517999328638667732e+01,
+ 1.8662167355098714543942057e+02,
+ 1.5301332413189378961665788e+01,
+ 6.2047063430646876349125085e+00,
+ 1.6894712385826521111610438e-04,
+}
+var expm1 = []float64{
+ 5.105047796122957327384770212e-02,
+ 8.046199708567344080562675439e-02,
+ -2.764970978891639815187418703e-03,
+ -4.8871434888875355394330300273e-02,
+ 1.0115864277221467777117227494e-01,
+ 2.969616407795910726014621657e-02,
+ 5.368214487944892300914037972e-02,
+ 2.765488851131274068067445335e-02,
+ 1.842068661871398836913874273e-02,
+ -8.3193870863553801814961137573e-02,
}
var floor = []float64{
4.0000000000000000e+00,
@@ -95,115 +209,150 @@
-9.0000000000000000e+00,
}
var fmod = []float64{
- 4.1976150232653000e-02,
- 2.2611275254218955e+00,
- 3.2317941087942760e-02,
- 4.9893963817289251e+00,
- 3.6370629280158270e-01,
- 1.2208682822681062e+00,
- 4.7709165685406934e+00,
- 1.8161802686919694e+00,
- 8.7345954159572500e-01,
- 1.3140752314243987e+00,
+ 4.197615023265299782906368e-02,
+ 2.261127525421895434476482e+00,
+ 3.231794108794261433104108e-02,
+ 4.989396381728925078391512e+00,
+ 3.637062928015826201999516e-01,
+ 1.220868282268106064236690e+00,
+ 4.770916568540693347699744e+00,
+ 1.816180268691969246219742e+00,
+ 8.734595415957246977711748e-01,
+ 1.314075231424398637614104e+00,
}
var log = []float64{
- 1.6052314626930630e+00,
- 2.0462560018708768e+00,
- -1.2841708730962657e+00,
- 1.6115563905281544e+00,
- 2.2655365644872018e+00,
- 1.0737652208918380e+00,
- 1.6542360106073545e+00,
- 1.0035467127723465e+00,
- 6.0174879014578053e-01,
- 2.1617038728473527e+00,
+ 1.605231462693062999102599e+00,
+ 2.0462560018708770653153909e+00,
+ -1.2841708730962657801275038e+00,
+ 1.6115563905281545116286206e+00,
+ 2.2655365644872016636317461e+00,
+ 1.0737652208918379856272735e+00,
+ 1.6542360106073546632707956e+00,
+ 1.0035467127723465801264487e+00,
+ 6.0174879014578057187016475e-01,
+ 2.161703872847352815363655e+00,
}
var log10 = []float64{
- 6.9714316642508291e-01,
- 8.8867769017393205e-01,
- -5.5770832400658930e-01,
- 6.9989004768229943e-01,
- 9.8391002850684232e-01,
- 4.6633031029295153e-01,
- 7.1842557117242328e-01,
- 4.3583479968917772e-01,
- 2.6133617905227037e-01,
- 9.3881606348649405e-01,
+ 6.9714316642508290997617083e-01,
+ 8.886776901739320576279124e-01,
+ -5.5770832400658929815908236e-01,
+ 6.998900476822994346229723e-01,
+ 9.8391002850684232013281033e-01,
+ 4.6633031029295153334285302e-01,
+ 7.1842557117242328821552533e-01,
+ 4.3583479968917773161304553e-01,
+ 2.6133617905227038228626834e-01,
+ 9.3881606348649405716214241e-01,
+}
+var log1p = []float64{
+ 4.8590257759797794104158205e-02,
+ 7.4540265965225865330849141e-02,
+ -2.7726407903942672823234024e-03,
+ -5.1404917651627649094953380e-02,
+ 9.1998280672258624681335010e-02,
+ 2.8843762576593352865894824e-02,
+ 5.0969534581863707268992645e-02,
+ 2.6913947602193238458458594e-02,
+ 1.8088493239630770262045333e-02,
+ -9.0865245631588989681559268e-02,
}
var pow = []float64{
- 9.5282232631648415e+04,
- 5.4811599352999900e+07,
- 5.2859121715894400e-01,
- 9.7587991957286472e-06,
- 4.3280643293460450e+09,
- 8.4406761805034551e+02,
- 1.6946633276191194e+05,
- 5.3449040147551940e+02,
- 6.6881821384514159e+01,
- 2.0609869004248744e-09,
+ 9.5282232631648411840742957e+04,
+ 5.4811599352999901232411871e+07,
+ 5.2859121715894396531132279e-01,
+ 9.7587991957286474464259698e-06,
+ 4.328064329346044846740467e+09,
+ 8.4406761805034547437659092e+02,
+ 1.6946633276191194947742146e+05,
+ 5.3449040147551939075312879e+02,
+ 6.688182138451414936380374e+01,
+ 2.0609869004248742886827439e-09,
}
var sin = []float64{
- -9.6466616586009283e-01,
- 9.9338225271646543e-01,
- -2.7335587039794395e-01,
- 9.5586257685042800e-01,
- -2.0994210667799692e-01,
- 2.1355787807998605e-01,
- -8.6945689711673619e-01,
- 4.0195666811555783e-01,
- 9.6778633541688000e-01,
- -6.7344058690503452e-01,
+ -9.6466616586009283766724726e-01,
+ 9.9338225271646545763467022e-01,
+ -2.7335587039794393342449301e-01,
+ 9.5586257685042792878173752e-01,
+ -2.099421066779969164496634e-01,
+ 2.135578780799860532750616e-01,
+ -8.694568971167362743327708e-01,
+ 4.019566681155577786649878e-01,
+ 9.6778633541687993721617774e-01,
+ -6.734405869050344734943028e-01,
}
var sinh = []float64{
- 7.2661916084208533e+01,
- 1.1479409110035194e+03,
- -2.8043136512812520e-01,
- -7.4994290911815868e+01,
- 7.6552466042906761e+03,
- 9.3031583421672010e+00,
- 9.3308157558281088e+01,
- 7.6179893137269143e+00,
- 3.0217691805496156e+00,
- -2.9595057572444951e+03,
+ 7.2661916084208532301448439e+01,
+ 1.1479409110035194500526446e+03,
+ -2.8043136512812518927312641e-01,
+ -7.499429091181587232835164e+01,
+ 7.6552466042906758523925934e+03,
+ 9.3031583421672014313789064e+00,
+ 9.330815755828109072810322e+01,
+ 7.6179893137269146407361477e+00,
+ 3.021769180549615819524392e+00,
+ -2.95950575724449499189888e+03,
}
var sqrt = []float64{
- 2.2313699659365484e+00,
- 2.7818829009464263e+00,
- 5.2619393496314792e-01,
- 2.2384377628763938e+00,
- 3.1042380236055380e+00,
- 1.7106657298385224e+00,
- 2.2867189227054791e+00,
- 1.6516476350711160e+00,
- 1.3510396336454586e+00,
- 2.9471892997524950e+00,
+ 2.2313699659365484748756904e+00,
+ 2.7818829009464263511285458e+00,
+ 5.2619393496314796848143251e-01,
+ 2.2384377628763938724244104e+00,
+ 3.1042380236055381099288487e+00,
+ 1.7106657298385224403917771e+00,
+ 2.286718922705479046148059e+00,
+ 1.6516476350711159636222979e+00,
+ 1.3510396336454586262419247e+00,
+ 2.9471892997524949215723329e+00,
}
var tan = []float64{
- -3.6613165650402277e+00,
- 8.6490023264859754e+00,
- -2.8417941955033615e-01,
- 3.2532901859747287e+00,
- 2.1472756403802937e-01,
- -2.1860091071106700e-01,
- -1.7600028178723679e+00,
- -4.3898089147528178e-01,
- -3.8438855602011305e+00,
- 9.1098879337768517e-01,
+ -3.661316565040227801781974e+00,
+ 8.64900232648597589369854e+00,
+ -2.8417941955033612725238097e-01,
+ 3.253290185974728640827156e+00,
+ 2.147275640380293804770778e-01,
+ -2.18600910711067004921551e-01,
+ -1.760002817872367935518928e+00,
+ -4.389808914752818126249079e-01,
+ -3.843885560201130679995041e+00,
+ 9.10988793377685105753416e-01,
}
var tanh = []float64{
- 9.9990531206936328e-01,
- 9.9999962057085307e-01,
- -2.7001505097318680e-01,
- -9.9991110943061700e-01,
- 9.9999999146798441e-01,
- 9.9427249436125233e-01,
- 9.9994257600983156e-01,
- 9.9149409509772863e-01,
- 9.4936501296239700e-01,
- -9.9999994291374019e-01,
+ 9.9990531206936338549262119e-01,
+ 9.9999962057085294197613294e-01,
+ -2.7001505097318677233756845e-01,
+ -9.9991110943061718603541401e-01,
+ 9.9999999146798465745022007e-01,
+ 9.9427249436125236705001048e-01,
+ 9.9994257600983138572705076e-01,
+ 9.9149409509772875982054701e-01,
+ 9.4936501296239685514466577e-01,
+ -9.9999994291374030946055701e-01,
+}
+var trunc = []float64{
+ 4.0000000000000000e+00,
+ 7.0000000000000000e+00,
+ -0.0000000000000000e+00,
+ -5.0000000000000000e+00,
+ 9.0000000000000000e+00,
+ 2.0000000000000000e+00,
+ 5.0000000000000000e+00,
+ 2.0000000000000000e+00,
+ 1.0000000000000000e+00,
+ -8.0000000000000000e+00,
}
// arguments and expected results for special cases
+var vfacoshSC = []float64{
+ Inf(-1),
+ 0.5,
+ NaN(),
+}
+var acoshSC = []float64{
+ NaN(),
+ NaN(),
+ NaN(),
+}
+
var vfasinSC = []float64{
NaN(),
-Pi,
@@ -215,6 +364,17 @@
NaN(),
}
+var vfasinhSC = []float64{
+ Inf(-1),
+ Inf(1),
+ NaN(),
+}
+var asinhSC = []float64{
+ Inf(-1),
+ Inf(1),
+ NaN(),
+}
+
var vfatanSC = []float64{
NaN(),
}
@@ -222,6 +382,21 @@
NaN(),
}
+var vfatanhSC = []float64{
+ -Pi,
+ -1,
+ 1,
+ Pi,
+ NaN(),
+}
+var atanhSC = []float64{
+ NaN(),
+ Inf(-1),
+ Inf(1),
+ NaN(),
+ NaN(),
+}
+
var vfceilSC = []float64{
Inf(-1),
Inf(1),
@@ -233,6 +408,33 @@
NaN(),
}
+var vfcopysignSC = []float64{
+ Inf(-1),
+ Inf(1),
+ NaN(),
+}
+var copysignSC = []float64{
+ Inf(-1),
+ Inf(-1),
+ NaN(),
+}
+
+var vferfSC = []float64{
+ Inf(-1),
+ Inf(1),
+ NaN(),
+}
+var erfSC = []float64{
+ -1,
+ 1,
+ NaN(),
+}
+var erfcSC = []float64{
+ 2,
+ 0,
+ NaN(),
+}
+
var vfexpSC = []float64{
Inf(-1),
Inf(1),
@@ -243,6 +445,11 @@
Inf(1),
NaN(),
}
+var expm1SC = []float64{
+ -1,
+ Inf(1),
+ NaN(),
+}
var vffmodSC = [][2]float64{
[2]float64{Inf(-1), Inf(-1)},
@@ -359,6 +566,21 @@
NaN(),
}
+var vflog1pSC = []float64{
+ Inf(-1),
+ -Pi,
+ -1,
+ Inf(1),
+ NaN(),
+}
+var log1pSC = []float64{
+ NaN(),
+ NaN(),
+ Inf(-1),
+ Inf(1),
+ NaN(),
+}
+
var vfpowSC = [][2]float64{
[2]float64{-Pi, Pi},
[2]float64{-Pi, -Pi},
@@ -494,8 +716,9 @@
func TestAcos(t *testing.T) {
for i := 0; i < len(vf); i++ {
- if f := Acos(vf[i] / 10); !close(acos[i], f) {
- t.Errorf("Acos(%g) = %g, want %g\n", vf[i]/10, f, acos[i])
+ a := vf[i] / 10
+ if f := Acos(a); !close(acos[i], f) {
+ t.Errorf("Acos(%g) = %g, want %g\n", a, f, acos[i])
}
}
for i := 0; i < len(vfasinSC); i++ {
@@ -505,10 +728,25 @@
}
}
+func TestAcosh(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ a := 1 + Fabs(vf[i])
+ if f := Acosh(a); !veryclose(acosh[i], f) {
+ t.Errorf("Acosh(%g) = %g, want %g\n", a, f, acosh[i])
+ }
+ }
+ for i := 0; i < len(vfacoshSC); i++ {
+ if f := Acosh(vfacoshSC[i]); !alike(acoshSC[i], f) {
+ t.Errorf("Acosh(%g) = %g, want %g\n", vfacoshSC[i], f, acoshSC[i])
+ }
+ }
+}
+
func TestAsin(t *testing.T) {
for i := 0; i < len(vf); i++ {
- if f := Asin(vf[i] / 10); !veryclose(asin[i], f) {
- t.Errorf("Asin(%g) = %g, want %g\n", vf[i]/10, f, asin[i])
+ a := vf[i] / 10
+ if f := Asin(a); !veryclose(asin[i], f) {
+ t.Errorf("Asin(%g) = %g, want %g\n", a, f, asin[i])
}
}
for i := 0; i < len(vfasinSC); i++ {
@@ -518,6 +756,19 @@
}
}
+func TestAsinh(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ if f := Asinh(vf[i]); !veryclose(asinh[i], f) {
+ t.Errorf("Asinh(%g) = %g, want %g\n", vf[i], f, asinh[i])
+ }
+ }
+ for i := 0; i < len(vfasinhSC); i++ {
+ if f := Asinh(vfasinhSC[i]); !alike(asinhSC[i], f) {
+ t.Errorf("Asinh(%g) = %g, want %g\n", vfasinhSC[i], f, asinhSC[i])
+ }
+ }
+}
+
func TestAtan(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := Atan(vf[i]); !veryclose(atan[i], f) {
@@ -531,6 +782,20 @@
}
}
+func TestAtanh(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ a := vf[i] / 10
+ if f := Atanh(a); !veryclose(atanh[i], f) {
+ t.Errorf("Atanh(%g) = %g, want %g\n", a, f, atanh[i])
+ }
+ }
+ for i := 0; i < len(vfatanhSC); i++ {
+ if f := Atanh(vfatanhSC[i]); !alike(atanhSC[i], f) {
+ t.Errorf("Atanh(%g) = %g, want %g\n", vfatanhSC[i], f, atanhSC[i])
+ }
+ }
+}
+
func TestCeil(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := Ceil(vf[i]); ceil[i] != f {
@@ -544,6 +809,63 @@
}
}
+func TestCopysign(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ if f := Copysign(vf[i], -1); copysign[i] != f {
+ t.Errorf("Copysign(%g, -1) = %g, want %g\n", vf[i], f, copysign[i])
+ }
+ }
+ for i := 0; i < len(vfcopysignSC); i++ {
+ if f := Copysign(vfcopysignSC[i], -1); !alike(copysignSC[i], f) {
+ t.Errorf("Copysign(%g, -1) = %g, want %g\n", vfcopysignSC[i], f, copysignSC[i])
+ }
+ }
+}
+
+func TestCos(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ if f := Cos(vf[i]); !close(cos[i], f) {
+ t.Errorf("Cos(%g) = %g, want %g\n", vf[i], f, cos[i])
+ }
+ }
+}
+
+func TestCosh(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ if f := Cosh(vf[i]); !veryclose(cosh[i], f) {
+ t.Errorf("Cosh(%g) = %g, want %g\n", vf[i], f, cosh[i])
+ }
+ }
+}
+
+func TestErf(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ a := vf[i] / 10
+ if f := Erf(a); !veryclose(erf[i], f) {
+ t.Errorf("Erf(%g) = %g, want %g\n", a, f, erf[i])
+ }
+ }
+ for i := 0; i < len(vferfSC); i++ {
+ if f := Erf(vferfSC[i]); !alike(erfSC[i], f) {
+ t.Errorf("Erf(%g) = %g, want %g\n", vferfSC[i], f, erfSC[i])
+ }
+ }
+}
+
+func TestErfc(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ a := vf[i] / 10
+ if f := Erfc(a); !veryclose(erfc[i], f) {
+ t.Errorf("Erfc(%g) = %g, want %g\n", a, f, erfc[i])
+ }
+ }
+ for i := 0; i < len(vferfSC); i++ {
+ if f := Erfc(vferfSC[i]); !alike(erfcSC[i], f) {
+ t.Errorf("Erfc(%g) = %g, want %g\n", vferfSC[i], f, erfcSC[i])
+ }
+ }
+}
+
func TestExp(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := Exp(vf[i]); !close(exp[i], f) {
@@ -557,6 +879,20 @@
}
}
+func TestExpm1(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ a := vf[i] / 100
+ if f := Expm1(a); !veryclose(expm1[i], f) {
+ t.Errorf("Expm1(%.26fg) = %.26fg, want %.26fg\n", a, f, expm1[i])
+ }
+ }
+ for i := 0; i < len(vfexpSC); i++ {
+ if f := Expm1(vfexpSC[i]); !alike(expm1SC[i], f) {
+ t.Errorf("Expm1(%g) = %g, want %g\n", vfexpSC[i], f, expm1SC[i])
+ }
+ }
+}
+
func TestFloor(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := Floor(vf[i]); floor[i] != f {
@@ -572,8 +908,8 @@
func TestFmod(t *testing.T) {
for i := 0; i < len(vf); i++ {
- if f := Fmod(10, vf[i]); !close(fmod[i], f) {
- t.Errorf("Fmod(10, %g) = %g, want %g\n", vf[i], f, fmod[i])
+ if f := Fmod(10, vf[i]); fmod[i] != f { /*!close(fmod[i], f)*/
+ t.Errorf("Fmod(10, %g) = %g, want %g\n", vf[i], f, fmod[i])
}
}
for i := 0; i < len(vffmodSC); i++ {
@@ -631,6 +967,24 @@
}
}
+func TestLog1p(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ a := vf[i] / 100
+ if f := Log1p(a); !veryclose(log1p[i], f) {
+ t.Errorf("Log1p(%g) = %g, want %g\n", a, f, log1p[i])
+ }
+ }
+ a := float64(9)
+ if f := Log1p(a); f != Ln10 {
+ t.Errorf("Log1p(%g) = %g, want %g\n", a, f, Ln10)
+ }
+ for i := 0; i < len(vflogSC); i++ {
+ if f := Log1p(vflog1pSC[i]); !alike(log1pSC[i], f) {
+ t.Errorf("Log1p(%g) = %g, want %g\n", vflog1pSC[i], f, log1pSC[i])
+ }
+ }
+}
+
func TestPow(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := Pow(10, vf[i]); !close(pow[i], f) {
@@ -694,6 +1048,19 @@
}
}
+func TestTrunc(t *testing.T) {
+ for i := 0; i < len(vf); i++ {
+ if f := Trunc(vf[i]); trunc[i] != f {
+ t.Errorf("Trunc(%g) = %g, want %g\n", vf[i], f, trunc[i])
+ }
+ }
+ for i := 0; i < len(vfceilSC); i++ {
+ if f := Trunc(vfceilSC[i]); !alike(ceilSC[i], f) {
+ t.Errorf("Trunc(%g) = %g, want %g\n", vfceilSC[i], f, ceilSC[i])
+ }
+ }
+}
+
// Check that math functions of high angle values
// return similar results to low angle values
func TestLargeSin(t *testing.T) {
@@ -718,7 +1085,6 @@
}
}
-
func TestLargeTan(t *testing.T) {
large := float64(100000 * Pi)
for i := 0; i < len(vf); i++ {
@@ -758,9 +1124,15 @@
// Benchmarks
-func BenchmarkAtan(b *testing.B) {
+func BenchmarkAcos(b *testing.B) {
for i := 0; i < b.N; i++ {
- Atan(.5)
+ Acos(.5)
+ }
+}
+
+func BenchmarkAcosh(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Acosh(.5)
}
}
@@ -770,9 +1142,105 @@
}
}
-func BenchmarkAcos(b *testing.B) {
+func BenchmarkAsinh(b *testing.B) {
for i := 0; i < b.N; i++ {
- Acos(.5)
+ Asinh(.5)
+ }
+}
+
+func BenchmarkAtan(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Atan(.5)
+ }
+}
+
+func BenchmarkAtanh(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Atanh(.5)
+ }
+}
+
+func BenchmarkCeil(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Ceil(.5)
+ }
+}
+
+func BenchmarkCopysign(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Copysign(.5, -1)
+ }
+}
+
+func BenchmarkCos(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Cos(.5)
+ }
+}
+
+func BenchmarkCosh(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Cosh(2.5)
+ }
+}
+
+func BenchmarkErf(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Erf(.5)
+ }
+}
+
+func BenchmarkErfc(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Erfc(.5)
+ }
+}
+
+func BenchmarkExp(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Exp(.5)
+ }
+}
+
+func BenchmarkExpm1(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Expm1(.5)
+ }
+}
+
+func BenchmarkFloor(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Floor(.5)
+ }
+}
+
+func BenchmarkFmod(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Fmod(10, 3)
+ }
+}
+
+func BenchmarkHypot(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Hypot(3, 4)
+ }
+}
+
+func BenchmarkLog(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Log(.5)
+ }
+}
+
+func BenchmarkLog10(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Log10(.5)
+ }
+}
+
+func BenchmarkLog1p(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Log1p(.5)
}
}
@@ -788,8 +1256,43 @@
}
}
+func BenchmarkSin(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Sin(.5)
+ }
+}
+
+func BenchmarkSinh(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Sinh(2.5)
+ }
+}
+
func BenchmarkSqrt(b *testing.B) {
for i := 0; i < b.N; i++ {
Sqrt(10)
}
}
+
+func BenchmarkSqrtGo(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ SqrtGo(10)
+ }
+}
+
+func BenchmarkTan(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Tan(.5)
+ }
+}
+
+func BenchmarkTanh(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Tanh(2.5)
+ }
+}
+func BenchmarkTrunc(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Trunc(.5)
+ }
+}