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