gitee.com/quant1x/num@v0.3.2/math32/all_test.go (about) 1 // Copyright 2009 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 package math32_test 6 7 import ( 8 "fmt" 9 "testing" 10 11 . "gitee.com/quant1x/num/math32" 12 ) 13 14 var vf = []float32{ 15 4.9790119248836735e+00, 16 7.7388724745781045e+00, 17 -2.7688005719200159e-01, 18 -5.0106036182710749e+00, 19 9.6362937071984173e+00, 20 2.9263772392439646e+00, 21 5.2290834314593066e+00, 22 2.7279399104360102e+00, 23 1.8253080916808550e+00, 24 -8.6859247685756013e+00, 25 } 26 27 // The expected results below were computed by the high precision calculators 28 // at http://keisan.casio.com/. More exact input values (array vf[], above) 29 // were obtained by printing them with "%.26f". The answers were calculated 30 // to 26 digits (by using the "Digit number" drop-down control of each 31 // calculator). 32 var acos = []float32{ 33 1.0496193546107222142571536e+00, 34 6.8584012813664425171660692e-01, 35 1.5984878714577160325521819e+00, 36 2.0956199361475859327461799e+00, 37 2.7053008467824138592616927e-01, 38 1.2738121680361776018155625e+00, 39 1.0205369421140629186287407e+00, 40 1.2945003481781246062157835e+00, 41 1.3872364345374451433846657e+00, 42 2.6231510803970463967294145e+00, 43 } 44 var acosh = []float32{ 45 2.4743347004159012494457618e+00, 46 2.8576385344292769649802701e+00, 47 7.2796961502981066190593175e-01, 48 2.4796794418831451156471977e+00, 49 3.0552020742306061857212962e+00, 50 2.044238592688586588942468e+00, 51 2.5158701513104513595766636e+00, 52 1.99050839282411638174299e+00, 53 1.6988625798424034227205445e+00, 54 2.9611454842470387925531875e+00, 55 } 56 var asin = []float32{ 57 5.2117697218417440497416805e-01, 58 8.8495619865825236751471477e-01, 59 -02.769154466281941332086016e-02, 60 -5.2482360935268931351485822e-01, 61 1.3002662421166552333051524e+00, 62 2.9698415875871901741575922e-01, 63 5.5025938468083370060258102e-01, 64 2.7629597861677201301553823e-01, 65 1.83559892257451475846656e-01, 66 -1.0523547536021497774980928e+00, 67 } 68 var asinh = []float32{ 69 2.3083139124923523427628243e+00, 70 2.743551594301593620039021e+00, 71 -2.7345908534880091229413487e-01, 72 -2.3145157644718338650499085e+00, 73 2.9613652154015058521951083e+00, 74 1.7949041616585821933067568e+00, 75 2.3564032905983506405561554e+00, 76 1.7287118790768438878045346e+00, 77 1.3626658083714826013073193e+00, 78 -2.8581483626513914445234004e+00, 79 } 80 var atan = []float32{ 81 1.372590262129621651920085e+00, 82 1.442290609645298083020664e+00, 83 -2.7011324359471758245192595e-01, 84 -1.3738077684543379452781531e+00, 85 1.4673921193587666049154681e+00, 86 1.2415173565870168649117764e+00, 87 1.3818396865615168979966498e+00, 88 1.2194305844639670701091426e+00, 89 1.0696031952318783760193244e+00, 90 -1.4561721938838084990898679e+00, 91 } 92 var atanh = []float32{ 93 5.4651163712251938116878204e-01, 94 1.0299474112843111224914709e+00, 95 -2.7695084420740135145234906e-02, 96 -5.5072096119207195480202529e-01, 97 1.9943940993171843235906642e+00, 98 3.01448604578089708203017e-01, 99 5.8033427206942188834370595e-01, 100 2.7987997499441511013958297e-01, 101 1.8459947964298794318714228e-01, 102 -1.3273186910532645867272502e+00, 103 } 104 var atan2 = []float32{ 105 1.1088291730037004444527075e+00, 106 9.1218183188715804018797795e-01, 107 1.5984772603216203736068915e+00, 108 2.0352918654092086637227327e+00, 109 8.0391819139044720267356014e-01, 110 1.2861075249894661588866752e+00, 111 1.0889904479131695712182587e+00, 112 1.3044821793397925293797357e+00, 113 1.3902530903455392306872261e+00, 114 2.2859857424479142655411058e+00, 115 } 116 var cbrt = []float32{ 117 1.7075799841925094446722675e+00, 118 1.9779982212970353936691498e+00, 119 -6.5177429017779910853339447e-01, 120 -1.7111838886544019873338113e+00, 121 2.1279920909827937423960472e+00, 122 1.4303536770460741452312367e+00, 123 1.7357021059106154902341052e+00, 124 1.3972633462554328350552916e+00, 125 1.2221149580905388454977636e+00, 126 -2.0556003730500069110343596e+00, 127 } 128 var ceil = []float32{ 129 5.0000000000000000e+00, 130 8.0000000000000000e+00, 131 0.0000000000000000e+00, 132 -5.0000000000000000e+00, 133 1.0000000000000000e+01, 134 3.0000000000000000e+00, 135 6.0000000000000000e+00, 136 3.0000000000000000e+00, 137 2.0000000000000000e+00, 138 -8.0000000000000000e+00, 139 } 140 var copysign = []float32{ 141 -4.9790119248836735e+00, 142 -7.7388724745781045e+00, 143 -2.7688005719200159e-01, 144 -5.0106036182710749e+00, 145 -9.6362937071984173e+00, 146 -2.9263772392439646e+00, 147 -5.2290834314593066e+00, 148 -2.7279399104360102e+00, 149 -1.8253080916808550e+00, 150 -8.6859247685756013e+00, 151 } 152 var cos = []float32{ 153 2.634752140995199110787593e-01, 154 0.114854835, //1.148551260848219865642039e-01, 155 9.6191297325640768154550453e-01, 156 0.2938137, //2.938141150061714816890637e-01, 157 -9.777138189897924126294461e-01, 158 -9.7693041344303219127199518e-01, 159 4.940088096948647263961162e-01, 160 -9.1565869021018925545016502e-01, 161 -2.517729313893103197176091e-01, 162 -7.39241351595676573201918e-01, 163 } 164 165 // Results for 100000 * Pi + vf[i] 166 var cosLarge = []float32{ 167 2.634752141185559426744e-01, 168 1.14855126055543100712e-01, 169 9.61912973266488928113e-01, 170 2.9381411499556122552e-01, 171 -9.777138189880161924641e-01, 172 -9.76930413445147608049e-01, 173 4.940088097314976789841e-01, 174 -9.15658690217517835002e-01, 175 -2.51772931436786954751e-01, 176 -7.3924135157173099849e-01, 177 } 178 var cosh = []float32{ 179 7.2668796942212842775517446e+01, 180 1.1479413465659254502011135e+03, 181 1.0385767908766418550935495e+00, 182 7.5000957789658051428857788e+01, 183 7.655246669605357888468613e+03, 184 9.3567491758321272072888257e+00, 185 9.331351599270605471131735e+01, 186 7.6833430994624643209296404e+00, 187 3.1829371625150718153881164e+00, 188 2.9595059261916188501640911e+03, 189 } 190 var erf = []float32{ 191 5.1865354817738701906913566e-01, 192 7.2623875834137295116929844e-01, 193 -3.123458688281309990629839e-02, 194 -5.2143121110253302920437013e-01, 195 8.2704742671312902508629582e-01, 196 3.2101767558376376743993945e-01, 197 5.403990312223245516066252e-01, 198 3.0034702916738588551174831e-01, 199 2.0369924417882241241559589e-01, 200 -7.8069386968009226729944677e-01, 201 } 202 var erfc = []float32{ 203 4.8134645182261298093086434e-01, 204 2.7376124165862704883070156e-01, 205 1.0312345868828130999062984e+00, 206 1.5214312111025330292043701e+00, 207 1.7295257328687097491370418e-01, 208 6.7898232441623623256006055e-01, 209 4.596009687776754483933748e-01, 210 6.9965297083261411448825169e-01, 211 7.9630075582117758758440411e-01, 212 1.7806938696800922672994468e+00, 213 } 214 var exp = []float32{ 215 1.4533071302642137507696589e+02, 216 2.2958822575694449002537581e+03, 217 7.5814542574851666582042306e-01, 218 6.6668778421791005061482264e-03, 219 1.5310493273896033740861206e+04, 220 1.8659907517999328638667732e+01, 221 1.8662167355098714543942057e+02, 222 1.5301332413189378961665788e+01, 223 6.2047063430646876349125085e+00, 224 1.6894712385826521111610438e-04, 225 } 226 var expm1 = []float32{ 227 5.105047796122957327384770212e-02, 228 8.046199708567344080562675439e-02, 229 -2.764970978891639815187418703e-03, 230 -4.8871434888875355394330300273e-02, 231 1.0115864277221467777117227494e-01, 232 2.969616407795910726014621657e-02, 233 5.368214487944892300914037972e-02, 234 2.765488851131274068067445335e-02, 235 1.842068661871398836913874273e-02, 236 -8.3193870863553801814961137573e-02, 237 } 238 var expm1Large = []float32{ 239 4.2031418113550844e+21, 240 4.0690789717473863e+33, 241 -0.9372627915981363e+00, 242 -1.0, 243 Inf(1), // NOTE: this was changed to fit float32 244 5.117936223839153e+12, 245 5.124137759001189e+22, 246 7.03546003972584e+11, 247 8.456921800389698e+07, 248 -1.0, 249 } 250 var exp2 = []float32{ 251 3.1537839463286288034313104e+01, 252 2.1361549283756232296144849e+02, 253 8.2537402562185562902577219e-01, 254 3.1021158628740294833424229e-02, 255 7.9581744110252191462569661e+02, 256 7.6019905892596359262696423e+00, 257 3.7506882048388096973183084e+01, 258 6.6250893439173561733216375e+00, 259 3.5438267900243941544605339e+00, 260 2.4281533133513300984289196e-03, 261 } 262 var fabs = []float32{ 263 4.9790119248836735e+00, 264 7.7388724745781045e+00, 265 2.7688005719200159e-01, 266 5.0106036182710749e+00, 267 9.6362937071984173e+00, 268 2.9263772392439646e+00, 269 5.2290834314593066e+00, 270 2.7279399104360102e+00, 271 1.8253080916808550e+00, 272 8.6859247685756013e+00, 273 } 274 var fdim = []float32{ 275 4.9790119248836735e+00, 276 7.7388724745781045e+00, 277 0.0000000000000000e+00, 278 0.0000000000000000e+00, 279 9.6362937071984173e+00, 280 2.9263772392439646e+00, 281 5.2290834314593066e+00, 282 2.7279399104360102e+00, 283 1.8253080916808550e+00, 284 0.0000000000000000e+00, 285 } 286 var floor = []float32{ 287 4.0000000000000000e+00, 288 7.0000000000000000e+00, 289 -1.0000000000000000e+00, 290 -6.0000000000000000e+00, 291 9.0000000000000000e+00, 292 2.0000000000000000e+00, 293 5.0000000000000000e+00, 294 2.0000000000000000e+00, 295 1.0000000000000000e+00, 296 -9.0000000000000000e+00, 297 } 298 var fmod = []float32{ 299 4.197615023265299782906368e-02, 300 2.261127525421895434476482e+00, 301 3.231794108794261433104108e-02, 302 4.989396381728925078391512e+00, 303 3.637062928015826201999516e-01, 304 1.220868282268106064236690e+00, 305 4.770916568540693347699744e+00, 306 1.816180268691969246219742e+00, 307 8.734595415957246977711748e-01, 308 1.314075231424398637614104e+00, 309 } 310 311 type fi struct { 312 f float32 313 i int 314 } 315 316 var frexp = []fi{ 317 {6.2237649061045918750e-01, 3}, 318 {9.6735905932226306250e-01, 3}, 319 {-5.5376011438400318000e-01, -1}, 320 {-6.2632545228388436250e-01, 3}, 321 {6.02268356699901081250e-01, 4}, 322 {7.3159430981099115000e-01, 2}, 323 {6.5363542893241332500e-01, 3}, 324 {6.8198497760900255000e-01, 2}, 325 {9.1265404584042750000e-01, 1}, 326 {-5.4287029803597508250e-01, 4}, 327 } 328 var gamma = []float32{ 329 2.3254348370739963835386613898e+01, 330 2.991153837155317076427529816e+03, 331 -4.561154336726758060575129109e+00, 332 7.719403468842639065959210984e-01, 333 1.6111876618855418534325755566e+05, 334 1.8706575145216421164173224946e+00, 335 3.4082787447257502836734201635e+01, 336 1.579733951448952054898583387e+00, 337 9.3834586598354592860187267089e-01, 338 -2.093995902923148389186189429e-05, 339 } 340 var j0 = []float32{ 341 -1.8444682230601672018219338e-01, 342 2.27353668906331975435892e-01, 343 9.809259936157051116270273e-01, 344 -1.741170131426226587841181e-01, 345 -2.1389448451144143352039069e-01, 346 -2.340905848928038763337414e-01, 347 -1.0029099691890912094586326e-01, 348 -1.5466726714884328135358907e-01, 349 3.252650187653420388714693e-01, 350 -8.72218484409407250005360235e-03, 351 } 352 var j1 = []float32{ 353 -3.251526395295203422162967e-01, 354 1.893581711430515718062564e-01, 355 -1.3711761352467242914491514e-01, 356 3.287486536269617297529617e-01, 357 1.3133899188830978473849215e-01, 358 3.660243417832986825301766e-01, 359 -3.4436769271848174665420672e-01, 360 4.329481396640773768835036e-01, 361 5.8181350531954794639333955e-01, 362 -2.7030574577733036112996607e-01, 363 } 364 var j2 = []float32{ 365 5.3837518920137802565192769e-02, 366 -1.7841678003393207281244667e-01, 367 9.521746934916464142495821e-03, 368 4.28958355470987397983072e-02, 369 2.4115371837854494725492872e-01, 370 4.842458532394520316844449e-01, 371 -3.142145220618633390125946e-02, 372 4.720849184745124761189957e-01, 373 3.122312022520957042957497e-01, 374 7.096213118930231185707277e-02, 375 } 376 var jM3 = []float32{ 377 -3.684042080996403091021151e-01, 378 2.8157665936340887268092661e-01, 379 4.401005480841948348343589e-04, 380 3.629926999056814081597135e-01, 381 3.123672198825455192489266e-02, 382 -2.958805510589623607540455e-01, 383 -3.2033177696533233403289416e-01, 384 -2.592737332129663376736604e-01, 385 -1.0241334641061485092351251e-01, 386 -2.3762660886100206491674503e-01, 387 } 388 var lgamma = []fi{ 389 {3.146492141244545774319734e+00, 1}, 390 {8.003414490659126375852113e+00, 1}, 391 {1.517575735509779707488106e+00, -1}, 392 {-2.588480028182145853558748e-01, 1}, 393 {1.1989897050205555002007985e+01, 1}, 394 {6.262899811091257519386906e-01, 1}, 395 {3.5287924899091566764846037e+00, 1}, 396 {4.5725644770161182299423372e-01, 1}, 397 {-6.363667087767961257654854e-02, 1}, 398 {-1.077385130910300066425564e+01, -1}, 399 } 400 var log = []float32{ 401 1.605231462693062999102599e+00, 402 2.0462560018708770653153909e+00, 403 -1.2841708730962657801275038e+00, 404 1.6115563905281545116286206e+00, 405 2.2655365644872016636317461e+00, 406 1.0737652208918379856272735e+00, 407 1.6542360106073546632707956e+00, 408 1.0035467127723465801264487e+00, 409 6.0174879014578057187016475e-01, 410 2.161703872847352815363655e+00, 411 } 412 var logb = []float32{ 413 2.0000000000000000e+00, 414 2.0000000000000000e+00, 415 -2.0000000000000000e+00, 416 2.0000000000000000e+00, 417 3.0000000000000000e+00, 418 1.0000000000000000e+00, 419 2.0000000000000000e+00, 420 1.0000000000000000e+00, 421 0.0000000000000000e+00, 422 3.0000000000000000e+00, 423 } 424 var log10 = []float32{ 425 6.9714316642508290997617083e-01, 426 8.886776901739320576279124e-01, 427 -5.5770832400658929815908236e-01, 428 6.998900476822994346229723e-01, 429 9.8391002850684232013281033e-01, 430 4.6633031029295153334285302e-01, 431 7.1842557117242328821552533e-01, 432 4.3583479968917773161304553e-01, 433 2.6133617905227038228626834e-01, 434 9.3881606348649405716214241e-01, 435 } 436 var log1p = []float32{ 437 4.8590257759797794104158205e-02, 438 7.4540265965225865330849141e-02, 439 -2.7726407903942672823234024e-03, 440 -5.1404917651627649094953380e-02, 441 9.1998280672258624681335010e-02, 442 2.8843762576593352865894824e-02, 443 5.0969534581863707268992645e-02, 444 2.6913947602193238458458594e-02, 445 1.8088493239630770262045333e-02, 446 -9.0865245631588989681559268e-02, 447 } 448 var log2 = []float32{ 449 2.3158594707062190618898251e+00, 450 2.9521233862883917703341018e+00, 451 -1.8526669502700329984917062e+00, 452 2.3249844127278861543568029e+00, 453 3.268478366538305087466309e+00, 454 1.5491157592596970278166492e+00, 455 2.3865580889631732407886495e+00, 456 1.447811865817085365540347e+00, 457 8.6813999540425116282815557e-01, 458 3.118679457227342224364709e+00, 459 } 460 var modf = [][2]float32{ 461 {4.0000000000000000e+00, 9.7901192488367350108546816e-01}, 462 {7.0000000000000000e+00, 7.3887247457810456552351752e-01}, 463 {Copysign(0, -1), -2.7688005719200159404635997e-01}, 464 {-5.0000000000000000e+00, -1.060361827107492160848778e-02}, 465 {9.0000000000000000e+00, 6.3629370719841737980004837e-01}, 466 {2.0000000000000000e+00, 9.2637723924396464525443662e-01}, 467 {5.0000000000000000e+00, 2.2908343145930665230025625e-01}, 468 {2.0000000000000000e+00, 7.2793991043601025126008608e-01}, 469 {1.0000000000000000e+00, 8.2530809168085506044576505e-01}, 470 {-8.0000000000000000e+00, -6.8592476857560136238589621e-01}, 471 } 472 var nextafter32 = []float32{ 473 4.979012489318848e+00, 474 7.738873004913330e+00, 475 -2.768800258636475e-01, 476 -5.010602951049805e+00, 477 9.636294364929199e+00, 478 2.926377534866333e+00, 479 5.229084014892578e+00, 480 2.727940082550049e+00, 481 1.825308203697205e+00, 482 -8.685923576354980e+00, 483 } 484 485 var pow = []float32{ 486 9.5282232631648411840742957e+04, 487 5.4811599352999901232411871e+07, 488 5.2859121715894396531132279e-01, 489 9.7587991957286474464259698e-06, 490 4.328064329346044846740467e+09, 491 8.4406761805034547437659092e+02, 492 1.6946633276191194947742146e+05, 493 5.3449040147551939075312879e+02, 494 6.688182138451414936380374e+01, 495 2.0609869004248742886827439e-09, 496 } 497 var remainder = []float32{ 498 4.197615023265299782906368e-02, 499 2.261127525421895434476482e+00, 500 3.231794108794261433104108e-02, 501 -2.120723654214984321697556e-02, 502 3.637062928015826201999516e-01, 503 1.220868282268106064236690e+00, 504 -4.581668629186133046005125e-01, 505 -9.117596417440410050403443e-01, 506 8.734595415957246977711748e-01, 507 1.314075231424398637614104e+00, 508 } 509 var signbit = []bool{ 510 false, 511 false, 512 true, 513 true, 514 false, 515 false, 516 false, 517 false, 518 false, 519 true, 520 } 521 var sin = []float32{ 522 -9.6466616586009283766724726e-01, 523 9.9338225271646545763467022e-01, 524 -2.7335587039794393342449301e-01, 525 9.5586257685042792878173752e-01, 526 -2.099421066779969164496634e-01, 527 2.135578780799860532750616e-01, 528 -8.694568971167362743327708e-01, 529 4.019566681155577786649878e-01, 530 9.6778633541687993721617774e-01, 531 -6.734405869050344734943028e-01, 532 } 533 534 // Results for 100000 * Pi + vf[i] 535 var sinLarge = []float32{ 536 -9.646661658548936063912e-01, 537 9.933822527198506903752e-01, 538 -2.7335587036246899796e-01, 539 9.55862576853689321268e-01, 540 -2.099421066862688873691e-01, 541 2.13557878070308981163e-01, 542 -8.694568970959221300497e-01, 543 4.01956668098863248917e-01, 544 9.67786335404528727927e-01, 545 -6.7344058693131973066e-01, 546 } 547 var sinh = []float32{ 548 7.2661916084208532301448439e+01, 549 1.1479409110035194500526446e+03, 550 -2.8043136512812518927312641e-01, 551 -7.499429091181587232835164e+01, 552 7.6552466042906758523925934e+03, 553 9.3031583421672014313789064e+00, 554 9.330815755828109072810322e+01, 555 7.6179893137269146407361477e+00, 556 3.021769180549615819524392e+00, 557 -2.95950575724449499189888e+03, 558 } 559 var sqrt = []float32{ 560 2.2313699659365484748756904e+00, 561 2.7818829009464263511285458e+00, 562 5.2619393496314796848143251e-01, 563 2.2384377628763938724244104e+00, 564 3.1042380236055381099288487e+00, 565 1.7106657298385224403917771e+00, 566 2.286718922705479046148059e+00, 567 1.6516476350711159636222979e+00, 568 1.3510396336454586262419247e+00, 569 2.9471892997524949215723329e+00, 570 } 571 var tan = []float32{ 572 -3.661316565040227801781974e+00, 573 8.64900232648597589369854e+00, 574 -2.8417941955033612725238097e-01, 575 3.253290185974728640827156e+00, 576 2.147275640380293804770778e-01, 577 -2.18600910711067004921551e-01, 578 -1.760002817872367935518928e+00, 579 -4.389808914752818126249079e-01, 580 -3.843885560201130679995041e+00, 581 9.10988793377685105753416e-01, 582 } 583 584 // Results for 100000 * Pi + vf[i] 585 var tanLarge = []float32{ 586 -3.66131656475596512705e+00, 587 8.6490023287202547927e+00, 588 -2.841794195104782406e-01, 589 3.2532901861033120983e+00, 590 2.14727564046880001365e-01, 591 -2.18600910700688062874e-01, 592 -1.760002817699722747043e+00, 593 -4.38980891453536115952e-01, 594 -3.84388555942723509071e+00, 595 9.1098879344275101051e-01, 596 } 597 var tanh = []float32{ 598 9.9990531206936338549262119e-01, 599 9.9999962057085294197613294e-01, 600 -2.7001505097318677233756845e-01, 601 -9.9991110943061718603541401e-01, 602 9.9999999146798465745022007e-01, 603 9.9427249436125236705001048e-01, 604 9.9994257600983138572705076e-01, 605 9.9149409509772875982054701e-01, 606 9.4936501296239685514466577e-01, 607 -9.9999994291374030946055701e-01, 608 } 609 var trunc = []float32{ 610 4.0000000000000000e+00, 611 7.0000000000000000e+00, 612 -0.0000000000000000e+00, 613 -5.0000000000000000e+00, 614 9.0000000000000000e+00, 615 2.0000000000000000e+00, 616 5.0000000000000000e+00, 617 2.0000000000000000e+00, 618 1.0000000000000000e+00, 619 -8.0000000000000000e+00, 620 } 621 var y0 = []float32{ 622 -3.053399153780788357534855e-01, 623 1.7437227649515231515503649e-01, 624 -8.6221781263678836910392572e-01, 625 -3.100664880987498407872839e-01, 626 1.422200649300982280645377e-01, 627 4.000004067997901144239363e-01, 628 -3.3340749753099352392332536e-01, 629 4.5399790746668954555205502e-01, 630 4.8290004112497761007536522e-01, 631 2.7036697826604756229601611e-01, 632 } 633 var y1 = []float32{ 634 0.15494213737457922210218611, 635 -0.2165955142081145245075746, 636 -2.4644949631241895201032829, 637 0.1442740489541836405154505, 638 0.2215379960518984777080163, 639 0.3038800915160754150565448, 640 0.0691107642452362383808547, 641 0.2380116417809914424860165, 642 -0.20849492979459761009678934, 643 0.0242503179793232308250804, 644 } 645 var y2 = []float32{ 646 0.3675780219390303613394936, 647 -0.23034826393250119879267257, 648 -16.939677983817727205631397, 649 0.367653980523052152867791, 650 -0.0962401471767804440353136, 651 -0.1923169356184851105200523, 652 0.35984072054267882391843766, 653 -0.2794987252299739821654982, 654 -0.7113490692587462579757954, 655 -0.2647831587821263302087457, 656 } 657 var yM3 = []float32{ 658 -0.14035984421094849100895341, 659 -0.097535139617792072703973, 660 242.25775994555580176377379, 661 -0.1492267014802818619511046, 662 0.26148702629155918694500469, 663 0.56675383593895176530394248, 664 -0.206150264009006981070575, 665 0.64784284687568332737963658, 666 1.3503631555901938037008443, 667 0.1461869756579956803341844, 668 } 669 670 // arguments and expected results for special cases 671 var vfacosSC = []float32{ 672 -Pi, 673 1, 674 Pi, 675 NaN(), 676 } 677 var acosSC = []float32{ 678 NaN(), 679 0, 680 NaN(), 681 NaN(), 682 } 683 684 var vfacoshSC = []float32{ 685 Inf(-1), 686 0.5, 687 1, 688 Inf(1), 689 NaN(), 690 } 691 var acoshSC = []float32{ 692 NaN(), 693 NaN(), 694 0, 695 Inf(1), 696 NaN(), 697 } 698 699 var vfasinSC = []float32{ 700 -Pi, 701 Copysign(0, -1), 702 0, 703 Pi, 704 NaN(), 705 } 706 var asinSC = []float32{ 707 NaN(), 708 Copysign(0, -1), 709 0, 710 NaN(), 711 NaN(), 712 } 713 714 var vfasinhSC = []float32{ 715 Inf(-1), 716 Copysign(0, -1), 717 0, 718 Inf(1), 719 NaN(), 720 } 721 var asinhSC = []float32{ 722 Inf(-1), 723 Copysign(0, -1), 724 0, 725 Inf(1), 726 NaN(), 727 } 728 729 var vfatanSC = []float32{ 730 Inf(-1), 731 Copysign(0, -1), 732 0, 733 Inf(1), 734 NaN(), 735 } 736 var atanSC = []float32{ 737 -Pi / 2, 738 Copysign(0, -1), 739 0, 740 Pi / 2, 741 NaN(), 742 } 743 744 var vfatanhSC = []float32{ 745 Inf(-1), 746 -Pi, 747 -1, 748 Copysign(0, -1), 749 0, 750 1, 751 Pi, 752 Inf(1), 753 NaN(), 754 } 755 var atanhSC = []float32{ 756 NaN(), 757 NaN(), 758 Inf(-1), 759 Copysign(0, -1), 760 0, 761 Inf(1), 762 NaN(), 763 NaN(), 764 NaN(), 765 } 766 var vfatan2SC = [][2]float32{ 767 {Inf(-1), Inf(-1)}, 768 {Inf(-1), -Pi}, 769 {Inf(-1), 0}, 770 {Inf(-1), +Pi}, 771 {Inf(-1), Inf(1)}, 772 {Inf(-1), NaN()}, 773 {-Pi, Inf(-1)}, 774 {-Pi, 0}, 775 {-Pi, Inf(1)}, 776 {-Pi, NaN()}, 777 {Copysign(0, -1), Inf(-1)}, 778 {Copysign(0, -1), -Pi}, 779 {Copysign(0, -1), Copysign(0, -1)}, 780 {Copysign(0, -1), 0}, 781 {Copysign(0, -1), +Pi}, 782 {Copysign(0, -1), Inf(1)}, 783 {Copysign(0, -1), NaN()}, 784 {0, Inf(-1)}, 785 {0, -Pi}, 786 {0, Copysign(0, -1)}, 787 {0, 0}, 788 {0, +Pi}, 789 {0, Inf(1)}, 790 {0, NaN()}, 791 {+Pi, Inf(-1)}, 792 {+Pi, 0}, 793 {+Pi, Inf(1)}, 794 {+Pi, NaN()}, 795 {Inf(1), Inf(-1)}, 796 {Inf(1), -Pi}, 797 {Inf(1), 0}, 798 {Inf(1), +Pi}, 799 {Inf(1), Inf(1)}, 800 {Inf(1), NaN()}, 801 {NaN(), NaN()}, 802 } 803 var atan2SC = []float32{ 804 -3 * Pi / 4, // atan2(-Inf, -Inf) 805 -Pi / 2, // atan2(-Inf, -Pi) 806 -Pi / 2, // atan2(-Inf, +0) 807 -Pi / 2, // atan2(-Inf, +Pi) 808 -Pi / 4, // atan2(-Inf, +Inf) 809 NaN(), // atan2(-Inf, NaN) 810 -Pi, // atan2(-Pi, -Inf) 811 -Pi / 2, // atan2(-Pi, +0) 812 Copysign(0, -1), // atan2(-Pi, Inf) 813 NaN(), // atan2(-Pi, NaN) 814 -Pi, // atan2(-0, -Inf) 815 -Pi, // atan2(-0, -Pi) 816 -Pi, // atan2(-0, -0) 817 Copysign(0, -1), // atan2(-0, +0) 818 Copysign(0, -1), // atan2(-0, +Pi) 819 Copysign(0, -1), // atan2(-0, +Inf) 820 NaN(), // atan2(-0, NaN) 821 Pi, // atan2(+0, -Inf) 822 Pi, // atan2(+0, -Pi) 823 Pi, // atan2(+0, -0) 824 0, // atan2(+0, +0) 825 0, // atan2(+0, +Pi) 826 0, // atan2(+0, +Inf) 827 NaN(), // atan2(+0, NaN) 828 Pi, // atan2(+Pi, -Inf) 829 Pi / 2, // atan2(+Pi, +0) 830 0, // atan2(+Pi, +Inf) 831 NaN(), // atan2(+Pi, NaN) 832 3 * Pi / 4, // atan2(+Inf, -Inf) 833 Pi / 2, // atan2(+Inf, -Pi) 834 Pi / 2, // atan2(+Inf, +0) 835 Pi / 2, // atan2(+Inf, +Pi) 836 Pi / 4, // atan2(+Inf, +Inf) 837 NaN(), // atan2(+Inf, NaN) 838 NaN(), // atan2(NaN, NaN) 839 } 840 841 var vfcbrtSC = []float32{ 842 Inf(-1), 843 Copysign(0, -1), 844 0, 845 Inf(1), 846 NaN(), 847 } 848 var cbrtSC = []float32{ 849 Inf(-1), 850 Copysign(0, -1), 851 0, 852 Inf(1), 853 NaN(), 854 } 855 856 var vfceilSC = []float32{ 857 Inf(-1), 858 Copysign(0, -1), 859 0, 860 Inf(1), 861 NaN(), 862 } 863 var ceilSC = []float32{ 864 Inf(-1), 865 Copysign(0, -1), 866 0, 867 Inf(1), 868 NaN(), 869 } 870 871 var vfcopysignSC = []float32{ 872 Inf(-1), 873 Inf(1), 874 NaN(), 875 } 876 var copysignSC = []float32{ 877 Inf(-1), 878 Inf(-1), 879 NaN(), 880 } 881 882 var vfcosSC = []float32{ 883 Inf(-1), 884 Inf(1), 885 NaN(), 886 } 887 var cosSC = []float32{ 888 NaN(), 889 NaN(), 890 NaN(), 891 } 892 893 var vfcoshSC = []float32{ 894 Inf(-1), 895 Copysign(0, -1), 896 0, 897 Inf(1), 898 NaN(), 899 } 900 var coshSC = []float32{ 901 Inf(1), 902 1, 903 1, 904 Inf(1), 905 NaN(), 906 } 907 908 var vferfSC = []float32{ 909 Inf(-1), 910 Copysign(0, -1), 911 0, 912 Inf(1), 913 NaN(), 914 } 915 var erfSC = []float32{ 916 -1, 917 Copysign(0, -1), 918 0, 919 1, 920 NaN(), 921 } 922 923 var vferfcSC = []float32{ 924 Inf(-1), 925 Inf(1), 926 NaN(), 927 } 928 var erfcSC = []float32{ 929 2, 930 0, 931 NaN(), 932 } 933 934 var vfexpSC = []float32{ 935 Inf(-1), 936 -2000, 937 2000, 938 Inf(1), 939 NaN(), 940 } 941 var expSC = []float32{ 942 0, 943 0, 944 Inf(1), 945 Inf(1), 946 NaN(), 947 } 948 949 var vfexpm1SC = []float32{ 950 Inf(-1), 951 -710, 952 Copysign(0, -1), 953 0, 954 710, 955 Inf(1), 956 NaN(), 957 } 958 var expm1SC = []float32{ 959 -1, 960 -1, 961 Copysign(0, -1), 962 0, 963 Inf(1), 964 Inf(1), 965 NaN(), 966 } 967 968 var vffabsSC = []float32{ 969 Inf(-1), 970 Copysign(0, -1), 971 0, 972 Inf(1), 973 NaN(), 974 } 975 var fabsSC = []float32{ 976 Inf(1), 977 0, 978 0, 979 Inf(1), 980 NaN(), 981 } 982 983 var vffdimSC = [][2]float32{ 984 {Inf(-1), Inf(-1)}, 985 {Inf(-1), Inf(1)}, 986 {Inf(-1), NaN()}, 987 {Copysign(0, -1), Copysign(0, -1)}, 988 {Copysign(0, -1), 0}, 989 {0, Copysign(0, -1)}, 990 {0, 0}, 991 {Inf(1), Inf(-1)}, 992 {Inf(1), Inf(1)}, 993 {Inf(1), NaN()}, 994 {NaN(), Inf(-1)}, 995 {NaN(), Copysign(0, -1)}, 996 {NaN(), 0}, 997 {NaN(), Inf(1)}, 998 {NaN(), NaN()}, 999 } 1000 var nan = Float32frombits(0x7FF80001) // SSE2 DIVSD 0/0 1001 var vffdim2SC = [][2]float32{ 1002 {Inf(-1), Inf(-1)}, 1003 {Inf(-1), Inf(1)}, 1004 {Inf(-1), nan}, 1005 {Copysign(0, -1), Copysign(0, -1)}, 1006 {Copysign(0, -1), 0}, 1007 {0, Copysign(0, -1)}, 1008 {0, 0}, 1009 {Inf(1), Inf(-1)}, 1010 {Inf(1), Inf(1)}, 1011 {Inf(1), nan}, 1012 {nan, Inf(-1)}, 1013 {nan, Copysign(0, -1)}, 1014 {nan, 0}, 1015 {nan, Inf(1)}, 1016 {nan, nan}, 1017 } 1018 var fdimSC = []float32{ 1019 NaN(), 1020 0, 1021 NaN(), 1022 0, 1023 0, 1024 0, 1025 0, 1026 Inf(1), 1027 NaN(), 1028 NaN(), 1029 NaN(), 1030 NaN(), 1031 NaN(), 1032 NaN(), 1033 NaN(), 1034 } 1035 var fmaxSC = []float32{ 1036 Inf(-1), 1037 Inf(1), 1038 NaN(), 1039 Copysign(0, -1), 1040 0, 1041 0, 1042 0, 1043 Inf(1), 1044 Inf(1), 1045 Inf(1), 1046 NaN(), 1047 NaN(), 1048 NaN(), 1049 Inf(1), 1050 NaN(), 1051 } 1052 var fminSC = []float32{ 1053 Inf(-1), 1054 Inf(-1), 1055 Inf(-1), 1056 Copysign(0, -1), 1057 Copysign(0, -1), 1058 Copysign(0, -1), 1059 0, 1060 Inf(-1), 1061 Inf(1), 1062 NaN(), 1063 Inf(-1), 1064 NaN(), 1065 NaN(), 1066 NaN(), 1067 NaN(), 1068 } 1069 1070 var vffmodSC = [][2]float32{ 1071 {Inf(-1), Inf(-1)}, 1072 {Inf(-1), -Pi}, 1073 {Inf(-1), 0}, 1074 {Inf(-1), Pi}, 1075 {Inf(-1), Inf(1)}, 1076 {Inf(-1), NaN()}, 1077 {-Pi, Inf(-1)}, 1078 {-Pi, 0}, 1079 {-Pi, Inf(1)}, 1080 {-Pi, NaN()}, 1081 {Copysign(0, -1), Inf(-1)}, 1082 {Copysign(0, -1), 0}, 1083 {Copysign(0, -1), Inf(1)}, 1084 {Copysign(0, -1), NaN()}, 1085 {0, Inf(-1)}, 1086 {0, 0}, 1087 {0, Inf(1)}, 1088 {0, NaN()}, 1089 {Pi, Inf(-1)}, 1090 {Pi, 0}, 1091 {Pi, Inf(1)}, 1092 {Pi, NaN()}, 1093 {Inf(1), Inf(-1)}, 1094 {Inf(1), -Pi}, 1095 {Inf(1), 0}, 1096 {Inf(1), Pi}, 1097 {Inf(1), Inf(1)}, 1098 {Inf(1), NaN()}, 1099 {NaN(), Inf(-1)}, 1100 {NaN(), -Pi}, 1101 {NaN(), 0}, 1102 {NaN(), Pi}, 1103 {NaN(), Inf(1)}, 1104 {NaN(), NaN()}, 1105 } 1106 var fmodSC = []float32{ 1107 NaN(), // fmod(-Inf, -Inf) 1108 NaN(), // fmod(-Inf, -Pi) 1109 NaN(), // fmod(-Inf, 0) 1110 NaN(), // fmod(-Inf, Pi) 1111 NaN(), // fmod(-Inf, +Inf) 1112 NaN(), // fmod(-Inf, NaN) 1113 -Pi, // fmod(-Pi, -Inf) 1114 NaN(), // fmod(-Pi, 0) 1115 -Pi, // fmod(-Pi, +Inf) 1116 NaN(), // fmod(-Pi, NaN) 1117 Copysign(0, -1), // fmod(-0, -Inf) 1118 NaN(), // fmod(-0, 0) 1119 Copysign(0, -1), // fmod(-0, Inf) 1120 NaN(), // fmod(-0, NaN) 1121 0, // fmod(0, -Inf) 1122 NaN(), // fmod(0, 0) 1123 0, // fmod(0, +Inf) 1124 NaN(), // fmod(0, NaN) 1125 Pi, // fmod(Pi, -Inf) 1126 NaN(), // fmod(Pi, 0) 1127 Pi, // fmod(Pi, +Inf) 1128 NaN(), // fmod(Pi, NaN) 1129 NaN(), // fmod(+Inf, -Inf) 1130 NaN(), // fmod(+Inf, -Pi) 1131 NaN(), // fmod(+Inf, 0) 1132 NaN(), // fmod(+Inf, Pi) 1133 NaN(), // fmod(+Inf, +Inf) 1134 NaN(), // fmod(+Inf, NaN) 1135 NaN(), // fmod(NaN, -Inf) 1136 NaN(), // fmod(NaN, -Pi) 1137 NaN(), // fmod(NaN, 0) 1138 NaN(), // fmod(NaN, Pi) 1139 NaN(), // fmod(NaN, +Inf) 1140 NaN(), // fmod(NaN, NaN) 1141 } 1142 1143 var vffrexpSC = []float32{ 1144 Inf(-1), 1145 Copysign(0, -1), 1146 0, 1147 Inf(1), 1148 NaN(), 1149 } 1150 var frexpSC = []fi{ 1151 {Inf(-1), 0}, 1152 {Copysign(0, -1), 0}, 1153 {0, 0}, 1154 {Inf(1), 0}, 1155 {NaN(), 0}, 1156 } 1157 1158 var vfgammaSC = []float32{ 1159 Inf(-1), 1160 -3, 1161 Copysign(0, -1), 1162 0, 1163 Inf(1), 1164 NaN(), 1165 } 1166 var gammaSC = []float32{ 1167 NaN(), 1168 NaN(), 1169 Inf(-1), 1170 Inf(1), 1171 Inf(1), 1172 NaN(), 1173 } 1174 1175 var vfhypotSC = [][2]float32{ 1176 {Inf(-1), Inf(-1)}, 1177 {Inf(-1), 0}, 1178 {Inf(-1), Inf(1)}, 1179 {Inf(-1), NaN()}, 1180 {Copysign(0, -1), Copysign(0, -1)}, 1181 {Copysign(0, -1), 0}, 1182 {0, Copysign(0, -1)}, 1183 {0, 0}, // +0, +0 1184 {0, Inf(-1)}, 1185 {0, Inf(1)}, 1186 {0, NaN()}, 1187 {Inf(1), Inf(-1)}, 1188 {Inf(1), 0}, 1189 {Inf(1), Inf(1)}, 1190 {Inf(1), NaN()}, 1191 {NaN(), Inf(-1)}, 1192 {NaN(), 0}, 1193 {NaN(), Inf(1)}, 1194 {NaN(), NaN()}, 1195 } 1196 var hypotSC = []float32{ 1197 Inf(1), 1198 Inf(1), 1199 Inf(1), 1200 Inf(1), 1201 0, 1202 0, 1203 0, 1204 0, 1205 Inf(1), 1206 Inf(1), 1207 NaN(), 1208 Inf(1), 1209 Inf(1), 1210 Inf(1), 1211 Inf(1), 1212 Inf(1), 1213 NaN(), 1214 Inf(1), 1215 NaN(), 1216 } 1217 1218 var ilogbSC = []int{ 1219 MaxInt32, 1220 MinInt32, 1221 MaxInt32, 1222 MaxInt32, 1223 } 1224 1225 var vfj0SC = []float32{ 1226 Inf(-1), 1227 0, 1228 Inf(1), 1229 NaN(), 1230 } 1231 var j0SC = []float32{ 1232 0, 1233 1, 1234 0, 1235 NaN(), 1236 } 1237 var j1SC = []float32{ 1238 0, 1239 0, 1240 0, 1241 NaN(), 1242 } 1243 var j2SC = []float32{ 1244 0, 1245 0, 1246 0, 1247 NaN(), 1248 } 1249 var jM3SC = []float32{ 1250 0, 1251 0, 1252 0, 1253 NaN(), 1254 } 1255 1256 var vfldexpSC = []fi{ 1257 {0, 0}, 1258 {0, -1075}, 1259 {0, 1024}, 1260 {Copysign(0, -1), 0}, 1261 {Copysign(0, -1), -1075}, 1262 {Copysign(0, -1), 1024}, 1263 {Inf(1), 0}, 1264 {Inf(1), -1024}, 1265 {Inf(-1), 0}, 1266 {Inf(-1), -1024}, 1267 {NaN(), -1024}, 1268 } 1269 var ldexpSC = []float32{ 1270 0, 1271 0, 1272 0, 1273 Copysign(0, -1), 1274 Copysign(0, -1), 1275 Copysign(0, -1), 1276 Inf(1), 1277 Inf(1), 1278 Inf(-1), 1279 Inf(-1), 1280 NaN(), 1281 } 1282 1283 var vflgammaSC = []float32{ 1284 Inf(-1), 1285 -3, 1286 0, 1287 1, 1288 2, 1289 Inf(1), 1290 NaN(), 1291 } 1292 var lgammaSC = []fi{ 1293 {Inf(-1), 1}, 1294 {Inf(1), 1}, 1295 {Inf(1), 1}, 1296 {0, 1}, 1297 {0, 1}, 1298 {Inf(1), 1}, 1299 {NaN(), 1}, 1300 } 1301 1302 var vflogSC = []float32{ 1303 Inf(-1), 1304 -Pi, 1305 Copysign(0, -1), 1306 0, 1307 1, 1308 Inf(1), 1309 NaN(), 1310 } 1311 var logSC = []float32{ 1312 NaN(), 1313 NaN(), 1314 Inf(-1), 1315 Inf(-1), 1316 0, 1317 Inf(1), 1318 NaN(), 1319 } 1320 1321 var vflogbSC = []float32{ 1322 Inf(-1), 1323 0, 1324 Inf(1), 1325 NaN(), 1326 } 1327 var logbSC = []float32{ 1328 Inf(1), 1329 Inf(-1), 1330 Inf(1), 1331 NaN(), 1332 } 1333 1334 var vflog1pSC = []float32{ 1335 Inf(-1), 1336 -Pi, 1337 -1, 1338 Copysign(0, -1), 1339 0, 1340 Inf(1), 1341 NaN(), 1342 } 1343 var log1pSC = []float32{ 1344 NaN(), 1345 NaN(), 1346 Inf(-1), 1347 Copysign(0, -1), 1348 0, 1349 Inf(1), 1350 NaN(), 1351 } 1352 1353 var vfmodfSC = []float32{ 1354 Inf(-1), 1355 Copysign(0, -1), 1356 Inf(1), 1357 NaN(), 1358 } 1359 var modfSC = [][2]float32{ 1360 {Inf(-1), NaN()}, // [2]float32{Copysign(0, -1), Inf(-1)}, 1361 {Copysign(0, -1), Copysign(0, -1)}, 1362 {Inf(1), NaN()}, // [2]float32{0, Inf(1)}, 1363 {NaN(), NaN()}, 1364 } 1365 1366 var vfnextafter32SC = [][2]float32{ 1367 {0, 0}, 1368 {0, float32(Copysign(0, -1))}, 1369 {0, -1}, 1370 {0, float32(NaN())}, 1371 {float32(Copysign(0, -1)), 1}, 1372 {float32(Copysign(0, -1)), 0}, 1373 {float32(Copysign(0, -1)), float32(Copysign(0, -1))}, 1374 {float32(Copysign(0, -1)), -1}, 1375 {float32(NaN()), 0}, 1376 {float32(NaN()), float32(NaN())}, 1377 } 1378 var nextafter32SC = []float32{ 1379 0, 1380 0, 1381 -1.401298464e-45, // Float32frombits(0x80000001) 1382 float32(NaN()), 1383 1.401298464e-45, // Float32frombits(0x00000001) 1384 float32(Copysign(0, -1)), 1385 float32(Copysign(0, -1)), 1386 -1.401298464e-45, // Float32frombits(0x80000001) 1387 float32(NaN()), 1388 float32(NaN()), 1389 } 1390 1391 var vfpowSC = [][2]float32{ 1392 {Inf(-1), -Pi}, 1393 {Inf(-1), -3}, 1394 {Inf(-1), Copysign(0, -1)}, 1395 {Inf(-1), 0}, 1396 {Inf(-1), 1}, 1397 {Inf(-1), 3}, 1398 {Inf(-1), Pi}, 1399 {Inf(-1), NaN()}, 1400 1401 {-Pi, Inf(-1)}, 1402 {-Pi, -Pi}, 1403 {-Pi, Copysign(0, -1)}, 1404 {-Pi, 0}, 1405 {-Pi, 1}, 1406 {-Pi, Pi}, 1407 {-Pi, Inf(1)}, 1408 {-Pi, NaN()}, 1409 1410 {-1, Inf(-1)}, 1411 {-1, Inf(1)}, 1412 {-1, NaN()}, 1413 {-1 / 2, Inf(-1)}, 1414 {-1 / 2, Inf(1)}, 1415 {Copysign(0, -1), Inf(-1)}, 1416 {Copysign(0, -1), -Pi}, 1417 {Copysign(0, -1), -3}, 1418 {Copysign(0, -1), 3}, 1419 {Copysign(0, -1), Pi}, 1420 {Copysign(0, -1), Inf(1)}, 1421 1422 {0, Inf(-1)}, 1423 {0, -Pi}, 1424 {0, -3}, 1425 {0, Copysign(0, -1)}, 1426 {0, 0}, 1427 {0, 3}, 1428 {0, Pi}, 1429 {0, Inf(1)}, 1430 {0, NaN()}, 1431 1432 {1 / 2, Inf(-1)}, 1433 {1 / 2, Inf(1)}, 1434 {1, Inf(-1)}, 1435 {1, Inf(1)}, 1436 {1, NaN()}, 1437 1438 {Pi, Inf(-1)}, 1439 {Pi, Copysign(0, -1)}, 1440 {Pi, 0}, 1441 {Pi, 1}, 1442 {Pi, Inf(1)}, 1443 {Pi, NaN()}, 1444 {Inf(1), -Pi}, 1445 {Inf(1), Copysign(0, -1)}, 1446 {Inf(1), 0}, 1447 {Inf(1), 1}, 1448 {Inf(1), Pi}, 1449 {Inf(1), NaN()}, 1450 {NaN(), -Pi}, 1451 {NaN(), Copysign(0, -1)}, 1452 {NaN(), 0}, 1453 {NaN(), 1}, 1454 {NaN(), Pi}, 1455 {NaN(), NaN()}, 1456 } 1457 var powSC = []float32{ 1458 0, // pow(-Inf, -Pi) 1459 Copysign(0, -1), // pow(-Inf, -3) 1460 1, // pow(-Inf, -0) 1461 1, // pow(-Inf, +0) 1462 Inf(-1), // pow(-Inf, 1) 1463 Inf(-1), // pow(-Inf, 3) 1464 Inf(1), // pow(-Inf, Pi) 1465 NaN(), // pow(-Inf, NaN) 1466 0, // pow(-Pi, -Inf) 1467 NaN(), // pow(-Pi, -Pi) 1468 1, // pow(-Pi, -0) 1469 1, // pow(-Pi, +0) 1470 -Pi, // pow(-Pi, 1) 1471 NaN(), // pow(-Pi, Pi) 1472 Inf(1), // pow(-Pi, +Inf) 1473 NaN(), // pow(-Pi, NaN) 1474 1, // pow(-1, -Inf) IEEE 754-2008 1475 1, // pow(-1, +Inf) IEEE 754-2008 1476 NaN(), // pow(-1, NaN) 1477 Inf(1), // pow(-1/2, -Inf) 1478 0, // pow(-1/2, +Inf) 1479 Inf(1), // pow(-0, -Inf) 1480 Inf(1), // pow(-0, -Pi) 1481 Inf(-1), // pow(-0, -3) IEEE 754-2008 1482 Copysign(0, -1), // pow(-0, 3) IEEE 754-2008 1483 0, // pow(-0, +Pi) 1484 0, // pow(-0, +Inf) 1485 Inf(1), // pow(+0, -Inf) 1486 Inf(1), // pow(+0, -Pi) 1487 Inf(1), // pow(+0, -3) 1488 1, // pow(+0, -0) 1489 1, // pow(+0, +0) 1490 0, // pow(+0, 3) 1491 0, // pow(+0, +Pi) 1492 0, // pow(+0, +Inf) 1493 NaN(), // pow(+0, NaN) 1494 Inf(1), // pow(1/2, -Inf) 1495 0, // pow(1/2, +Inf) 1496 1, // pow(1, -Inf) IEEE 754-2008 1497 1, // pow(1, +Inf) IEEE 754-2008 1498 1, // pow(1, NaN) IEEE 754-2008 1499 0, // pow(+Pi, -Inf) 1500 1, // pow(+Pi, -0) 1501 1, // pow(+Pi, +0) 1502 Pi, // pow(+Pi, 1) 1503 Inf(1), // pow(+Pi, +Inf) 1504 NaN(), // pow(+Pi, NaN) 1505 0, // pow(+Inf, -Pi) 1506 1, // pow(+Inf, -0) 1507 1, // pow(+Inf, +0) 1508 Inf(1), // pow(+Inf, 1) 1509 Inf(1), // pow(+Inf, Pi) 1510 NaN(), // pow(+Inf, NaN) 1511 NaN(), // pow(NaN, -Pi) 1512 1, // pow(NaN, -0) 1513 1, // pow(NaN, +0) 1514 NaN(), // pow(NaN, 1) 1515 NaN(), // pow(NaN, +Pi) 1516 NaN(), // pow(NaN, NaN) 1517 } 1518 1519 var vfpow10SC = []int{ 1520 MinInt32, 1521 MaxInt32, 1522 -325, 1523 309, 1524 } 1525 1526 var pow10SC = []float32{ 1527 0, // pow10(MinInt32) 1528 Inf(1), // pow10(MaxInt32) 1529 0, // pow10(-325) 1530 Inf(1), // pow10(309) 1531 } 1532 1533 var vfsignbitSC = []float32{ 1534 Inf(-1), 1535 Copysign(0, -1), 1536 0, 1537 Inf(1), 1538 NaN(), 1539 } 1540 var signbitSC = []bool{ 1541 true, 1542 true, 1543 false, 1544 false, 1545 false, 1546 } 1547 1548 var vfsinSC = []float32{ 1549 Inf(-1), 1550 Copysign(0, -1), 1551 0, 1552 Inf(1), 1553 NaN(), 1554 } 1555 var sinSC = []float32{ 1556 NaN(), 1557 Copysign(0, -1), 1558 0, 1559 NaN(), 1560 NaN(), 1561 } 1562 1563 var vfsinhSC = []float32{ 1564 Inf(-1), 1565 Copysign(0, -1), 1566 0, 1567 Inf(1), 1568 NaN(), 1569 } 1570 var sinhSC = []float32{ 1571 Inf(-1), 1572 Copysign(0, -1), 1573 0, 1574 Inf(1), 1575 NaN(), 1576 } 1577 1578 var vfsqrtSC = []float32{ 1579 Inf(-1), 1580 -Pi, 1581 Copysign(0, -1), 1582 0, 1583 Inf(1), 1584 NaN(), 1585 Float32frombits(2), // subnormal; see https://golang.org/issue/13013 1586 } 1587 var sqrtSC = []float32{ 1588 NaN(), 1589 NaN(), 1590 Copysign(0, -1), 1591 0, 1592 Inf(1), 1593 NaN(), 1594 5.293956e-23, //3.1434555694052576e-162, 1595 } 1596 1597 var vftanhSC = []float32{ 1598 Inf(-1), 1599 Copysign(0, -1), 1600 0, 1601 Inf(1), 1602 NaN(), 1603 } 1604 var tanhSC = []float32{ 1605 -1, 1606 Copysign(0, -1), 1607 0, 1608 1, 1609 NaN(), 1610 } 1611 1612 var vfy0SC = []float32{ 1613 Inf(-1), 1614 0, 1615 Inf(1), 1616 NaN(), 1617 } 1618 var y0SC = []float32{ 1619 NaN(), 1620 Inf(-1), 1621 0, 1622 NaN(), 1623 } 1624 var y1SC = []float32{ 1625 NaN(), 1626 Inf(-1), 1627 0, 1628 NaN(), 1629 } 1630 var y2SC = []float32{ 1631 NaN(), 1632 Inf(-1), 1633 0, 1634 NaN(), 1635 } 1636 var yM3SC = []float32{ 1637 NaN(), 1638 Inf(1), 1639 0, 1640 NaN(), 1641 } 1642 1643 // arguments and expected results for boundary cases 1644 const ( 1645 SmallestNormalFloat32 = 1.1754943508222875079687365e-38 // 1/(2**(127-1)) 1646 LargestSubnormalFloat32 = SmallestNormalFloat32 - SmallestNonzeroFloat32 1647 ) 1648 1649 var vffrexpBC = []float32{ 1650 SmallestNormalFloat32, 1651 LargestSubnormalFloat32, 1652 SmallestNonzeroFloat32, 1653 MaxFloat32, 1654 -SmallestNormalFloat32, 1655 -LargestSubnormalFloat32, 1656 -SmallestNonzeroFloat32, 1657 -MaxFloat32, 1658 } 1659 var frexpBC = []fi{ 1660 {0.5, -125}, 1661 {0.9999999, -126}, 1662 {0.5, -148}, 1663 {0.99999994, 128}, 1664 {-0.5, -125}, 1665 {-0.9999999, -126}, 1666 {-0.5, -148}, 1667 {-0.99999994, 128}, 1668 } 1669 1670 var vfldexpBC = []fi{ 1671 {SmallestNormalFloat32, -23}, 1672 {LargestSubnormalFloat32, -22}, 1673 {SmallestNonzeroFloat32, 256}, 1674 {MaxFloat32, -(127 + 149)}, 1675 {1, -150}, 1676 {-1, -150}, 1677 {1, 128}, 1678 {-1, 128}, 1679 } 1680 var ldexpBC = []float32{ 1681 SmallestNonzeroFloat32, 1682 3e-45, // 2**-148 1683 1.6225928e32, // 2**130 1684 3e-45, // 2**-127 1685 0, 1686 Copysign(0, -1), 1687 Inf(1), 1688 Inf(-1), 1689 } 1690 1691 var logbBC = []float32{ 1692 -126, 1693 -127, 1694 -149, 1695 127, 1696 -126, 1697 -127, 1698 -149, 1699 127, 1700 } 1701 1702 func tolerance(a, b, e float32) bool { 1703 d := a - b 1704 if d < 0 { 1705 d = -d 1706 } 1707 1708 // note: b is correct (expected) value, a is actual value. 1709 // make error tolerance a fraction of b, not a. 1710 if b != 0 { 1711 e = e * b 1712 if e < 0 { 1713 e = -e 1714 } 1715 } 1716 return d < e 1717 } 1718 1719 // 5e-1 tolerance 1720 func nearby(a, b float32) bool { return tolerance(a, b, 5e-1) } // for large trig inputs results may be far apart. 1721 1722 // 1e-5 tolerance 1723 func close(a, b float32) bool { return tolerance(a, b, 1e-5) } // the number gotten from the cfloat standard. Haskell's Linear package uses 1e-6 for floats 1724 1725 // 1e-6 tolerance 1726 func veryclose(a, b float32) bool { return tolerance(a, b, 1e-6) } // from wiki 1727 func thisclose(a, b, e float32) bool { return tolerance(a, b, e) } 1728 func alike(a, b float32) bool { 1729 switch { 1730 case IsNaN(a) && IsNaN(b): 1731 return true 1732 case a == b: 1733 return Signbit(a) == Signbit(b) 1734 } 1735 return false 1736 } 1737 1738 func TestNaN(t *testing.T) { 1739 f64 := NaN() 1740 if f64 == f64 { 1741 t.Fatalf("NaN() returns %g, expected NaN", f64) 1742 } 1743 f32 := float32(f64) 1744 if f32 == f32 { 1745 t.Fatalf("float32(NaN()) is %g, expected NaN", f32) 1746 } 1747 } 1748 1749 func TestAcos(t *testing.T) { 1750 for i := 0; i < len(vf); i++ { 1751 a := vf[i] / 10 1752 if f := Acos(a); !close(acos[i], f) { 1753 t.Errorf("Acos(%g) = %g, want %g", a, f, acos[i]) 1754 } 1755 } 1756 for i := 0; i < len(vfacosSC); i++ { 1757 if f := Acos(vfacosSC[i]); !alike(acosSC[i], f) { 1758 t.Errorf("Acos(%g) = %g, want %g", vfacosSC[i], f, acosSC[i]) 1759 } 1760 } 1761 } 1762 1763 func TestAcosh(t *testing.T) { 1764 for i := 0; i < len(vf); i++ { 1765 a := 1 + Abs(vf[i]) 1766 if f := Acosh(a); !veryclose(acosh[i], f) { 1767 t.Errorf("Acosh(%g) = %g, want %g", a, f, acosh[i]) 1768 } 1769 } 1770 for i := 0; i < len(vfacoshSC); i++ { 1771 if f := Acosh(vfacoshSC[i]); !alike(acoshSC[i], f) { 1772 t.Errorf("Acosh(%g) = %g, want %g", vfacoshSC[i], f, acoshSC[i]) 1773 } 1774 } 1775 } 1776 1777 func TestAsin(t *testing.T) { 1778 for i := 0; i < len(vf); i++ { 1779 a := vf[i] / 10 1780 if f := Asin(a); !veryclose(asin[i], f) { 1781 t.Errorf("Asin(%g) = %g, want %g", a, f, asin[i]) 1782 } 1783 } 1784 for i := 0; i < len(vfasinSC); i++ { 1785 if f := Asin(vfasinSC[i]); !alike(asinSC[i], f) { 1786 t.Errorf("Asin(%g) = %g, want %g", vfasinSC[i], f, asinSC[i]) 1787 } 1788 } 1789 } 1790 1791 func TestAsinh(t *testing.T) { 1792 for i := 0; i < len(vf); i++ { 1793 if f := Asinh(vf[i]); !veryclose(asinh[i], f) { 1794 t.Errorf("Asinh(%g) = %g, want %g", vf[i], f, asinh[i]) 1795 } 1796 } 1797 for i := 0; i < len(vfasinhSC); i++ { 1798 if f := Asinh(vfasinhSC[i]); !alike(asinhSC[i], f) { 1799 t.Errorf("Asinh(%g) = %g, want %g", vfasinhSC[i], f, asinhSC[i]) 1800 } 1801 } 1802 } 1803 1804 func TestAtan(t *testing.T) { 1805 for i := 0; i < len(vf); i++ { 1806 if f := Atan(vf[i]); !veryclose(atan[i], f) { 1807 t.Errorf("Atan(%g) = %g, want %g", vf[i], f, atan[i]) 1808 } 1809 } 1810 for i := 0; i < len(vfatanSC); i++ { 1811 if f := Atan(vfatanSC[i]); !alike(atanSC[i], f) { 1812 t.Errorf("Atan(%g) = %g, want %g", vfatanSC[i], f, atanSC[i]) 1813 } 1814 } 1815 } 1816 1817 func TestAtanh(t *testing.T) { 1818 for i := 0; i < len(vf); i++ { 1819 a := vf[i] / 10 1820 if f := Atanh(a); !veryclose(atanh[i], f) { 1821 t.Errorf("Atanh(%g) = %g, want %g", a, f, atanh[i]) 1822 } 1823 } 1824 for i := 0; i < len(vfatanhSC); i++ { 1825 if f := Atanh(vfatanhSC[i]); !alike(atanhSC[i], f) { 1826 t.Errorf("Atanh(%g) = %g, want %g", vfatanhSC[i], f, atanhSC[i]) 1827 } 1828 } 1829 } 1830 1831 func TestAtan2(t *testing.T) { 1832 for i := 0; i < len(vf); i++ { 1833 if f := Atan2(10, vf[i]); !veryclose(atan2[i], f) { 1834 t.Errorf("Atan2(10, %g) = %g, want %g", vf[i], f, atan2[i]) 1835 } 1836 } 1837 for i := 0; i < len(vfatan2SC); i++ { 1838 if f := Atan2(vfatan2SC[i][0], vfatan2SC[i][1]); !alike(atan2SC[i], f) { 1839 t.Errorf("Atan2(%g, %g) = %g, want %g", vfatan2SC[i][0], vfatan2SC[i][1], f, atan2SC[i]) 1840 } 1841 } 1842 } 1843 1844 func TestCbrt(t *testing.T) { 1845 for i := 0; i < len(vf); i++ { 1846 if f := Cbrt(vf[i]); !veryclose(cbrt[i], f) { 1847 t.Errorf("Cbrt(%g) = %g, want %g", vf[i], f, cbrt[i]) 1848 } 1849 } 1850 for i := 0; i < len(vfcbrtSC); i++ { 1851 if f := Cbrt(vfcbrtSC[i]); !alike(cbrtSC[i], f) { 1852 t.Errorf("Cbrt(%g) = %g, want %g", vfcbrtSC[i], f, cbrtSC[i]) 1853 } 1854 } 1855 } 1856 1857 func TestCeil(t *testing.T) { 1858 for i := 0; i < len(vf); i++ { 1859 if f := Ceil(vf[i]); ceil[i] != f { 1860 t.Errorf("Ceil(%g) = %g, want %g", vf[i], f, ceil[i]) 1861 } 1862 } 1863 for i := 0; i < len(vfceilSC); i++ { 1864 if f := Ceil(vfceilSC[i]); !alike(ceilSC[i], f) { 1865 t.Errorf("Ceil(%g) = %g, want %g", vfceilSC[i], f, ceilSC[i]) 1866 } 1867 } 1868 } 1869 1870 func TestCopysign(t *testing.T) { 1871 for i := 0; i < len(vf); i++ { 1872 if f := Copysign(vf[i], -1); copysign[i] != f { 1873 t.Errorf("Copysign(%g, -1) = %g, want %g", vf[i], f, copysign[i]) 1874 } 1875 } 1876 for i := 0; i < len(vf); i++ { 1877 if f := Copysign(vf[i], 1); -copysign[i] != f { 1878 t.Errorf("Copysign(%g, 1) = %g, want %g", vf[i], f, -copysign[i]) 1879 } 1880 } 1881 for i := 0; i < len(vfcopysignSC); i++ { 1882 if f := Copysign(vfcopysignSC[i], -1); !alike(copysignSC[i], f) { 1883 t.Errorf("Copysign(%g, -1) = %g, want %g", vfcopysignSC[i], f, copysignSC[i]) 1884 } 1885 } 1886 } 1887 1888 func TestCos(t *testing.T) { 1889 for i := 0; i < len(vf); i++ { 1890 if f := Cos(vf[i]); !veryclose(cos[i], f) { 1891 fmt.Println(f) 1892 t.Errorf("%d: Cos(%g) = %g, want %g", i, vf[i], f, cos[i]) 1893 } 1894 } 1895 for i := 0; i < len(vfcosSC); i++ { 1896 if f := Cos(vfcosSC[i]); !alike(cosSC[i], f) { 1897 t.Errorf("%d: Cos(%g) = %g, want %g", i, vfcosSC[i], f, cosSC[i]) 1898 } 1899 } 1900 } 1901 1902 func TestCosh(t *testing.T) { 1903 for i := 0; i < len(vf); i++ { 1904 if f := Cosh(vf[i]); !close(cosh[i], f) { 1905 t.Errorf("Cosh(%g) = %g, want %g", vf[i], f, cosh[i]) 1906 } 1907 } 1908 for i := 0; i < len(vfcoshSC); i++ { 1909 if f := Cosh(vfcoshSC[i]); !alike(coshSC[i], f) { 1910 t.Errorf("Cosh(%g) = %g, want %g", vfcoshSC[i], f, coshSC[i]) 1911 } 1912 } 1913 } 1914 1915 func TestErf(t *testing.T) { 1916 for i := 0; i < len(vf); i++ { 1917 a := vf[i] / 10 1918 if f := Erf(a); !veryclose(erf[i], f) { 1919 t.Errorf("Erf(%g) = %g, want %g", a, f, erf[i]) 1920 } 1921 } 1922 for i := 0; i < len(vferfSC); i++ { 1923 if f := Erf(vferfSC[i]); !alike(erfSC[i], f) { 1924 t.Errorf("Erf(%g) = %g, want %g", vferfSC[i], f, erfSC[i]) 1925 } 1926 } 1927 } 1928 1929 func TestErfc(t *testing.T) { 1930 for i := 0; i < len(vf); i++ { 1931 a := vf[i] / 10 1932 if f := Erfc(a); !veryclose(erfc[i], f) { 1933 t.Errorf("Erfc(%g) = %g, want %g", a, f, erfc[i]) 1934 } 1935 } 1936 for i := 0; i < len(vferfcSC); i++ { 1937 if f := Erfc(vferfcSC[i]); !alike(erfcSC[i], f) { 1938 t.Errorf("Erfc(%g) = %g, want %g", vferfcSC[i], f, erfcSC[i]) 1939 } 1940 } 1941 } 1942 1943 func TestExp(t *testing.T) { 1944 testExp(t, Exp, "Exp") 1945 // testExp(t, ExpGo, "ExpGo") 1946 } 1947 1948 func testExp(t *testing.T, Exp func(float32) float32, name string) { 1949 for i := 0; i < len(vf); i++ { 1950 if f := Exp(vf[i]); !close(exp[i], f) { 1951 t.Errorf("%s(%g) = %g, want %g", name, vf[i], f, exp[i]) 1952 } 1953 } 1954 for i := 0; i < len(vfexpSC); i++ { 1955 if f := Exp(vfexpSC[i]); !alike(expSC[i], f) { 1956 t.Errorf("%s(%g) = %g, want %g", name, vfexpSC[i], f, expSC[i]) 1957 } 1958 } 1959 } 1960 1961 func TestExpm1(t *testing.T) { 1962 for i := 0; i < len(vf); i++ { 1963 a := vf[i] / 100 1964 if f := Expm1(a); !veryclose(expm1[i], f) { 1965 t.Errorf("Expm1(%g) = %g, want %g", a, f, expm1[i]) 1966 } 1967 } 1968 for i := 0; i < len(vf); i++ { 1969 a := vf[i] * 10 1970 if f := Expm1(a); !close(expm1Large[i], f) && (i == 4 && !IsInf(f, 1)) { 1971 t.Errorf("Expm1(%g) = %g, want %g", a, f, expm1Large[i]) 1972 } 1973 } 1974 for i := 0; i < len(vfexpm1SC); i++ { 1975 if f := Expm1(vfexpm1SC[i]); !alike(expm1SC[i], f) { 1976 t.Errorf("Expm1(%g) = %g, want %g", vfexpm1SC[i], f, expm1SC[i]) 1977 } 1978 } 1979 } 1980 1981 // func TestExp2(t *testing.T) { 1982 // testExp2(t, Exp2, "Exp2") 1983 // testExp2(t, Exp2Go, "Exp2Go") 1984 // } 1985 1986 func testExp2(t *testing.T, Exp2 func(float32) float32, name string) { 1987 for i := 0; i < len(vf); i++ { 1988 if f := Exp2(vf[i]); !close(exp2[i], f) { 1989 t.Errorf("%s(%g) = %g, want %g", name, vf[i], f, exp2[i]) 1990 } 1991 } 1992 for i := 0; i < len(vfexpSC); i++ { 1993 if f := Exp2(vfexpSC[i]); !alike(expSC[i], f) { 1994 t.Errorf("%s(%g) = %g, want %g", name, vfexpSC[i], f, expSC[i]) 1995 } 1996 } 1997 for n := -1074; n < 1024; n++ { 1998 f := Exp2(float32(n)) 1999 vf := Ldexp(1, n) 2000 if f != vf { 2001 t.Errorf("%s(%d) = %g, want %g", name, n, f, vf) 2002 } 2003 } 2004 } 2005 2006 func TestAbs(t *testing.T) { 2007 for i := 0; i < len(vf); i++ { 2008 if f := Abs(vf[i]); fabs[i] != f { 2009 t.Errorf("Abs(%g) = %g, want %g", vf[i], f, fabs[i]) 2010 } 2011 } 2012 for i := 0; i < len(vffabsSC); i++ { 2013 if f := Abs(vffabsSC[i]); !alike(fabsSC[i], f) { 2014 t.Errorf("Abs(%g) = %g, want %g", vffabsSC[i], f, fabsSC[i]) 2015 } 2016 } 2017 } 2018 2019 func TestDim(t *testing.T) { 2020 for i := 0; i < len(vf); i++ { 2021 if f := Dim(vf[i], 0); fdim[i] != f { 2022 t.Errorf("Dim(%g, %g) = %g, want %g", vf[i], 0.0, f, fdim[i]) 2023 } 2024 } 2025 for i := 0; i < len(vffdimSC); i++ { 2026 if f := Dim(vffdimSC[i][0], vffdimSC[i][1]); !alike(fdimSC[i], f) { 2027 t.Errorf("Dim(%g, %g) = %g, want %g", vffdimSC[i][0], vffdimSC[i][1], f, fdimSC[i]) 2028 } 2029 } 2030 for i := 0; i < len(vffdim2SC); i++ { 2031 if f := Dim(vffdim2SC[i][0], vffdim2SC[i][1]); !alike(fdimSC[i], f) { 2032 t.Errorf("Dim(%g, %g) = %g, want %g", vffdim2SC[i][0], vffdim2SC[i][1], f, fdimSC[i]) 2033 } 2034 } 2035 } 2036 2037 func TestFloor(t *testing.T) { 2038 for i := 0; i < len(vf); i++ { 2039 if f := Floor(vf[i]); floor[i] != f { 2040 t.Errorf("Floor(%g) = %g, want %g", vf[i], f, floor[i]) 2041 } 2042 } 2043 for i := 0; i < len(vfceilSC); i++ { 2044 if f := Floor(vfceilSC[i]); !alike(ceilSC[i], f) { 2045 t.Errorf("Floor(%g) = %g, want %g", vfceilSC[i], f, ceilSC[i]) 2046 } 2047 } 2048 } 2049 2050 func TestMax(t *testing.T) { 2051 for i := 0; i < len(vf); i++ { 2052 if f := Max(vf[i], ceil[i]); ceil[i] != f { 2053 t.Errorf("Max(%g, %g) = %g, want %g", vf[i], ceil[i], f, ceil[i]) 2054 } 2055 } 2056 for i := 0; i < len(vffdimSC); i++ { 2057 if f := Max(vffdimSC[i][0], vffdimSC[i][1]); !alike(fmaxSC[i], f) { 2058 t.Errorf("Max(%g, %g) = %g, want %g", vffdimSC[i][0], vffdimSC[i][1], f, fmaxSC[i]) 2059 } 2060 } 2061 for i := 0; i < len(vffdim2SC); i++ { 2062 if f := Max(vffdim2SC[i][0], vffdim2SC[i][1]); !alike(fmaxSC[i], f) { 2063 t.Errorf("Max(%g, %g) = %g, want %g", vffdim2SC[i][0], vffdim2SC[i][1], f, fmaxSC[i]) 2064 } 2065 } 2066 } 2067 2068 func TestMin(t *testing.T) { 2069 for i := 0; i < len(vf); i++ { 2070 if f := Min(vf[i], floor[i]); floor[i] != f { 2071 t.Errorf("Min(%g, %g) = %g, want %g", vf[i], floor[i], f, floor[i]) 2072 } 2073 } 2074 for i := 0; i < len(vffdimSC); i++ { 2075 if f := Min(vffdimSC[i][0], vffdimSC[i][1]); !alike(fminSC[i], f) { 2076 t.Errorf("Min(%g, %g) = %g, want %g", vffdimSC[i][0], vffdimSC[i][1], f, fminSC[i]) 2077 } 2078 } 2079 for i := 0; i < len(vffdim2SC); i++ { 2080 if f := Min(vffdim2SC[i][0], vffdim2SC[i][1]); !alike(fminSC[i], f) { 2081 t.Errorf("Min(%g, %g) = %g, want %g", vffdim2SC[i][0], vffdim2SC[i][1], f, fminSC[i]) 2082 } 2083 } 2084 } 2085 2086 func TestMod(t *testing.T) { 2087 for i := 0; i < len(vf); i++ { 2088 if f := Mod(10, vf[i]); !close(fmod[i], f) { 2089 t.Errorf("Mod(10, %g) = %g, want %g", vf[i], f, fmod[i]) 2090 } 2091 } 2092 for i := 0; i < len(vffmodSC); i++ { 2093 if f := Mod(vffmodSC[i][0], vffmodSC[i][1]); !alike(fmodSC[i], f) { 2094 t.Errorf("Mod(%g, %g) = %g, want %g", vffmodSC[i][0], vffmodSC[i][1], f, fmodSC[i]) 2095 } 2096 } 2097 } 2098 2099 func TestFrexp(t *testing.T) { 2100 for i := 0; i < len(vf); i++ { 2101 if f, j := Frexp(vf[i]); !veryclose(frexp[i].f, f) || frexp[i].i != j { 2102 t.Errorf("Frexp(%g) = %g, %d, want %g, %d", vf[i], f, j, frexp[i].f, frexp[i].i) 2103 } 2104 } 2105 for i := 0; i < len(vffrexpSC); i++ { 2106 if f, j := Frexp(vffrexpSC[i]); !alike(frexpSC[i].f, f) || frexpSC[i].i != j { 2107 t.Errorf("Frexp(%g) = %g, %d, want %g, %d", vffrexpSC[i], f, j, frexpSC[i].f, frexpSC[i].i) 2108 } 2109 } 2110 for i := 0; i < len(vffrexpBC); i++ { 2111 if f, j := Frexp(vffrexpBC[i]); !alike(frexpBC[i].f, f) || frexpBC[i].i != j { 2112 t.Errorf("Frexp(%g) = %g, %d, want %g, %d", vffrexpBC[i], f, j, frexpBC[i].f, frexpBC[i].i) 2113 } 2114 } 2115 } 2116 2117 func TestGamma(t *testing.T) { 2118 for i := 0; i < len(vf); i++ { 2119 if f := Gamma(vf[i]); !thisclose(gamma[i], f, 1e-4) { 2120 t.Errorf("Gamma(%g) = %g, want %g", vf[i], f, gamma[i]) 2121 } 2122 } 2123 for i := 0; i < len(vfgammaSC); i++ { 2124 if f := Gamma(vfgammaSC[i]); !alike(gammaSC[i], f) { 2125 t.Errorf("Gamma(%g) = %g, want %g", vfgammaSC[i], f, gammaSC[i]) 2126 } 2127 } 2128 } 2129 2130 func TestHypot(t *testing.T) { 2131 for i := 0; i < len(vf); i++ { 2132 a := Abs(1e20 * tanh[i] * Sqrt(2)) 2133 if f := Hypot(1e20*tanh[i], 1e20*tanh[i]); !veryclose(a, f) { 2134 t.Errorf("Hypot(%g, %g) = %g, want %g", 1e20*tanh[i], 1e20*tanh[i], f, a) 2135 } 2136 } 2137 for i := 0; i < len(vfhypotSC); i++ { 2138 if f := Hypot(vfhypotSC[i][0], vfhypotSC[i][1]); !alike(hypotSC[i], f) { 2139 t.Errorf("Hypot(%g, %g) = %g, want %g", vfhypotSC[i][0], vfhypotSC[i][1], f, hypotSC[i]) 2140 } 2141 } 2142 } 2143 2144 func TestIlogb(t *testing.T) { 2145 for i := 0; i < len(vf); i++ { 2146 a := frexp[i].i - 1 // adjust because fr in the interval [½, 1) 2147 if e := Ilogb(vf[i]); a != e { 2148 t.Errorf("Ilogb(%g) = %d, want %d", vf[i], e, a) 2149 } 2150 } 2151 for i := 0; i < len(vflogbSC); i++ { 2152 if e := Ilogb(vflogbSC[i]); ilogbSC[i] != e { 2153 t.Errorf("Ilogb(%g) = %d, want %d", vflogbSC[i], e, ilogbSC[i]) 2154 } 2155 } 2156 for i := 0; i < len(vffrexpBC); i++ { 2157 if e := Ilogb(vffrexpBC[i]); int(logbBC[i]) != e { 2158 t.Errorf("Ilogb(%g) = %d, want %d", vffrexpBC[i], e, int(logbBC[i])) 2159 } 2160 } 2161 } 2162 2163 func TestJ0(t *testing.T) { 2164 for i := 0; i < len(vf); i++ { 2165 if f := J0(vf[i]); !thisclose(j0[i], f, 4e-5) { 2166 t.Errorf("J0(%g) = %g, want %g", vf[i], f, j0[i]) 2167 } 2168 } 2169 for i := 0; i < len(vfj0SC); i++ { 2170 if f := J0(vfj0SC[i]); !alike(j0SC[i], f) { 2171 t.Errorf("J0(%g) = %g, want %g", vfj0SC[i], f, j0SC[i]) 2172 } 2173 } 2174 } 2175 2176 func TestJ1(t *testing.T) { 2177 for i := 0; i < len(vf); i++ { 2178 if f := J1(vf[i]); !close(j1[i], f) { 2179 t.Errorf("J1(%g) = %g, want %g", vf[i], f, j1[i]) 2180 } 2181 } 2182 for i := 0; i < len(vfj0SC); i++ { 2183 if f := J1(vfj0SC[i]); !alike(j1SC[i], f) { 2184 t.Errorf("J1(%g) = %g, want %g", vfj0SC[i], f, j1SC[i]) 2185 } 2186 } 2187 } 2188 2189 func TestJn(t *testing.T) { 2190 for i := 0; i < len(vf); i++ { 2191 if f := Jn(2, vf[i]); !close(j2[i], f) { 2192 t.Errorf("Jn(2, %g) = %g, want %g", vf[i], f, j2[i]) 2193 } 2194 if f := Jn(-3, vf[i]); !close(jM3[i], f) { 2195 t.Errorf("Jn(-3, %g) = %g, want %g", vf[i], f, jM3[i]) 2196 } 2197 } 2198 for i := 0; i < len(vfj0SC); i++ { 2199 if f := Jn(2, vfj0SC[i]); !alike(j2SC[i], f) { 2200 t.Errorf("Jn(2, %g) = %g, want %g", vfj0SC[i], f, j2SC[i]) 2201 } 2202 if f := Jn(-3, vfj0SC[i]); !alike(jM3SC[i], f) { 2203 t.Errorf("Jn(-3, %g) = %g, want %g", vfj0SC[i], f, jM3SC[i]) 2204 } 2205 } 2206 } 2207 2208 func TestLdexp(t *testing.T) { 2209 for i := 0; i < len(vf); i++ { 2210 if f := Ldexp(frexp[i].f, frexp[i].i); !veryclose(vf[i], f) { 2211 t.Errorf("Ldexp(%g, %d) = %g, want %g", frexp[i].f, frexp[i].i, f, vf[i]) 2212 } 2213 } 2214 for i := 0; i < len(vffrexpSC); i++ { 2215 if f := Ldexp(frexpSC[i].f, frexpSC[i].i); !alike(vffrexpSC[i], f) { 2216 t.Errorf("Ldexp(%g, %d) = %g, want %g", frexpSC[i].f, frexpSC[i].i, f, vffrexpSC[i]) 2217 } 2218 } 2219 for i := 0; i < len(vfldexpSC); i++ { 2220 if f := Ldexp(vfldexpSC[i].f, vfldexpSC[i].i); !alike(ldexpSC[i], f) { 2221 t.Errorf("Ldexp(%g, %d) = %g, want %g", vfldexpSC[i].f, vfldexpSC[i].i, f, ldexpSC[i]) 2222 } 2223 } 2224 for i := 0; i < len(vffrexpBC); i++ { 2225 if f := Ldexp(frexpBC[i].f, frexpBC[i].i); !alike(vffrexpBC[i], f) { 2226 t.Errorf("Ldexp(%g, %d) = %g, want %g", frexpBC[i].f, frexpBC[i].i, f, vffrexpBC[i]) 2227 } 2228 } 2229 for i := 0; i < len(vfldexpBC); i++ { 2230 if f := Ldexp(vfldexpBC[i].f, vfldexpBC[i].i); !alike(ldexpBC[i], f) { 2231 t.Errorf("Ldexp(%g, %d) = %g, want %g", vfldexpBC[i].f, vfldexpBC[i].i, f, ldexpBC[i]) 2232 } 2233 } 2234 } 2235 2236 func TestLgamma(t *testing.T) { 2237 for i := 0; i < len(vf); i++ { 2238 if f, s := Lgamma(vf[i]); !thisclose(lgamma[i].f, f, 1e-4) || lgamma[i].i != s { 2239 t.Errorf("Lgamma(%g) = %g, %d, want %g, %d", vf[i], f, s, lgamma[i].f, lgamma[i].i) 2240 } 2241 } 2242 for i := 0; i < len(vflgammaSC); i++ { 2243 if f, s := Lgamma(vflgammaSC[i]); !alike(lgammaSC[i].f, f) || lgammaSC[i].i != s { 2244 t.Errorf("Lgamma(%g) = %g, %d, want %g, %d", vflgammaSC[i], f, s, lgammaSC[i].f, lgammaSC[i].i) 2245 } 2246 } 2247 } 2248 2249 func TestLog(t *testing.T) { 2250 for i := 0; i < len(vf); i++ { 2251 a := Abs(vf[i]) 2252 if f := Log(a); !close(log[i], f) { 2253 t.Errorf("Log(%g) = %g, want %g", a, f, log[i]) 2254 } 2255 } 2256 if f := Log(10); f != Ln10 { 2257 t.Errorf("Log(%g) = %g, want %g", 10.0, f, Ln10) 2258 } 2259 for i := 0; i < len(vflogSC); i++ { 2260 if f := Log(vflogSC[i]); !alike(logSC[i], f) { 2261 t.Errorf("Log(%g) = %g, want %g", vflogSC[i], f, logSC[i]) 2262 } 2263 } 2264 } 2265 2266 func TestLogb(t *testing.T) { 2267 for i := 0; i < len(vf); i++ { 2268 if f := Logb(vf[i]); logb[i] != f { 2269 t.Errorf("Logb(%g) = %g, want %g", vf[i], f, logb[i]) 2270 } 2271 } 2272 for i := 0; i < len(vflogbSC); i++ { 2273 if f := Logb(vflogbSC[i]); !alike(logbSC[i], f) { 2274 t.Errorf("Logb(%g) = %g, want %g", vflogbSC[i], f, logbSC[i]) 2275 } 2276 } 2277 for i := 0; i < len(vffrexpBC); i++ { 2278 if f := Logb(vffrexpBC[i]); !alike(logbBC[i], f) { 2279 t.Errorf("Logb(%g) = %g, want %g", vffrexpBC[i], f, logbBC[i]) 2280 } 2281 } 2282 } 2283 2284 func TestLog10(t *testing.T) { 2285 for i := 0; i < len(vf); i++ { 2286 a := Abs(vf[i]) 2287 if f := Log10(a); !veryclose(log10[i], f) { 2288 t.Errorf("Log10(%g) = %g, want %g", a, f, log10[i]) 2289 } 2290 } 2291 if f := Log10(E); f != Log10E { 2292 t.Errorf("Log10(%g) = %g, want %g", E, f, Log10E) 2293 } 2294 for i := 0; i < len(vflogSC); i++ { 2295 if f := Log10(vflogSC[i]); !alike(logSC[i], f) { 2296 t.Errorf("Log10(%g) = %g, want %g", vflogSC[i], f, logSC[i]) 2297 } 2298 } 2299 } 2300 2301 func TestLog1p(t *testing.T) { 2302 for i := 0; i < len(vf); i++ { 2303 a := vf[i] / 100 2304 if f := Log1p(a); !veryclose(log1p[i], f) { 2305 t.Errorf("Log1p(%g) = %g, want %g", a, f, log1p[i]) 2306 } 2307 } 2308 a := float32(9.0) 2309 if f := Log1p(a); f != Ln10 { 2310 t.Errorf("Log1p(%g) = %g, want %g", a, f, Ln10) 2311 } 2312 for i := 0; i < len(vflogSC); i++ { 2313 if f := Log1p(vflog1pSC[i]); !alike(log1pSC[i], f) { 2314 t.Errorf("Log1p(%g) = %g, want %g", vflog1pSC[i], f, log1pSC[i]) 2315 } 2316 } 2317 } 2318 2319 func TestLog2(t *testing.T) { 2320 for i := 0; i < len(vf); i++ { 2321 a := Abs(vf[i]) 2322 if f := Log2(a); !veryclose(log2[i], f) { 2323 t.Errorf("Log2(%g) = %g, want %g", a, f, log2[i]) 2324 } 2325 } 2326 if f := Log2(E); f != Log2E { 2327 t.Errorf("Log2(%g) = %g, want %g", E, f, Log2E) 2328 } 2329 for i := 0; i < len(vflogSC); i++ { 2330 if f := Log2(vflogSC[i]); !alike(logSC[i], f) { 2331 t.Errorf("Log2(%g) = %g, want %g", vflogSC[i], f, logSC[i]) 2332 } 2333 } 2334 for i := -149; i <= 127; i++ { 2335 f := Ldexp(1, i) 2336 l := Log2(f) 2337 if l != float32(i) { 2338 t.Errorf("Log2(2**%d) = %g, want %d", i, l, i) 2339 } 2340 } 2341 } 2342 2343 func TestModf(t *testing.T) { 2344 for i := 0; i < len(vf); i++ { 2345 if f, g := Modf(vf[i]); !veryclose(modf[i][0], f) || !thisclose(modf[i][1], g, 1e-4) { 2346 t.Errorf("Modf(%g) = %g, %g, want %g, %g", vf[i], f, g, modf[i][0], modf[i][1]) 2347 } 2348 } 2349 for i := 0; i < len(vfmodfSC); i++ { 2350 if f, g := Modf(vfmodfSC[i]); !alike(modfSC[i][0], f) || !alike(modfSC[i][1], g) { 2351 t.Errorf("Modf(%g) = %g, %g, want %g, %g", vfmodfSC[i], f, g, modfSC[i][0], modfSC[i][1]) 2352 } 2353 } 2354 } 2355 2356 func TestNextafter(t *testing.T) { 2357 for i := 0; i < len(vf); i++ { 2358 vfi := vf[i] 2359 if f := Nextafter(vfi, 10); nextafter32[i] != f { 2360 t.Errorf("Nextafter32(%g, %g) = %g want %g", vfi, 10.0, f, nextafter32[i]) 2361 } 2362 } 2363 for i := 0; i < len(vfnextafter32SC); i++ { 2364 if f := Nextafter(vfnextafter32SC[i][0], vfnextafter32SC[i][1]); !alike(nextafter32SC[i], f) { 2365 t.Errorf("Nextafter32(%g, %g) = %g want %g", vfnextafter32SC[i][0], vfnextafter32SC[i][1], f, nextafter32SC[i]) 2366 } 2367 } 2368 } 2369 2370 func TestPow(t *testing.T) { 2371 for i := 0; i < len(vf); i++ { 2372 if f := Pow(10, vf[i]); !close(pow[i], f) { 2373 t.Errorf("Pow(10, %g) = %g, want %g", vf[i], f, pow[i]) 2374 } 2375 } 2376 for i := 0; i < len(vfpowSC); i++ { 2377 if f := Pow(vfpowSC[i][0], vfpowSC[i][1]); !alike(powSC[i], f) { 2378 t.Errorf("Pow(%g, %g) = %g, want %g", vfpowSC[i][0], vfpowSC[i][1], f, powSC[i]) 2379 } 2380 } 2381 } 2382 2383 func TestPow10(t *testing.T) { 2384 for i := 0; i < len(vfpow10SC); i++ { 2385 if f := Pow10(vfpow10SC[i]); !alike(pow10SC[i], f) { 2386 t.Errorf("Pow10(%d) = %g, want %g", vfpow10SC[i], f, pow10SC[i]) 2387 } 2388 } 2389 } 2390 2391 func TestRemainder(t *testing.T) { 2392 for i := 0; i < len(vf); i++ { 2393 if f := Remainder(10, vf[i]); !thisclose(remainder[i], f, 1e-4) { 2394 t.Errorf("Remainder(10, %g) = %g, want %g", vf[i], f, remainder[i]) 2395 } 2396 } 2397 for i := 0; i < len(vffmodSC); i++ { 2398 if f := Remainder(vffmodSC[i][0], vffmodSC[i][1]); !alike(fmodSC[i], f) { 2399 t.Errorf("Remainder(%g, %g) = %g, want %g", vffmodSC[i][0], vffmodSC[i][1], f, fmodSC[i]) 2400 } 2401 } 2402 } 2403 2404 func TestSignbit(t *testing.T) { 2405 for i := 0; i < len(vf); i++ { 2406 if f := Signbit(vf[i]); signbit[i] != f { 2407 t.Errorf("Signbit(%g) = %t, want %t", vf[i], f, signbit[i]) 2408 } 2409 } 2410 for i := 0; i < len(vfsignbitSC); i++ { 2411 if f := Signbit(vfsignbitSC[i]); signbitSC[i] != f { 2412 t.Errorf("Signbit(%g) = %t, want %t", vfsignbitSC[i], f, signbitSC[i]) 2413 } 2414 } 2415 } 2416 func TestSin(t *testing.T) { 2417 for i := 0; i < len(vf); i++ { 2418 if f := Sin(vf[i]); !close(sin[i], f) { 2419 t.Errorf("Sin(%g) = %g, want %g", vf[i], f, sin[i]) 2420 } 2421 } 2422 for i := 0; i < len(vfsinSC); i++ { 2423 if f := Sin(vfsinSC[i]); !alike(sinSC[i], f) { 2424 t.Errorf("Sin(%g) = %g, want %g", vfsinSC[i], f, sinSC[i]) 2425 } 2426 } 2427 } 2428 2429 func TestSincos(t *testing.T) { 2430 for i := 0; i < len(vf); i++ { 2431 if s, c := Sincos(vf[i]); !close(sin[i], s) || !close(cos[i], c) { 2432 t.Errorf("Sincos(%g) = %g, %g want %g, %g", vf[i], s, c, sin[i], cos[i]) 2433 } 2434 } 2435 } 2436 2437 func TestSinh(t *testing.T) { 2438 for i := 0; i < len(vf); i++ { 2439 if f := Sinh(vf[i]); !close(sinh[i], f) { 2440 t.Errorf("Sinh(%g) = %g, want %g", vf[i], f, sinh[i]) 2441 } 2442 } 2443 for i := 0; i < len(vfsinhSC); i++ { 2444 if f := Sinh(vfsinhSC[i]); !alike(sinhSC[i], f) { 2445 t.Errorf("Sinh(%g) = %g, want %g", vfsinhSC[i], f, sinhSC[i]) 2446 } 2447 } 2448 } 2449 2450 func TestSqrt(t *testing.T) { 2451 const tol = 1e-7 2452 for i := 0; i < len(vf); i++ { 2453 a := Abs(vf[i]) 2454 if f := SqrtGo(a); !thisclose(f, sqrt[i], tol) { 2455 t.Errorf("SqrtGo(%g) = %g, want %g", a, f, sqrt[i]) 2456 } 2457 if f := Sqrt(a); !thisclose(f, sqrt[i], tol) { 2458 t.Errorf("Sqrt(%g) = %g, want %g", a, f, sqrt[i]) 2459 } 2460 } 2461 for i := 0; i < len(vfsqrtSC); i++ { 2462 if f := SqrtGo(vfsqrtSC[i]); !alike(sqrtSC[i], f) { 2463 t.Errorf("%d: SqrtGo(%g) = %g, want %g", i, vfsqrtSC[i], f, sqrtSC[i]) 2464 } 2465 if f := Sqrt(vfsqrtSC[i]); !alike(sqrtSC[i], f) { 2466 t.Errorf("%d: Sqrt(%g) = %g, want %g", i, vfsqrtSC[i], f, sqrtSC[i]) 2467 } 2468 } 2469 } 2470 2471 func TestTan(t *testing.T) { 2472 for i := 0; i < len(vf); i++ { 2473 if f := Tan(vf[i]); !close(tan[i], f) { 2474 t.Errorf("Tan(%g) = %g, want %g", vf[i], f, tan[i]) 2475 } 2476 } 2477 // same special cases as Sin 2478 for i := 0; i < len(vfsinSC); i++ { 2479 if f := Tan(vfsinSC[i]); !alike(sinSC[i], f) { 2480 t.Errorf("Tan(%g) = %g, want %g", vfsinSC[i], f, sinSC[i]) 2481 } 2482 } 2483 } 2484 2485 func TestTanh(t *testing.T) { 2486 for i := 0; i < len(vf); i++ { 2487 if f := Tanh(vf[i]); !veryclose(tanh[i], f) { 2488 t.Errorf("Tanh(%g) = %g, want %g", vf[i], f, tanh[i]) 2489 } 2490 } 2491 for i := 0; i < len(vftanhSC); i++ { 2492 if f := Tanh(vftanhSC[i]); !alike(tanhSC[i], f) { 2493 t.Errorf("Tanh(%g) = %g, want %g", vftanhSC[i], f, tanhSC[i]) 2494 } 2495 } 2496 } 2497 2498 func TestTrunc(t *testing.T) { 2499 for i := 0; i < len(vf); i++ { 2500 if f := Trunc(vf[i]); trunc[i] != f { 2501 t.Errorf("Trunc(%g) = %g, want %g", vf[i], f, trunc[i]) 2502 } 2503 } 2504 for i := 0; i < len(vfceilSC); i++ { 2505 if f := Trunc(vfceilSC[i]); !alike(ceilSC[i], f) { 2506 t.Errorf("Trunc(%g) = %g, want %g", vfceilSC[i], f, ceilSC[i]) 2507 } 2508 } 2509 } 2510 2511 func TestY0(t *testing.T) { 2512 for i := 0; i < len(vf); i++ { 2513 a := Abs(vf[i]) 2514 if f := Y0(a); !close(y0[i], f) { 2515 t.Errorf("Y0(%g) = %g, want %g", a, f, y0[i]) 2516 } 2517 } 2518 for i := 0; i < len(vfy0SC); i++ { 2519 if f := Y0(vfy0SC[i]); !alike(y0SC[i], f) { 2520 t.Errorf("Y0(%g) = %g, want %g", vfy0SC[i], f, y0SC[i]) 2521 } 2522 } 2523 } 2524 2525 func TestY1(t *testing.T) { 2526 for i := 0; i < len(vf); i++ { 2527 a := Abs(vf[i]) 2528 if f := Y1(a); !close(y1[i], f) { 2529 t.Errorf("Y1(%g) = %g, want %g", a, f, y1[i]) 2530 } 2531 } 2532 for i := 0; i < len(vfy0SC); i++ { 2533 if f := Y1(vfy0SC[i]); !alike(y1SC[i], f) { 2534 t.Errorf("Y1(%g) = %g, want %g", vfy0SC[i], f, y1SC[i]) 2535 } 2536 } 2537 } 2538 2539 func TestYn(t *testing.T) { 2540 for i := 0; i < len(vf); i++ { 2541 a := Abs(vf[i]) 2542 if f := Yn(2, a); !close(y2[i], f) { 2543 t.Errorf("Yn(2, %g) = %g, want %g", a, f, y2[i]) 2544 } 2545 if f := Yn(-3, a); !close(yM3[i], f) { 2546 t.Errorf("Yn(-3, %g) = %g, want %g", a, f, yM3[i]) 2547 } 2548 } 2549 for i := 0; i < len(vfy0SC); i++ { 2550 if f := Yn(2, vfy0SC[i]); !alike(y2SC[i], f) { 2551 t.Errorf("Yn(2, %g) = %g, want %g", vfy0SC[i], f, y2SC[i]) 2552 } 2553 if f := Yn(-3, vfy0SC[i]); !alike(yM3SC[i], f) { 2554 t.Errorf("Yn(-3, %g) = %g, want %g", vfy0SC[i], f, yM3SC[i]) 2555 } 2556 } 2557 } 2558 2559 // Check that math functions of high angle values 2560 // return accurate results. [Since (vf[i] + large) - large != vf[i], 2561 // testing for Trig(vf[i] + large) == Trig(vf[i]), where large is 2562 // a multiple of 2*Pi, is misleading.] 2563 func TestLargeCos(t *testing.T) { 2564 large := float32(100000 * Pi) 2565 for i := 0; i < len(vf); i++ { 2566 f1 := cosLarge[i] 2567 f2 := Cos(vf[i] + large) 2568 if !nearby(f1, f2) { 2569 t.Errorf("Cos(%g) = %g, want %g", vf[i]+large, f2, f1) 2570 } 2571 } 2572 } 2573 2574 func TestLargeSin(t *testing.T) { 2575 large := float32(100000 * Pi) 2576 for i := 0; i < len(vf); i++ { 2577 f1 := sinLarge[i] 2578 f2 := Sin(vf[i] + large) 2579 if !nearby(f1, f2) { 2580 t.Errorf("Sin(%g) = %g, want %g", vf[i]+large, f2, f1) 2581 } 2582 } 2583 } 2584 2585 func TestLargeSincos(t *testing.T) { 2586 large := float32(100000 * Pi) 2587 for i := 0; i < len(vf); i++ { 2588 f1, g1 := sinLarge[i], cosLarge[i] 2589 f2, g2 := Sincos(vf[i] + large) 2590 if !nearby(f1, f2) || !nearby(g1, g2) { 2591 t.Errorf("Sincos(%g) = %g, %g, want %g, %g", vf[i]+large, f2, g2, f1, g1) 2592 } 2593 } 2594 } 2595 2596 func TestLargeTan(t *testing.T) { 2597 large := float32(100000 * Pi) 2598 for i := 0; i < len(vf); i++ { 2599 f1 := tanLarge[i] 2600 f2 := Tan(vf[i] + large) 2601 if !nearby(f1, f2) { 2602 t.Errorf("Tan(%g) = %g, want %g", vf[i]+large, f2, f1) 2603 } 2604 } 2605 } 2606 2607 // Check that math constants are accepted by compiler 2608 // and have right value (assumes strconv.ParseFloat works). 2609 // https://golang.org/issue/201 2610 2611 type floatTest struct { 2612 val interface{} 2613 name string 2614 str string 2615 } 2616 2617 var floatTests = []floatTest{ 2618 {float32(MaxFloat32), "MaxFloat32", "3.4028235e+38"}, 2619 {float32(SmallestNonzeroFloat32), "SmallestNonzeroFloat32", "1e-45"}, 2620 } 2621 2622 func TestFloatMinMax(t *testing.T) { 2623 for _, tt := range floatTests { 2624 s := fmt.Sprint(tt.val) 2625 if s != tt.str { 2626 t.Errorf("Sprint(%v) = %s, want %s", tt.name, s, tt.str) 2627 } 2628 } 2629 } 2630 2631 // Benchmarks 2632 2633 func BenchmarkAcos(b *testing.B) { 2634 for i := 0; i < b.N; i++ { 2635 Acos(.5) 2636 } 2637 } 2638 2639 func BenchmarkAcosh(b *testing.B) { 2640 for i := 0; i < b.N; i++ { 2641 Acosh(1.5) 2642 } 2643 } 2644 2645 func BenchmarkAsin(b *testing.B) { 2646 for i := 0; i < b.N; i++ { 2647 Asin(.5) 2648 } 2649 } 2650 2651 func BenchmarkAsinh(b *testing.B) { 2652 for i := 0; i < b.N; i++ { 2653 Asinh(.5) 2654 } 2655 } 2656 2657 func BenchmarkAtan(b *testing.B) { 2658 for i := 0; i < b.N; i++ { 2659 Atan(.5) 2660 } 2661 } 2662 2663 func BenchmarkAtanh(b *testing.B) { 2664 for i := 0; i < b.N; i++ { 2665 Atanh(.5) 2666 } 2667 } 2668 2669 func BenchmarkAtan2(b *testing.B) { 2670 for i := 0; i < b.N; i++ { 2671 Atan2(.5, 1) 2672 } 2673 } 2674 2675 func BenchmarkCbrt(b *testing.B) { 2676 for i := 0; i < b.N; i++ { 2677 Cbrt(10) 2678 } 2679 } 2680 2681 func BenchmarkCeil(b *testing.B) { 2682 for i := 0; i < b.N; i++ { 2683 Ceil(.5) 2684 } 2685 } 2686 2687 func BenchmarkCopysign(b *testing.B) { 2688 for i := 0; i < b.N; i++ { 2689 Copysign(.5, -1) 2690 } 2691 } 2692 2693 func BenchmarkCos(b *testing.B) { 2694 for i := 0; i < b.N; i++ { 2695 Cos(.5) 2696 } 2697 } 2698 2699 func BenchmarkCosh(b *testing.B) { 2700 for i := 0; i < b.N; i++ { 2701 Cosh(2.5) 2702 } 2703 } 2704 2705 func BenchmarkErf(b *testing.B) { 2706 for i := 0; i < b.N; i++ { 2707 Erf(.5) 2708 } 2709 } 2710 2711 func BenchmarkErfc(b *testing.B) { 2712 for i := 0; i < b.N; i++ { 2713 Erfc(.5) 2714 } 2715 } 2716 2717 func BenchmarkExp(b *testing.B) { 2718 for i := 0; i < b.N; i++ { 2719 Exp(.5) 2720 } 2721 } 2722 2723 // func BenchmarkExpGo(b *testing.B) { 2724 // for i := 0; i < b.N; i++ { 2725 // ExpGo(.5) 2726 // } 2727 // } 2728 2729 func BenchmarkExpm1(b *testing.B) { 2730 for i := 0; i < b.N; i++ { 2731 Expm1(.5) 2732 } 2733 } 2734 2735 func BenchmarkExp2(b *testing.B) { 2736 for i := 0; i < b.N; i++ { 2737 Exp2(.5) 2738 } 2739 } 2740 2741 // func BenchmarkExp2Go(b *testing.B) { 2742 // for i := 0; i < b.N; i++ { 2743 // Exp2Go(.5) 2744 // } 2745 // } 2746 2747 func BenchmarkAbs(b *testing.B) { 2748 for i := 0; i < b.N; i++ { 2749 Abs(.5) 2750 } 2751 } 2752 2753 func BenchmarkDim(b *testing.B) { 2754 for i := 0; i < b.N; i++ { 2755 Dim(10, 3) 2756 } 2757 } 2758 2759 func BenchmarkFloor(b *testing.B) { 2760 for i := 0; i < b.N; i++ { 2761 Floor(.5) 2762 } 2763 } 2764 2765 func BenchmarkMax(b *testing.B) { 2766 for i := 0; i < b.N; i++ { 2767 Max(10, 3) 2768 } 2769 } 2770 2771 func BenchmarkMin(b *testing.B) { 2772 for i := 0; i < b.N; i++ { 2773 Min(10, 3) 2774 } 2775 } 2776 2777 func BenchmarkMod(b *testing.B) { 2778 for i := 0; i < b.N; i++ { 2779 Mod(10, 3) 2780 } 2781 } 2782 2783 func BenchmarkFrexp(b *testing.B) { 2784 for i := 0; i < b.N; i++ { 2785 Frexp(8) 2786 } 2787 } 2788 2789 func BenchmarkGamma(b *testing.B) { 2790 for i := 0; i < b.N; i++ { 2791 Gamma(2.5) 2792 } 2793 } 2794 2795 func BenchmarkHypot(b *testing.B) { 2796 for i := 0; i < b.N; i++ { 2797 Hypot(3, 4) 2798 } 2799 } 2800 2801 func BenchmarkIlogb(b *testing.B) { 2802 for i := 0; i < b.N; i++ { 2803 Ilogb(.5) 2804 } 2805 } 2806 2807 func BenchmarkJ0(b *testing.B) { 2808 for i := 0; i < b.N; i++ { 2809 J0(2.5) 2810 } 2811 } 2812 2813 func BenchmarkJ1(b *testing.B) { 2814 for i := 0; i < b.N; i++ { 2815 J1(2.5) 2816 } 2817 } 2818 2819 func BenchmarkJn(b *testing.B) { 2820 for i := 0; i < b.N; i++ { 2821 Jn(2, 2.5) 2822 } 2823 } 2824 2825 func BenchmarkLdexp(b *testing.B) { 2826 for i := 0; i < b.N; i++ { 2827 Ldexp(.5, 2) 2828 } 2829 } 2830 2831 func BenchmarkLgamma(b *testing.B) { 2832 for i := 0; i < b.N; i++ { 2833 Lgamma(2.5) 2834 } 2835 } 2836 2837 func BenchmarkLog(b *testing.B) { 2838 for i := 0; i < b.N; i++ { 2839 Log(.5) 2840 } 2841 } 2842 2843 func BenchmarkLogb(b *testing.B) { 2844 for i := 0; i < b.N; i++ { 2845 Logb(.5) 2846 } 2847 } 2848 2849 func BenchmarkLog1p(b *testing.B) { 2850 for i := 0; i < b.N; i++ { 2851 Log1p(.5) 2852 } 2853 } 2854 2855 func BenchmarkLog10(b *testing.B) { 2856 for i := 0; i < b.N; i++ { 2857 Log10(.5) 2858 } 2859 } 2860 2861 func BenchmarkLog2(b *testing.B) { 2862 for i := 0; i < b.N; i++ { 2863 Log2(.5) 2864 } 2865 } 2866 2867 func BenchmarkModf(b *testing.B) { 2868 for i := 0; i < b.N; i++ { 2869 Modf(1.5) 2870 } 2871 } 2872 2873 func BenchmarkNextafter(b *testing.B) { 2874 for i := 0; i < b.N; i++ { 2875 Nextafter(.5, 1) 2876 } 2877 } 2878 2879 func BenchmarkPowInt(b *testing.B) { 2880 for i := 0; i < b.N; i++ { 2881 Pow(2, 2) 2882 } 2883 } 2884 2885 func BenchmarkPowFrac(b *testing.B) { 2886 for i := 0; i < b.N; i++ { 2887 Pow(2.5, 1.5) 2888 } 2889 } 2890 2891 func BenchmarkPow10Pos(b *testing.B) { 2892 for i := 0; i < b.N; i++ { 2893 Pow10(300) 2894 } 2895 } 2896 2897 func BenchmarkPow10Neg(b *testing.B) { 2898 for i := 0; i < b.N; i++ { 2899 Pow10(-300) 2900 } 2901 } 2902 2903 func BenchmarkRemainder(b *testing.B) { 2904 for i := 0; i < b.N; i++ { 2905 Remainder(10, 3) 2906 } 2907 } 2908 2909 func BenchmarkSignbit(b *testing.B) { 2910 for i := 0; i < b.N; i++ { 2911 Signbit(2.5) 2912 } 2913 } 2914 2915 func BenchmarkSin(b *testing.B) { 2916 for i := 0; i < b.N; i++ { 2917 Sin(.5) 2918 } 2919 } 2920 2921 func BenchmarkSincos(b *testing.B) { 2922 for i := 0; i < b.N; i++ { 2923 Sincos(.5) 2924 } 2925 } 2926 2927 func BenchmarkSinh(b *testing.B) { 2928 for i := 0; i < b.N; i++ { 2929 Sinh(2.5) 2930 } 2931 } 2932 2933 var Global float32 2934 2935 func BenchmarkSqrt(b *testing.B) { 2936 var x, y float32 2937 x, y = 0.0, 10.0 2938 for i := 0; i < b.N; i++ { 2939 x += Sqrt(y) 2940 } 2941 Global = x 2942 } 2943 2944 func BenchmarkSqrtIndirect(b *testing.B) { 2945 var x, y float32 2946 x, y = 0.0, 10.0 2947 f := Sqrt 2948 for i := 0; i < b.N; i++ { 2949 x += f(y) 2950 } 2951 Global = x 2952 } 2953 2954 // func BenchmarkSqrtGo(b *testing.B) { 2955 // var x, y float32 2956 // x, y = 0.0, 10.0 2957 // for i := 0; i < b.N; i++ { 2958 // x += SqrtGo(y) 2959 // } 2960 // Global = x 2961 // } 2962 2963 func isPrime(i int) bool { 2964 // Yes, this is a dumb way to write this code, 2965 // but calling Sqrt repeatedly in this way demonstrates 2966 // the benefit of using a direct SQRT instruction on systems 2967 // that have one, whereas the obvious loop seems not to 2968 // demonstrate such a benefit. 2969 for j := 2; float32(j) <= Sqrt(float32(i)); j++ { 2970 if i%j == 0 { 2971 return false 2972 } 2973 } 2974 return true 2975 } 2976 2977 func BenchmarkSqrtPrime(b *testing.B) { 2978 any := false 2979 for i := 0; i < b.N; i++ { 2980 if isPrime(100003) { 2981 any = true 2982 } 2983 } 2984 if any { 2985 Global = 1 2986 } 2987 } 2988 2989 func BenchmarkTan(b *testing.B) { 2990 for i := 0; i < b.N; i++ { 2991 Tan(.5) 2992 } 2993 } 2994 2995 func BenchmarkTanh(b *testing.B) { 2996 for i := 0; i < b.N; i++ { 2997 Tanh(2.5) 2998 } 2999 } 3000 func BenchmarkTrunc(b *testing.B) { 3001 for i := 0; i < b.N; i++ { 3002 Trunc(.5) 3003 } 3004 } 3005 3006 func BenchmarkY0(b *testing.B) { 3007 for i := 0; i < b.N; i++ { 3008 Y0(2.5) 3009 } 3010 } 3011 3012 func BenchmarkY1(b *testing.B) { 3013 for i := 0; i < b.N; i++ { 3014 Y1(2.5) 3015 } 3016 } 3017 3018 func BenchmarkYn(b *testing.B) { 3019 for i := 0; i < b.N; i++ { 3020 Yn(2, 2.5) 3021 } 3022 }