github.com/Filosottile/go@v0.0.0-20170906193555-dbed9972d994/src/math/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 math_test 6 7 import ( 8 "fmt" 9 . "math" 10 "testing" 11 "unsafe" 12 ) 13 14 var vf = []float64{ 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 = []float64{ 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 = []float64{ 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 = []float64{ 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 = []float64{ 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 = []float64{ 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 = []float64{ 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 = []float64{ 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 = []float64{ 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 = []float64{ 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 = []float64{ 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 = []float64{ 153 2.634752140995199110787593e-01, 154 1.148551260848219865642039e-01, 155 9.6191297325640768154550453e-01, 156 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 = []float64{ 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 = []float64{ 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 = []float64{ 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 = []float64{ 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 erfinv = []float64{ 215 4.746037673358033586786350696e-01, 216 8.559054432692110956388764172e-01, 217 -2.45427830571707336251331946e-02, 218 -4.78116683518973366268905506e-01, 219 1.479804430319470983648120853e+00, 220 2.654485787128896161882650211e-01, 221 5.027444534221520197823192493e-01, 222 2.466703532707627818954585670e-01, 223 1.632011465103005426240343116e-01, 224 -1.06672334642196900710000389e+00, 225 } 226 var exp = []float64{ 227 1.4533071302642137507696589e+02, 228 2.2958822575694449002537581e+03, 229 7.5814542574851666582042306e-01, 230 6.6668778421791005061482264e-03, 231 1.5310493273896033740861206e+04, 232 1.8659907517999328638667732e+01, 233 1.8662167355098714543942057e+02, 234 1.5301332413189378961665788e+01, 235 6.2047063430646876349125085e+00, 236 1.6894712385826521111610438e-04, 237 } 238 var expm1 = []float64{ 239 5.105047796122957327384770212e-02, 240 8.046199708567344080562675439e-02, 241 -2.764970978891639815187418703e-03, 242 -4.8871434888875355394330300273e-02, 243 1.0115864277221467777117227494e-01, 244 2.969616407795910726014621657e-02, 245 5.368214487944892300914037972e-02, 246 2.765488851131274068067445335e-02, 247 1.842068661871398836913874273e-02, 248 -8.3193870863553801814961137573e-02, 249 } 250 var expm1Large = []float64{ 251 4.2031418113550844e+21, 252 4.0690789717473863e+33, 253 -0.9372627915981363e+00, 254 -1.0, 255 7.077694784145933e+41, 256 5.117936223839153e+12, 257 5.124137759001189e+22, 258 7.03546003972584e+11, 259 8.456921800389698e+07, 260 -1.0, 261 } 262 var exp2 = []float64{ 263 3.1537839463286288034313104e+01, 264 2.1361549283756232296144849e+02, 265 8.2537402562185562902577219e-01, 266 3.1021158628740294833424229e-02, 267 7.9581744110252191462569661e+02, 268 7.6019905892596359262696423e+00, 269 3.7506882048388096973183084e+01, 270 6.6250893439173561733216375e+00, 271 3.5438267900243941544605339e+00, 272 2.4281533133513300984289196e-03, 273 } 274 var fabs = []float64{ 275 4.9790119248836735e+00, 276 7.7388724745781045e+00, 277 2.7688005719200159e-01, 278 5.0106036182710749e+00, 279 9.6362937071984173e+00, 280 2.9263772392439646e+00, 281 5.2290834314593066e+00, 282 2.7279399104360102e+00, 283 1.8253080916808550e+00, 284 8.6859247685756013e+00, 285 } 286 var fdim = []float64{ 287 4.9790119248836735e+00, 288 7.7388724745781045e+00, 289 0.0000000000000000e+00, 290 0.0000000000000000e+00, 291 9.6362937071984173e+00, 292 2.9263772392439646e+00, 293 5.2290834314593066e+00, 294 2.7279399104360102e+00, 295 1.8253080916808550e+00, 296 0.0000000000000000e+00, 297 } 298 var floor = []float64{ 299 4.0000000000000000e+00, 300 7.0000000000000000e+00, 301 -1.0000000000000000e+00, 302 -6.0000000000000000e+00, 303 9.0000000000000000e+00, 304 2.0000000000000000e+00, 305 5.0000000000000000e+00, 306 2.0000000000000000e+00, 307 1.0000000000000000e+00, 308 -9.0000000000000000e+00, 309 } 310 var fmod = []float64{ 311 4.197615023265299782906368e-02, 312 2.261127525421895434476482e+00, 313 3.231794108794261433104108e-02, 314 4.989396381728925078391512e+00, 315 3.637062928015826201999516e-01, 316 1.220868282268106064236690e+00, 317 4.770916568540693347699744e+00, 318 1.816180268691969246219742e+00, 319 8.734595415957246977711748e-01, 320 1.314075231424398637614104e+00, 321 } 322 323 type fi struct { 324 f float64 325 i int 326 } 327 328 var frexp = []fi{ 329 {6.2237649061045918750e-01, 3}, 330 {9.6735905932226306250e-01, 3}, 331 {-5.5376011438400318000e-01, -1}, 332 {-6.2632545228388436250e-01, 3}, 333 {6.02268356699901081250e-01, 4}, 334 {7.3159430981099115000e-01, 2}, 335 {6.5363542893241332500e-01, 3}, 336 {6.8198497760900255000e-01, 2}, 337 {9.1265404584042750000e-01, 1}, 338 {-5.4287029803597508250e-01, 4}, 339 } 340 var gamma = []float64{ 341 2.3254348370739963835386613898e+01, 342 2.991153837155317076427529816e+03, 343 -4.561154336726758060575129109e+00, 344 7.719403468842639065959210984e-01, 345 1.6111876618855418534325755566e+05, 346 1.8706575145216421164173224946e+00, 347 3.4082787447257502836734201635e+01, 348 1.579733951448952054898583387e+00, 349 9.3834586598354592860187267089e-01, 350 -2.093995902923148389186189429e-05, 351 } 352 var j0 = []float64{ 353 -1.8444682230601672018219338e-01, 354 2.27353668906331975435892e-01, 355 9.809259936157051116270273e-01, 356 -1.741170131426226587841181e-01, 357 -2.1389448451144143352039069e-01, 358 -2.340905848928038763337414e-01, 359 -1.0029099691890912094586326e-01, 360 -1.5466726714884328135358907e-01, 361 3.252650187653420388714693e-01, 362 -8.72218484409407250005360235e-03, 363 } 364 var j1 = []float64{ 365 -3.251526395295203422162967e-01, 366 1.893581711430515718062564e-01, 367 -1.3711761352467242914491514e-01, 368 3.287486536269617297529617e-01, 369 1.3133899188830978473849215e-01, 370 3.660243417832986825301766e-01, 371 -3.4436769271848174665420672e-01, 372 4.329481396640773768835036e-01, 373 5.8181350531954794639333955e-01, 374 -2.7030574577733036112996607e-01, 375 } 376 var j2 = []float64{ 377 5.3837518920137802565192769e-02, 378 -1.7841678003393207281244667e-01, 379 9.521746934916464142495821e-03, 380 4.28958355470987397983072e-02, 381 2.4115371837854494725492872e-01, 382 4.842458532394520316844449e-01, 383 -3.142145220618633390125946e-02, 384 4.720849184745124761189957e-01, 385 3.122312022520957042957497e-01, 386 7.096213118930231185707277e-02, 387 } 388 var jM3 = []float64{ 389 -3.684042080996403091021151e-01, 390 2.8157665936340887268092661e-01, 391 4.401005480841948348343589e-04, 392 3.629926999056814081597135e-01, 393 3.123672198825455192489266e-02, 394 -2.958805510589623607540455e-01, 395 -3.2033177696533233403289416e-01, 396 -2.592737332129663376736604e-01, 397 -1.0241334641061485092351251e-01, 398 -2.3762660886100206491674503e-01, 399 } 400 var lgamma = []fi{ 401 {3.146492141244545774319734e+00, 1}, 402 {8.003414490659126375852113e+00, 1}, 403 {1.517575735509779707488106e+00, -1}, 404 {-2.588480028182145853558748e-01, 1}, 405 {1.1989897050205555002007985e+01, 1}, 406 {6.262899811091257519386906e-01, 1}, 407 {3.5287924899091566764846037e+00, 1}, 408 {4.5725644770161182299423372e-01, 1}, 409 {-6.363667087767961257654854e-02, 1}, 410 {-1.077385130910300066425564e+01, -1}, 411 } 412 var log = []float64{ 413 1.605231462693062999102599e+00, 414 2.0462560018708770653153909e+00, 415 -1.2841708730962657801275038e+00, 416 1.6115563905281545116286206e+00, 417 2.2655365644872016636317461e+00, 418 1.0737652208918379856272735e+00, 419 1.6542360106073546632707956e+00, 420 1.0035467127723465801264487e+00, 421 6.0174879014578057187016475e-01, 422 2.161703872847352815363655e+00, 423 } 424 var logb = []float64{ 425 2.0000000000000000e+00, 426 2.0000000000000000e+00, 427 -2.0000000000000000e+00, 428 2.0000000000000000e+00, 429 3.0000000000000000e+00, 430 1.0000000000000000e+00, 431 2.0000000000000000e+00, 432 1.0000000000000000e+00, 433 0.0000000000000000e+00, 434 3.0000000000000000e+00, 435 } 436 var log10 = []float64{ 437 6.9714316642508290997617083e-01, 438 8.886776901739320576279124e-01, 439 -5.5770832400658929815908236e-01, 440 6.998900476822994346229723e-01, 441 9.8391002850684232013281033e-01, 442 4.6633031029295153334285302e-01, 443 7.1842557117242328821552533e-01, 444 4.3583479968917773161304553e-01, 445 2.6133617905227038228626834e-01, 446 9.3881606348649405716214241e-01, 447 } 448 var log1p = []float64{ 449 4.8590257759797794104158205e-02, 450 7.4540265965225865330849141e-02, 451 -2.7726407903942672823234024e-03, 452 -5.1404917651627649094953380e-02, 453 9.1998280672258624681335010e-02, 454 2.8843762576593352865894824e-02, 455 5.0969534581863707268992645e-02, 456 2.6913947602193238458458594e-02, 457 1.8088493239630770262045333e-02, 458 -9.0865245631588989681559268e-02, 459 } 460 var log2 = []float64{ 461 2.3158594707062190618898251e+00, 462 2.9521233862883917703341018e+00, 463 -1.8526669502700329984917062e+00, 464 2.3249844127278861543568029e+00, 465 3.268478366538305087466309e+00, 466 1.5491157592596970278166492e+00, 467 2.3865580889631732407886495e+00, 468 1.447811865817085365540347e+00, 469 8.6813999540425116282815557e-01, 470 3.118679457227342224364709e+00, 471 } 472 var modf = [][2]float64{ 473 {4.0000000000000000e+00, 9.7901192488367350108546816e-01}, 474 {7.0000000000000000e+00, 7.3887247457810456552351752e-01}, 475 {Copysign(0, -1), -2.7688005719200159404635997e-01}, 476 {-5.0000000000000000e+00, -1.060361827107492160848778e-02}, 477 {9.0000000000000000e+00, 6.3629370719841737980004837e-01}, 478 {2.0000000000000000e+00, 9.2637723924396464525443662e-01}, 479 {5.0000000000000000e+00, 2.2908343145930665230025625e-01}, 480 {2.0000000000000000e+00, 7.2793991043601025126008608e-01}, 481 {1.0000000000000000e+00, 8.2530809168085506044576505e-01}, 482 {-8.0000000000000000e+00, -6.8592476857560136238589621e-01}, 483 } 484 var nextafter32 = []float32{ 485 4.979012489318848e+00, 486 7.738873004913330e+00, 487 -2.768800258636475e-01, 488 -5.010602951049805e+00, 489 9.636294364929199e+00, 490 2.926377534866333e+00, 491 5.229084014892578e+00, 492 2.727940082550049e+00, 493 1.825308203697205e+00, 494 -8.685923576354980e+00, 495 } 496 var nextafter64 = []float64{ 497 4.97901192488367438926388786e+00, 498 7.73887247457810545370193722e+00, 499 -2.7688005719200153853520874e-01, 500 -5.01060361827107403343006808e+00, 501 9.63629370719841915615688777e+00, 502 2.92637723924396508934364647e+00, 503 5.22908343145930754047867595e+00, 504 2.72793991043601069534929593e+00, 505 1.82530809168085528249036997e+00, 506 -8.68592476857559958602905681e+00, 507 } 508 var pow = []float64{ 509 9.5282232631648411840742957e+04, 510 5.4811599352999901232411871e+07, 511 5.2859121715894396531132279e-01, 512 9.7587991957286474464259698e-06, 513 4.328064329346044846740467e+09, 514 8.4406761805034547437659092e+02, 515 1.6946633276191194947742146e+05, 516 5.3449040147551939075312879e+02, 517 6.688182138451414936380374e+01, 518 2.0609869004248742886827439e-09, 519 } 520 var remainder = []float64{ 521 4.197615023265299782906368e-02, 522 2.261127525421895434476482e+00, 523 3.231794108794261433104108e-02, 524 -2.120723654214984321697556e-02, 525 3.637062928015826201999516e-01, 526 1.220868282268106064236690e+00, 527 -4.581668629186133046005125e-01, 528 -9.117596417440410050403443e-01, 529 8.734595415957246977711748e-01, 530 1.314075231424398637614104e+00, 531 } 532 var round = []float64{ 533 5, 534 8, 535 Copysign(0, -1), 536 -5, 537 10, 538 3, 539 5, 540 3, 541 2, 542 -9, 543 } 544 var signbit = []bool{ 545 false, 546 false, 547 true, 548 true, 549 false, 550 false, 551 false, 552 false, 553 false, 554 true, 555 } 556 var sin = []float64{ 557 -9.6466616586009283766724726e-01, 558 9.9338225271646545763467022e-01, 559 -2.7335587039794393342449301e-01, 560 9.5586257685042792878173752e-01, 561 -2.099421066779969164496634e-01, 562 2.135578780799860532750616e-01, 563 -8.694568971167362743327708e-01, 564 4.019566681155577786649878e-01, 565 9.6778633541687993721617774e-01, 566 -6.734405869050344734943028e-01, 567 } 568 569 // Results for 100000 * Pi + vf[i] 570 var sinLarge = []float64{ 571 -9.646661658548936063912e-01, 572 9.933822527198506903752e-01, 573 -2.7335587036246899796e-01, 574 9.55862576853689321268e-01, 575 -2.099421066862688873691e-01, 576 2.13557878070308981163e-01, 577 -8.694568970959221300497e-01, 578 4.01956668098863248917e-01, 579 9.67786335404528727927e-01, 580 -6.7344058693131973066e-01, 581 } 582 var sinh = []float64{ 583 7.2661916084208532301448439e+01, 584 1.1479409110035194500526446e+03, 585 -2.8043136512812518927312641e-01, 586 -7.499429091181587232835164e+01, 587 7.6552466042906758523925934e+03, 588 9.3031583421672014313789064e+00, 589 9.330815755828109072810322e+01, 590 7.6179893137269146407361477e+00, 591 3.021769180549615819524392e+00, 592 -2.95950575724449499189888e+03, 593 } 594 var sqrt = []float64{ 595 2.2313699659365484748756904e+00, 596 2.7818829009464263511285458e+00, 597 5.2619393496314796848143251e-01, 598 2.2384377628763938724244104e+00, 599 3.1042380236055381099288487e+00, 600 1.7106657298385224403917771e+00, 601 2.286718922705479046148059e+00, 602 1.6516476350711159636222979e+00, 603 1.3510396336454586262419247e+00, 604 2.9471892997524949215723329e+00, 605 } 606 var tan = []float64{ 607 -3.661316565040227801781974e+00, 608 8.64900232648597589369854e+00, 609 -2.8417941955033612725238097e-01, 610 3.253290185974728640827156e+00, 611 2.147275640380293804770778e-01, 612 -2.18600910711067004921551e-01, 613 -1.760002817872367935518928e+00, 614 -4.389808914752818126249079e-01, 615 -3.843885560201130679995041e+00, 616 9.10988793377685105753416e-01, 617 } 618 619 // Results for 100000 * Pi + vf[i] 620 var tanLarge = []float64{ 621 -3.66131656475596512705e+00, 622 8.6490023287202547927e+00, 623 -2.841794195104782406e-01, 624 3.2532901861033120983e+00, 625 2.14727564046880001365e-01, 626 -2.18600910700688062874e-01, 627 -1.760002817699722747043e+00, 628 -4.38980891453536115952e-01, 629 -3.84388555942723509071e+00, 630 9.1098879344275101051e-01, 631 } 632 var tanh = []float64{ 633 9.9990531206936338549262119e-01, 634 9.9999962057085294197613294e-01, 635 -2.7001505097318677233756845e-01, 636 -9.9991110943061718603541401e-01, 637 9.9999999146798465745022007e-01, 638 9.9427249436125236705001048e-01, 639 9.9994257600983138572705076e-01, 640 9.9149409509772875982054701e-01, 641 9.4936501296239685514466577e-01, 642 -9.9999994291374030946055701e-01, 643 } 644 var trunc = []float64{ 645 4.0000000000000000e+00, 646 7.0000000000000000e+00, 647 -0.0000000000000000e+00, 648 -5.0000000000000000e+00, 649 9.0000000000000000e+00, 650 2.0000000000000000e+00, 651 5.0000000000000000e+00, 652 2.0000000000000000e+00, 653 1.0000000000000000e+00, 654 -8.0000000000000000e+00, 655 } 656 var y0 = []float64{ 657 -3.053399153780788357534855e-01, 658 1.7437227649515231515503649e-01, 659 -8.6221781263678836910392572e-01, 660 -3.100664880987498407872839e-01, 661 1.422200649300982280645377e-01, 662 4.000004067997901144239363e-01, 663 -3.3340749753099352392332536e-01, 664 4.5399790746668954555205502e-01, 665 4.8290004112497761007536522e-01, 666 2.7036697826604756229601611e-01, 667 } 668 var y1 = []float64{ 669 0.15494213737457922210218611, 670 -0.2165955142081145245075746, 671 -2.4644949631241895201032829, 672 0.1442740489541836405154505, 673 0.2215379960518984777080163, 674 0.3038800915160754150565448, 675 0.0691107642452362383808547, 676 0.2380116417809914424860165, 677 -0.20849492979459761009678934, 678 0.0242503179793232308250804, 679 } 680 var y2 = []float64{ 681 0.3675780219390303613394936, 682 -0.23034826393250119879267257, 683 -16.939677983817727205631397, 684 0.367653980523052152867791, 685 -0.0962401471767804440353136, 686 -0.1923169356184851105200523, 687 0.35984072054267882391843766, 688 -0.2794987252299739821654982, 689 -0.7113490692587462579757954, 690 -0.2647831587821263302087457, 691 } 692 var yM3 = []float64{ 693 -0.14035984421094849100895341, 694 -0.097535139617792072703973, 695 242.25775994555580176377379, 696 -0.1492267014802818619511046, 697 0.26148702629155918694500469, 698 0.56675383593895176530394248, 699 -0.206150264009006981070575, 700 0.64784284687568332737963658, 701 1.3503631555901938037008443, 702 0.1461869756579956803341844, 703 } 704 705 // arguments and expected results for special cases 706 var vfacosSC = []float64{ 707 -Pi, 708 1, 709 Pi, 710 NaN(), 711 } 712 var acosSC = []float64{ 713 NaN(), 714 0, 715 NaN(), 716 NaN(), 717 } 718 719 var vfacoshSC = []float64{ 720 Inf(-1), 721 0.5, 722 1, 723 Inf(1), 724 NaN(), 725 } 726 var acoshSC = []float64{ 727 NaN(), 728 NaN(), 729 0, 730 Inf(1), 731 NaN(), 732 } 733 734 var vfasinSC = []float64{ 735 -Pi, 736 Copysign(0, -1), 737 0, 738 Pi, 739 NaN(), 740 } 741 var asinSC = []float64{ 742 NaN(), 743 Copysign(0, -1), 744 0, 745 NaN(), 746 NaN(), 747 } 748 749 var vfasinhSC = []float64{ 750 Inf(-1), 751 Copysign(0, -1), 752 0, 753 Inf(1), 754 NaN(), 755 } 756 var asinhSC = []float64{ 757 Inf(-1), 758 Copysign(0, -1), 759 0, 760 Inf(1), 761 NaN(), 762 } 763 764 var vfatanSC = []float64{ 765 Inf(-1), 766 Copysign(0, -1), 767 0, 768 Inf(1), 769 NaN(), 770 } 771 var atanSC = []float64{ 772 -Pi / 2, 773 Copysign(0, -1), 774 0, 775 Pi / 2, 776 NaN(), 777 } 778 779 var vfatanhSC = []float64{ 780 Inf(-1), 781 -Pi, 782 -1, 783 Copysign(0, -1), 784 0, 785 1, 786 Pi, 787 Inf(1), 788 NaN(), 789 } 790 var atanhSC = []float64{ 791 NaN(), 792 NaN(), 793 Inf(-1), 794 Copysign(0, -1), 795 0, 796 Inf(1), 797 NaN(), 798 NaN(), 799 NaN(), 800 } 801 var vfatan2SC = [][2]float64{ 802 {Inf(-1), Inf(-1)}, 803 {Inf(-1), -Pi}, 804 {Inf(-1), 0}, 805 {Inf(-1), +Pi}, 806 {Inf(-1), Inf(1)}, 807 {Inf(-1), NaN()}, 808 {-Pi, Inf(-1)}, 809 {-Pi, 0}, 810 {-Pi, Inf(1)}, 811 {-Pi, NaN()}, 812 {Copysign(0, -1), Inf(-1)}, 813 {Copysign(0, -1), -Pi}, 814 {Copysign(0, -1), Copysign(0, -1)}, 815 {Copysign(0, -1), 0}, 816 {Copysign(0, -1), +Pi}, 817 {Copysign(0, -1), Inf(1)}, 818 {Copysign(0, -1), NaN()}, 819 {0, Inf(-1)}, 820 {0, -Pi}, 821 {0, Copysign(0, -1)}, 822 {0, 0}, 823 {0, +Pi}, 824 {0, Inf(1)}, 825 {0, NaN()}, 826 {+Pi, Inf(-1)}, 827 {+Pi, 0}, 828 {+Pi, Inf(1)}, 829 {+Pi, NaN()}, 830 {Inf(1), Inf(-1)}, 831 {Inf(1), -Pi}, 832 {Inf(1), 0}, 833 {Inf(1), +Pi}, 834 {Inf(1), Inf(1)}, 835 {Inf(1), NaN()}, 836 {NaN(), NaN()}, 837 } 838 var atan2SC = []float64{ 839 -3 * Pi / 4, // atan2(-Inf, -Inf) 840 -Pi / 2, // atan2(-Inf, -Pi) 841 -Pi / 2, // atan2(-Inf, +0) 842 -Pi / 2, // atan2(-Inf, +Pi) 843 -Pi / 4, // atan2(-Inf, +Inf) 844 NaN(), // atan2(-Inf, NaN) 845 -Pi, // atan2(-Pi, -Inf) 846 -Pi / 2, // atan2(-Pi, +0) 847 Copysign(0, -1), // atan2(-Pi, Inf) 848 NaN(), // atan2(-Pi, NaN) 849 -Pi, // atan2(-0, -Inf) 850 -Pi, // atan2(-0, -Pi) 851 -Pi, // atan2(-0, -0) 852 Copysign(0, -1), // atan2(-0, +0) 853 Copysign(0, -1), // atan2(-0, +Pi) 854 Copysign(0, -1), // atan2(-0, +Inf) 855 NaN(), // atan2(-0, NaN) 856 Pi, // atan2(+0, -Inf) 857 Pi, // atan2(+0, -Pi) 858 Pi, // atan2(+0, -0) 859 0, // atan2(+0, +0) 860 0, // atan2(+0, +Pi) 861 0, // atan2(+0, +Inf) 862 NaN(), // atan2(+0, NaN) 863 Pi, // atan2(+Pi, -Inf) 864 Pi / 2, // atan2(+Pi, +0) 865 0, // atan2(+Pi, +Inf) 866 NaN(), // atan2(+Pi, NaN) 867 3 * Pi / 4, // atan2(+Inf, -Inf) 868 Pi / 2, // atan2(+Inf, -Pi) 869 Pi / 2, // atan2(+Inf, +0) 870 Pi / 2, // atan2(+Inf, +Pi) 871 Pi / 4, // atan2(+Inf, +Inf) 872 NaN(), // atan2(+Inf, NaN) 873 NaN(), // atan2(NaN, NaN) 874 } 875 876 var vfcbrtSC = []float64{ 877 Inf(-1), 878 Copysign(0, -1), 879 0, 880 Inf(1), 881 NaN(), 882 } 883 var cbrtSC = []float64{ 884 Inf(-1), 885 Copysign(0, -1), 886 0, 887 Inf(1), 888 NaN(), 889 } 890 891 var vfceilSC = []float64{ 892 Inf(-1), 893 Copysign(0, -1), 894 0, 895 Inf(1), 896 NaN(), 897 } 898 var ceilSC = []float64{ 899 Inf(-1), 900 Copysign(0, -1), 901 0, 902 Inf(1), 903 NaN(), 904 } 905 906 var vfcopysignSC = []float64{ 907 Inf(-1), 908 Inf(1), 909 NaN(), 910 } 911 var copysignSC = []float64{ 912 Inf(-1), 913 Inf(-1), 914 NaN(), 915 } 916 917 var vfcosSC = []float64{ 918 Inf(-1), 919 Inf(1), 920 NaN(), 921 } 922 var cosSC = []float64{ 923 NaN(), 924 NaN(), 925 NaN(), 926 } 927 928 var vfcoshSC = []float64{ 929 Inf(-1), 930 Copysign(0, -1), 931 0, 932 Inf(1), 933 NaN(), 934 } 935 var coshSC = []float64{ 936 Inf(1), 937 1, 938 1, 939 Inf(1), 940 NaN(), 941 } 942 943 var vferfSC = []float64{ 944 Inf(-1), 945 Copysign(0, -1), 946 0, 947 Inf(1), 948 NaN(), 949 } 950 var erfSC = []float64{ 951 -1, 952 Copysign(0, -1), 953 0, 954 1, 955 NaN(), 956 } 957 958 var vferfcSC = []float64{ 959 Inf(-1), 960 Inf(1), 961 NaN(), 962 } 963 var erfcSC = []float64{ 964 2, 965 0, 966 NaN(), 967 } 968 969 var vferfinvSC = []float64{ 970 1, 971 -1, 972 0, 973 Inf(-1), 974 Inf(1), 975 NaN(), 976 } 977 var erfinvSC = []float64{ 978 Inf(+1), 979 Inf(-1), 980 0, 981 NaN(), 982 NaN(), 983 NaN(), 984 } 985 986 var vferfcinvSC = []float64{ 987 0, 988 2, 989 1, 990 Inf(1), 991 Inf(-1), 992 NaN(), 993 } 994 var erfcinvSC = []float64{ 995 Inf(+1), 996 Inf(-1), 997 0, 998 NaN(), 999 NaN(), 1000 NaN(), 1001 } 1002 1003 var vfexpSC = []float64{ 1004 Inf(-1), 1005 -2000, 1006 2000, 1007 Inf(1), 1008 NaN(), 1009 // smallest float64 that overflows Exp(x) 1010 7.097827128933841e+02, 1011 // Issue 18912 1012 1.48852223e+09, 1013 1.4885222e+09, 1014 1, 1015 } 1016 var expSC = []float64{ 1017 0, 1018 0, 1019 Inf(1), 1020 Inf(1), 1021 NaN(), 1022 Inf(1), 1023 Inf(1), 1024 Inf(1), 1025 2.718281828459045, 1026 } 1027 1028 var vfexp2SC = []float64{ 1029 Inf(-1), 1030 -2000, 1031 2000, 1032 Inf(1), 1033 NaN(), 1034 // smallest float64 that overflows Exp2(x) 1035 1024, 1036 } 1037 var exp2SC = []float64{ 1038 0, 1039 0, 1040 Inf(1), 1041 Inf(1), 1042 NaN(), 1043 Inf(1), 1044 } 1045 1046 var vfexpm1SC = []float64{ 1047 Inf(-1), 1048 -710, 1049 Copysign(0, -1), 1050 0, 1051 710, 1052 Inf(1), 1053 NaN(), 1054 } 1055 var expm1SC = []float64{ 1056 -1, 1057 -1, 1058 Copysign(0, -1), 1059 0, 1060 Inf(1), 1061 Inf(1), 1062 NaN(), 1063 } 1064 1065 var vffabsSC = []float64{ 1066 Inf(-1), 1067 Copysign(0, -1), 1068 0, 1069 Inf(1), 1070 NaN(), 1071 } 1072 var fabsSC = []float64{ 1073 Inf(1), 1074 0, 1075 0, 1076 Inf(1), 1077 NaN(), 1078 } 1079 1080 var vffdimSC = [][2]float64{ 1081 {Inf(-1), Inf(-1)}, 1082 {Inf(-1), Inf(1)}, 1083 {Inf(-1), NaN()}, 1084 {Copysign(0, -1), Copysign(0, -1)}, 1085 {Copysign(0, -1), 0}, 1086 {0, Copysign(0, -1)}, 1087 {0, 0}, 1088 {Inf(1), Inf(-1)}, 1089 {Inf(1), Inf(1)}, 1090 {Inf(1), NaN()}, 1091 {NaN(), Inf(-1)}, 1092 {NaN(), Copysign(0, -1)}, 1093 {NaN(), 0}, 1094 {NaN(), Inf(1)}, 1095 {NaN(), NaN()}, 1096 } 1097 var nan = Float64frombits(0xFFF8000000000000) // SSE2 DIVSD 0/0 1098 var vffdim2SC = [][2]float64{ 1099 {Inf(-1), Inf(-1)}, 1100 {Inf(-1), Inf(1)}, 1101 {Inf(-1), nan}, 1102 {Copysign(0, -1), Copysign(0, -1)}, 1103 {Copysign(0, -1), 0}, 1104 {0, Copysign(0, -1)}, 1105 {0, 0}, 1106 {Inf(1), Inf(-1)}, 1107 {Inf(1), Inf(1)}, 1108 {Inf(1), nan}, 1109 {nan, Inf(-1)}, 1110 {nan, Copysign(0, -1)}, 1111 {nan, 0}, 1112 {nan, Inf(1)}, 1113 {nan, nan}, 1114 } 1115 var fdimSC = []float64{ 1116 NaN(), 1117 0, 1118 NaN(), 1119 0, 1120 0, 1121 0, 1122 0, 1123 Inf(1), 1124 NaN(), 1125 NaN(), 1126 NaN(), 1127 NaN(), 1128 NaN(), 1129 NaN(), 1130 NaN(), 1131 } 1132 var fmaxSC = []float64{ 1133 Inf(-1), 1134 Inf(1), 1135 NaN(), 1136 Copysign(0, -1), 1137 0, 1138 0, 1139 0, 1140 Inf(1), 1141 Inf(1), 1142 Inf(1), 1143 NaN(), 1144 NaN(), 1145 NaN(), 1146 Inf(1), 1147 NaN(), 1148 } 1149 var fminSC = []float64{ 1150 Inf(-1), 1151 Inf(-1), 1152 Inf(-1), 1153 Copysign(0, -1), 1154 Copysign(0, -1), 1155 Copysign(0, -1), 1156 0, 1157 Inf(-1), 1158 Inf(1), 1159 NaN(), 1160 Inf(-1), 1161 NaN(), 1162 NaN(), 1163 NaN(), 1164 NaN(), 1165 } 1166 1167 var vffmodSC = [][2]float64{ 1168 {Inf(-1), Inf(-1)}, 1169 {Inf(-1), -Pi}, 1170 {Inf(-1), 0}, 1171 {Inf(-1), Pi}, 1172 {Inf(-1), Inf(1)}, 1173 {Inf(-1), NaN()}, 1174 {-Pi, Inf(-1)}, 1175 {-Pi, 0}, 1176 {-Pi, Inf(1)}, 1177 {-Pi, NaN()}, 1178 {Copysign(0, -1), Inf(-1)}, 1179 {Copysign(0, -1), 0}, 1180 {Copysign(0, -1), Inf(1)}, 1181 {Copysign(0, -1), NaN()}, 1182 {0, Inf(-1)}, 1183 {0, 0}, 1184 {0, Inf(1)}, 1185 {0, NaN()}, 1186 {Pi, Inf(-1)}, 1187 {Pi, 0}, 1188 {Pi, Inf(1)}, 1189 {Pi, NaN()}, 1190 {Inf(1), Inf(-1)}, 1191 {Inf(1), -Pi}, 1192 {Inf(1), 0}, 1193 {Inf(1), Pi}, 1194 {Inf(1), Inf(1)}, 1195 {Inf(1), NaN()}, 1196 {NaN(), Inf(-1)}, 1197 {NaN(), -Pi}, 1198 {NaN(), 0}, 1199 {NaN(), Pi}, 1200 {NaN(), Inf(1)}, 1201 {NaN(), NaN()}, 1202 } 1203 var fmodSC = []float64{ 1204 NaN(), // fmod(-Inf, -Inf) 1205 NaN(), // fmod(-Inf, -Pi) 1206 NaN(), // fmod(-Inf, 0) 1207 NaN(), // fmod(-Inf, Pi) 1208 NaN(), // fmod(-Inf, +Inf) 1209 NaN(), // fmod(-Inf, NaN) 1210 -Pi, // fmod(-Pi, -Inf) 1211 NaN(), // fmod(-Pi, 0) 1212 -Pi, // fmod(-Pi, +Inf) 1213 NaN(), // fmod(-Pi, NaN) 1214 Copysign(0, -1), // fmod(-0, -Inf) 1215 NaN(), // fmod(-0, 0) 1216 Copysign(0, -1), // fmod(-0, Inf) 1217 NaN(), // fmod(-0, NaN) 1218 0, // fmod(0, -Inf) 1219 NaN(), // fmod(0, 0) 1220 0, // fmod(0, +Inf) 1221 NaN(), // fmod(0, NaN) 1222 Pi, // fmod(Pi, -Inf) 1223 NaN(), // fmod(Pi, 0) 1224 Pi, // fmod(Pi, +Inf) 1225 NaN(), // fmod(Pi, NaN) 1226 NaN(), // fmod(+Inf, -Inf) 1227 NaN(), // fmod(+Inf, -Pi) 1228 NaN(), // fmod(+Inf, 0) 1229 NaN(), // fmod(+Inf, Pi) 1230 NaN(), // fmod(+Inf, +Inf) 1231 NaN(), // fmod(+Inf, NaN) 1232 NaN(), // fmod(NaN, -Inf) 1233 NaN(), // fmod(NaN, -Pi) 1234 NaN(), // fmod(NaN, 0) 1235 NaN(), // fmod(NaN, Pi) 1236 NaN(), // fmod(NaN, +Inf) 1237 NaN(), // fmod(NaN, NaN) 1238 } 1239 1240 var vffrexpSC = []float64{ 1241 Inf(-1), 1242 Copysign(0, -1), 1243 0, 1244 Inf(1), 1245 NaN(), 1246 } 1247 var frexpSC = []fi{ 1248 {Inf(-1), 0}, 1249 {Copysign(0, -1), 0}, 1250 {0, 0}, 1251 {Inf(1), 0}, 1252 {NaN(), 0}, 1253 } 1254 1255 var vfgamma = [][2]float64{ 1256 {Inf(1), Inf(1)}, 1257 {Inf(-1), NaN()}, 1258 {0, Inf(1)}, 1259 {Copysign(0, -1), Inf(-1)}, 1260 {NaN(), NaN()}, 1261 {-1, NaN()}, 1262 {-2, NaN()}, 1263 {-3, NaN()}, 1264 {-1e16, NaN()}, 1265 {-1e300, NaN()}, 1266 {1.7e308, Inf(1)}, 1267 1268 // Test inputs inspired by Python test suite. 1269 // Outputs computed at high precision by PARI/GP. 1270 // If recomputing table entries, be careful to use 1271 // high-precision (%.1000g) formatting of the float64 inputs. 1272 // For example, -2.0000000000000004 is the float64 with exact value 1273 // -2.00000000000000044408920985626161695, and 1274 // gamma(-2.0000000000000004) = -1249999999999999.5386078562728167651513, while 1275 // gamma(-2.00000000000000044408920985626161695) = -1125899906826907.2044875028130093136826. 1276 // Thus the table lists -1.1258999068426235e+15 as the answer. 1277 {0.5, 1.772453850905516}, 1278 {1.5, 0.886226925452758}, 1279 {2.5, 1.329340388179137}, 1280 {3.5, 3.3233509704478426}, 1281 {-0.5, -3.544907701811032}, 1282 {-1.5, 2.363271801207355}, 1283 {-2.5, -0.9453087204829419}, 1284 {-3.5, 0.2700882058522691}, 1285 {0.1, 9.51350769866873}, 1286 {0.01, 99.4325851191506}, 1287 {1e-08, 9.999999942278434e+07}, 1288 {1e-16, 1e+16}, 1289 {0.001, 999.4237724845955}, 1290 {1e-16, 1e+16}, 1291 {1e-308, 1e+308}, 1292 {5.6e-309, 1.7857142857142864e+308}, 1293 {5.5e-309, Inf(1)}, 1294 {1e-309, Inf(1)}, 1295 {1e-323, Inf(1)}, 1296 {5e-324, Inf(1)}, 1297 {-0.1, -10.686287021193193}, 1298 {-0.01, -100.58719796441078}, 1299 {-1e-08, -1.0000000057721567e+08}, 1300 {-1e-16, -1e+16}, 1301 {-0.001, -1000.5782056293586}, 1302 {-1e-16, -1e+16}, 1303 {-1e-308, -1e+308}, 1304 {-5.6e-309, -1.7857142857142864e+308}, 1305 {-5.5e-309, Inf(-1)}, 1306 {-1e-309, Inf(-1)}, 1307 {-1e-323, Inf(-1)}, 1308 {-5e-324, Inf(-1)}, 1309 {-0.9999999999999999, -9.007199254740992e+15}, 1310 {-1.0000000000000002, 4.5035996273704955e+15}, 1311 {-1.9999999999999998, 2.2517998136852485e+15}, 1312 {-2.0000000000000004, -1.1258999068426235e+15}, 1313 {-100.00000000000001, -7.540083334883109e-145}, 1314 {-99.99999999999999, 7.540083334884096e-145}, 1315 {17, 2.0922789888e+13}, 1316 {171, 7.257415615307999e+306}, 1317 {171.6, 1.5858969096672565e+308}, 1318 {171.624, 1.7942117599248104e+308}, 1319 {171.625, Inf(1)}, 1320 {172, Inf(1)}, 1321 {2000, Inf(1)}, 1322 {-100.5, -3.3536908198076787e-159}, 1323 {-160.5, -5.255546447007829e-286}, 1324 {-170.5, -3.3127395215386074e-308}, 1325 {-171.5, 1.9316265431712e-310}, 1326 {-176.5, -1.196e-321}, 1327 {-177.5, 5e-324}, 1328 {-178.5, Copysign(0, -1)}, 1329 {-179.5, 0}, 1330 {-201.0001, 0}, 1331 {-202.9999, Copysign(0, -1)}, 1332 {-1000.5, Copysign(0, -1)}, 1333 {-1.0000000003e+09, Copysign(0, -1)}, 1334 {-4.5035996273704955e+15, 0}, 1335 {-63.349078729022985, 4.177797167776188e-88}, 1336 {-127.45117632943295, 1.183111089623681e-214}, 1337 } 1338 1339 var vfhypotSC = [][2]float64{ 1340 {Inf(-1), Inf(-1)}, 1341 {Inf(-1), 0}, 1342 {Inf(-1), Inf(1)}, 1343 {Inf(-1), NaN()}, 1344 {Copysign(0, -1), Copysign(0, -1)}, 1345 {Copysign(0, -1), 0}, 1346 {0, Copysign(0, -1)}, 1347 {0, 0}, // +0, +0 1348 {0, Inf(-1)}, 1349 {0, Inf(1)}, 1350 {0, NaN()}, 1351 {Inf(1), Inf(-1)}, 1352 {Inf(1), 0}, 1353 {Inf(1), Inf(1)}, 1354 {Inf(1), NaN()}, 1355 {NaN(), Inf(-1)}, 1356 {NaN(), 0}, 1357 {NaN(), Inf(1)}, 1358 {NaN(), NaN()}, 1359 } 1360 var hypotSC = []float64{ 1361 Inf(1), 1362 Inf(1), 1363 Inf(1), 1364 Inf(1), 1365 0, 1366 0, 1367 0, 1368 0, 1369 Inf(1), 1370 Inf(1), 1371 NaN(), 1372 Inf(1), 1373 Inf(1), 1374 Inf(1), 1375 Inf(1), 1376 Inf(1), 1377 NaN(), 1378 Inf(1), 1379 NaN(), 1380 } 1381 1382 var ilogbSC = []int{ 1383 MaxInt32, 1384 MinInt32, 1385 MaxInt32, 1386 MaxInt32, 1387 } 1388 1389 var vfj0SC = []float64{ 1390 Inf(-1), 1391 0, 1392 Inf(1), 1393 NaN(), 1394 } 1395 var j0SC = []float64{ 1396 0, 1397 1, 1398 0, 1399 NaN(), 1400 } 1401 var j1SC = []float64{ 1402 0, 1403 0, 1404 0, 1405 NaN(), 1406 } 1407 var j2SC = []float64{ 1408 0, 1409 0, 1410 0, 1411 NaN(), 1412 } 1413 var jM3SC = []float64{ 1414 0, 1415 0, 1416 0, 1417 NaN(), 1418 } 1419 1420 var vfldexpSC = []fi{ 1421 {0, 0}, 1422 {0, -1075}, 1423 {0, 1024}, 1424 {Copysign(0, -1), 0}, 1425 {Copysign(0, -1), -1075}, 1426 {Copysign(0, -1), 1024}, 1427 {Inf(1), 0}, 1428 {Inf(1), -1024}, 1429 {Inf(-1), 0}, 1430 {Inf(-1), -1024}, 1431 {NaN(), -1024}, 1432 {10, int(1) << (uint64(unsafe.Sizeof(0)-1) * 8)}, 1433 {10, -(int(1) << (uint64(unsafe.Sizeof(0)-1) * 8))}, 1434 } 1435 var ldexpSC = []float64{ 1436 0, 1437 0, 1438 0, 1439 Copysign(0, -1), 1440 Copysign(0, -1), 1441 Copysign(0, -1), 1442 Inf(1), 1443 Inf(1), 1444 Inf(-1), 1445 Inf(-1), 1446 NaN(), 1447 Inf(1), 1448 0, 1449 } 1450 1451 var vflgammaSC = []float64{ 1452 Inf(-1), 1453 -3, 1454 0, 1455 1, 1456 2, 1457 Inf(1), 1458 NaN(), 1459 } 1460 var lgammaSC = []fi{ 1461 {Inf(-1), 1}, 1462 {Inf(1), 1}, 1463 {Inf(1), 1}, 1464 {0, 1}, 1465 {0, 1}, 1466 {Inf(1), 1}, 1467 {NaN(), 1}, 1468 } 1469 1470 var vflogSC = []float64{ 1471 Inf(-1), 1472 -Pi, 1473 Copysign(0, -1), 1474 0, 1475 1, 1476 Inf(1), 1477 NaN(), 1478 } 1479 var logSC = []float64{ 1480 NaN(), 1481 NaN(), 1482 Inf(-1), 1483 Inf(-1), 1484 0, 1485 Inf(1), 1486 NaN(), 1487 } 1488 1489 var vflogbSC = []float64{ 1490 Inf(-1), 1491 0, 1492 Inf(1), 1493 NaN(), 1494 } 1495 var logbSC = []float64{ 1496 Inf(1), 1497 Inf(-1), 1498 Inf(1), 1499 NaN(), 1500 } 1501 1502 var vflog1pSC = []float64{ 1503 Inf(-1), 1504 -Pi, 1505 -1, 1506 Copysign(0, -1), 1507 0, 1508 Inf(1), 1509 NaN(), 1510 } 1511 var log1pSC = []float64{ 1512 NaN(), 1513 NaN(), 1514 Inf(-1), 1515 Copysign(0, -1), 1516 0, 1517 Inf(1), 1518 NaN(), 1519 } 1520 1521 var vfmodfSC = []float64{ 1522 Inf(-1), 1523 Copysign(0, -1), 1524 Inf(1), 1525 NaN(), 1526 } 1527 var modfSC = [][2]float64{ 1528 {Inf(-1), NaN()}, // [2]float64{Copysign(0, -1), Inf(-1)}, 1529 {Copysign(0, -1), Copysign(0, -1)}, 1530 {Inf(1), NaN()}, // [2]float64{0, Inf(1)}, 1531 {NaN(), NaN()}, 1532 } 1533 1534 var vfnextafter32SC = [][2]float32{ 1535 {0, 0}, 1536 {0, float32(Copysign(0, -1))}, 1537 {0, -1}, 1538 {0, float32(NaN())}, 1539 {float32(Copysign(0, -1)), 1}, 1540 {float32(Copysign(0, -1)), 0}, 1541 {float32(Copysign(0, -1)), float32(Copysign(0, -1))}, 1542 {float32(Copysign(0, -1)), -1}, 1543 {float32(NaN()), 0}, 1544 {float32(NaN()), float32(NaN())}, 1545 } 1546 var nextafter32SC = []float32{ 1547 0, 1548 0, 1549 -1.401298464e-45, // Float32frombits(0x80000001) 1550 float32(NaN()), 1551 1.401298464e-45, // Float32frombits(0x00000001) 1552 float32(Copysign(0, -1)), 1553 float32(Copysign(0, -1)), 1554 -1.401298464e-45, // Float32frombits(0x80000001) 1555 float32(NaN()), 1556 float32(NaN()), 1557 } 1558 1559 var vfnextafter64SC = [][2]float64{ 1560 {0, 0}, 1561 {0, Copysign(0, -1)}, 1562 {0, -1}, 1563 {0, NaN()}, 1564 {Copysign(0, -1), 1}, 1565 {Copysign(0, -1), 0}, 1566 {Copysign(0, -1), Copysign(0, -1)}, 1567 {Copysign(0, -1), -1}, 1568 {NaN(), 0}, 1569 {NaN(), NaN()}, 1570 } 1571 var nextafter64SC = []float64{ 1572 0, 1573 0, 1574 -4.9406564584124654418e-324, // Float64frombits(0x8000000000000001) 1575 NaN(), 1576 4.9406564584124654418e-324, // Float64frombits(0x0000000000000001) 1577 Copysign(0, -1), 1578 Copysign(0, -1), 1579 -4.9406564584124654418e-324, // Float64frombits(0x8000000000000001) 1580 NaN(), 1581 NaN(), 1582 } 1583 1584 var vfpowSC = [][2]float64{ 1585 {Inf(-1), -Pi}, 1586 {Inf(-1), -3}, 1587 {Inf(-1), Copysign(0, -1)}, 1588 {Inf(-1), 0}, 1589 {Inf(-1), 1}, 1590 {Inf(-1), 3}, 1591 {Inf(-1), Pi}, 1592 {Inf(-1), NaN()}, 1593 1594 {-Pi, Inf(-1)}, 1595 {-Pi, -Pi}, 1596 {-Pi, Copysign(0, -1)}, 1597 {-Pi, 0}, 1598 {-Pi, 1}, 1599 {-Pi, Pi}, 1600 {-Pi, Inf(1)}, 1601 {-Pi, NaN()}, 1602 1603 {-1, Inf(-1)}, 1604 {-1, Inf(1)}, 1605 {-1, NaN()}, 1606 {-1 / 2, Inf(-1)}, 1607 {-1 / 2, Inf(1)}, 1608 {Copysign(0, -1), Inf(-1)}, 1609 {Copysign(0, -1), -Pi}, 1610 {Copysign(0, -1), -3}, 1611 {Copysign(0, -1), 3}, 1612 {Copysign(0, -1), Pi}, 1613 {Copysign(0, -1), Inf(1)}, 1614 1615 {0, Inf(-1)}, 1616 {0, -Pi}, 1617 {0, -3}, 1618 {0, Copysign(0, -1)}, 1619 {0, 0}, 1620 {0, 3}, 1621 {0, Pi}, 1622 {0, Inf(1)}, 1623 {0, NaN()}, 1624 1625 {1 / 2, Inf(-1)}, 1626 {1 / 2, Inf(1)}, 1627 {1, Inf(-1)}, 1628 {1, Inf(1)}, 1629 {1, NaN()}, 1630 1631 {Pi, Inf(-1)}, 1632 {Pi, Copysign(0, -1)}, 1633 {Pi, 0}, 1634 {Pi, 1}, 1635 {Pi, Inf(1)}, 1636 {Pi, NaN()}, 1637 {Inf(1), -Pi}, 1638 {Inf(1), Copysign(0, -1)}, 1639 {Inf(1), 0}, 1640 {Inf(1), 1}, 1641 {Inf(1), Pi}, 1642 {Inf(1), NaN()}, 1643 {NaN(), -Pi}, 1644 {NaN(), Copysign(0, -1)}, 1645 {NaN(), 0}, 1646 {NaN(), 1}, 1647 {NaN(), Pi}, 1648 {NaN(), NaN()}, 1649 1650 // Issue #7394 overflow checks 1651 {2, float64(1 << 32)}, 1652 {2, -float64(1 << 32)}, 1653 {-2, float64(1<<32 + 1)}, 1654 {1 / 2, float64(1 << 45)}, 1655 {1 / 2, -float64(1 << 45)}, 1656 {Nextafter(1, 2), float64(1 << 63)}, 1657 {Nextafter(1, -2), float64(1 << 63)}, 1658 {Nextafter(-1, 2), float64(1 << 63)}, 1659 {Nextafter(-1, -2), float64(1 << 63)}, 1660 } 1661 var powSC = []float64{ 1662 0, // pow(-Inf, -Pi) 1663 Copysign(0, -1), // pow(-Inf, -3) 1664 1, // pow(-Inf, -0) 1665 1, // pow(-Inf, +0) 1666 Inf(-1), // pow(-Inf, 1) 1667 Inf(-1), // pow(-Inf, 3) 1668 Inf(1), // pow(-Inf, Pi) 1669 NaN(), // pow(-Inf, NaN) 1670 0, // pow(-Pi, -Inf) 1671 NaN(), // pow(-Pi, -Pi) 1672 1, // pow(-Pi, -0) 1673 1, // pow(-Pi, +0) 1674 -Pi, // pow(-Pi, 1) 1675 NaN(), // pow(-Pi, Pi) 1676 Inf(1), // pow(-Pi, +Inf) 1677 NaN(), // pow(-Pi, NaN) 1678 1, // pow(-1, -Inf) IEEE 754-2008 1679 1, // pow(-1, +Inf) IEEE 754-2008 1680 NaN(), // pow(-1, NaN) 1681 Inf(1), // pow(-1/2, -Inf) 1682 0, // pow(-1/2, +Inf) 1683 Inf(1), // pow(-0, -Inf) 1684 Inf(1), // pow(-0, -Pi) 1685 Inf(-1), // pow(-0, -3) IEEE 754-2008 1686 Copysign(0, -1), // pow(-0, 3) IEEE 754-2008 1687 0, // pow(-0, +Pi) 1688 0, // pow(-0, +Inf) 1689 Inf(1), // pow(+0, -Inf) 1690 Inf(1), // pow(+0, -Pi) 1691 Inf(1), // pow(+0, -3) 1692 1, // pow(+0, -0) 1693 1, // pow(+0, +0) 1694 0, // pow(+0, 3) 1695 0, // pow(+0, +Pi) 1696 0, // pow(+0, +Inf) 1697 NaN(), // pow(+0, NaN) 1698 Inf(1), // pow(1/2, -Inf) 1699 0, // pow(1/2, +Inf) 1700 1, // pow(1, -Inf) IEEE 754-2008 1701 1, // pow(1, +Inf) IEEE 754-2008 1702 1, // pow(1, NaN) IEEE 754-2008 1703 0, // pow(+Pi, -Inf) 1704 1, // pow(+Pi, -0) 1705 1, // pow(+Pi, +0) 1706 Pi, // pow(+Pi, 1) 1707 Inf(1), // pow(+Pi, +Inf) 1708 NaN(), // pow(+Pi, NaN) 1709 0, // pow(+Inf, -Pi) 1710 1, // pow(+Inf, -0) 1711 1, // pow(+Inf, +0) 1712 Inf(1), // pow(+Inf, 1) 1713 Inf(1), // pow(+Inf, Pi) 1714 NaN(), // pow(+Inf, NaN) 1715 NaN(), // pow(NaN, -Pi) 1716 1, // pow(NaN, -0) 1717 1, // pow(NaN, +0) 1718 NaN(), // pow(NaN, 1) 1719 NaN(), // pow(NaN, +Pi) 1720 NaN(), // pow(NaN, NaN) 1721 1722 // Issue #7394 overflow checks 1723 Inf(1), // pow(2, float64(1 << 32)) 1724 0, // pow(2, -float64(1 << 32)) 1725 Inf(-1), // pow(-2, float64(1<<32 + 1)) 1726 0, // pow(1/2, float64(1 << 45)) 1727 Inf(1), // pow(1/2, -float64(1 << 45)) 1728 Inf(1), // pow(Nextafter(1, 2), float64(1 << 63)) 1729 0, // pow(Nextafter(1, -2), float64(1 << 63)) 1730 0, // pow(Nextafter(-1, 2), float64(1 << 63)) 1731 Inf(1), // pow(Nextafter(-1, -2), float64(1 << 63)) 1732 } 1733 1734 var vfpow10SC = []int{ 1735 MinInt32, 1736 -324, 1737 -323, 1738 -50, 1739 -22, 1740 -1, 1741 0, 1742 1, 1743 22, 1744 50, 1745 100, 1746 200, 1747 308, 1748 309, 1749 MaxInt32, 1750 } 1751 1752 var pow10SC = []float64{ 1753 0, // pow10(MinInt32) 1754 0, // pow10(-324) 1755 1.0e-323, // pow10(-323) 1756 1.0e-50, // pow10(-50) 1757 1.0e-22, // pow10(-22) 1758 1.0e-1, // pow10(-1) 1759 1.0e0, // pow10(0) 1760 1.0e1, // pow10(1) 1761 1.0e22, // pow10(22) 1762 1.0e50, // pow10(50) 1763 1.0e100, // pow10(100) 1764 1.0e200, // pow10(200) 1765 1.0e308, // pow10(308) 1766 Inf(1), // pow10(309) 1767 Inf(1), // pow10(MaxInt32) 1768 } 1769 1770 var vfroundSC = [][2]float64{ 1771 {0, 0}, 1772 {1.390671161567e-309, 0}, // denormal 1773 {0.49999999999999994, 0}, // 0.5-epsilon 1774 {0.5, 1}, 1775 {0.5000000000000001, 1}, // 0.5+epsilon 1776 {-1.5, -2}, 1777 {NaN(), NaN()}, 1778 {Inf(1), Inf(1)}, 1779 {2251799813685249.5, 2251799813685250}, // 1 bit fraction 1780 {4503599627370495.5, 4503599627370496}, // 1 bit fraction, rounding to 0 bit fraction 1781 {4503599627370497, 4503599627370497}, // large integer 1782 } 1783 1784 var vfsignbitSC = []float64{ 1785 Inf(-1), 1786 Copysign(0, -1), 1787 0, 1788 Inf(1), 1789 NaN(), 1790 } 1791 var signbitSC = []bool{ 1792 true, 1793 true, 1794 false, 1795 false, 1796 false, 1797 } 1798 1799 var vfsinSC = []float64{ 1800 Inf(-1), 1801 Copysign(0, -1), 1802 0, 1803 Inf(1), 1804 NaN(), 1805 } 1806 var sinSC = []float64{ 1807 NaN(), 1808 Copysign(0, -1), 1809 0, 1810 NaN(), 1811 NaN(), 1812 } 1813 1814 var vfsinhSC = []float64{ 1815 Inf(-1), 1816 Copysign(0, -1), 1817 0, 1818 Inf(1), 1819 NaN(), 1820 } 1821 var sinhSC = []float64{ 1822 Inf(-1), 1823 Copysign(0, -1), 1824 0, 1825 Inf(1), 1826 NaN(), 1827 } 1828 1829 var vfsqrtSC = []float64{ 1830 Inf(-1), 1831 -Pi, 1832 Copysign(0, -1), 1833 0, 1834 Inf(1), 1835 NaN(), 1836 Float64frombits(2), // subnormal; see https://golang.org/issue/13013 1837 } 1838 var sqrtSC = []float64{ 1839 NaN(), 1840 NaN(), 1841 Copysign(0, -1), 1842 0, 1843 Inf(1), 1844 NaN(), 1845 3.1434555694052576e-162, 1846 } 1847 1848 var vftanhSC = []float64{ 1849 Inf(-1), 1850 Copysign(0, -1), 1851 0, 1852 Inf(1), 1853 NaN(), 1854 } 1855 var tanhSC = []float64{ 1856 -1, 1857 Copysign(0, -1), 1858 0, 1859 1, 1860 NaN(), 1861 } 1862 1863 var vfy0SC = []float64{ 1864 Inf(-1), 1865 0, 1866 Inf(1), 1867 NaN(), 1868 -1, 1869 } 1870 var y0SC = []float64{ 1871 NaN(), 1872 Inf(-1), 1873 0, 1874 NaN(), 1875 NaN(), 1876 } 1877 var y1SC = []float64{ 1878 NaN(), 1879 Inf(-1), 1880 0, 1881 NaN(), 1882 NaN(), 1883 } 1884 var y2SC = []float64{ 1885 NaN(), 1886 Inf(-1), 1887 0, 1888 NaN(), 1889 NaN(), 1890 } 1891 var yM3SC = []float64{ 1892 NaN(), 1893 Inf(1), 1894 0, 1895 NaN(), 1896 NaN(), 1897 } 1898 1899 // arguments and expected results for boundary cases 1900 const ( 1901 SmallestNormalFloat64 = 2.2250738585072014e-308 // 2**-1022 1902 LargestSubnormalFloat64 = SmallestNormalFloat64 - SmallestNonzeroFloat64 1903 ) 1904 1905 var vffrexpBC = []float64{ 1906 SmallestNormalFloat64, 1907 LargestSubnormalFloat64, 1908 SmallestNonzeroFloat64, 1909 MaxFloat64, 1910 -SmallestNormalFloat64, 1911 -LargestSubnormalFloat64, 1912 -SmallestNonzeroFloat64, 1913 -MaxFloat64, 1914 } 1915 var frexpBC = []fi{ 1916 {0.5, -1021}, 1917 {0.99999999999999978, -1022}, 1918 {0.5, -1073}, 1919 {0.99999999999999989, 1024}, 1920 {-0.5, -1021}, 1921 {-0.99999999999999978, -1022}, 1922 {-0.5, -1073}, 1923 {-0.99999999999999989, 1024}, 1924 } 1925 1926 var vfldexpBC = []fi{ 1927 {SmallestNormalFloat64, -52}, 1928 {LargestSubnormalFloat64, -51}, 1929 {SmallestNonzeroFloat64, 1074}, 1930 {MaxFloat64, -(1023 + 1074)}, 1931 {1, -1075}, 1932 {-1, -1075}, 1933 {1, 1024}, 1934 {-1, 1024}, 1935 } 1936 var ldexpBC = []float64{ 1937 SmallestNonzeroFloat64, 1938 1e-323, // 2**-1073 1939 1, 1940 1e-323, // 2**-1073 1941 0, 1942 Copysign(0, -1), 1943 Inf(1), 1944 Inf(-1), 1945 } 1946 1947 var logbBC = []float64{ 1948 -1022, 1949 -1023, 1950 -1074, 1951 1023, 1952 -1022, 1953 -1023, 1954 -1074, 1955 1023, 1956 } 1957 1958 func tolerance(a, b, e float64) bool { 1959 // Multiplying by e here can underflow denormal values to zero. 1960 // Check a==b so that at least if a and b are small and identical 1961 // we say they match. 1962 if a == b { 1963 return true 1964 } 1965 d := a - b 1966 if d < 0 { 1967 d = -d 1968 } 1969 1970 // note: b is correct (expected) value, a is actual value. 1971 // make error tolerance a fraction of b, not a. 1972 if b != 0 { 1973 e = e * b 1974 if e < 0 { 1975 e = -e 1976 } 1977 } 1978 return d < e 1979 } 1980 func close(a, b float64) bool { return tolerance(a, b, 1e-14) } 1981 func veryclose(a, b float64) bool { return tolerance(a, b, 4e-16) } 1982 func soclose(a, b, e float64) bool { return tolerance(a, b, e) } 1983 func alike(a, b float64) bool { 1984 switch { 1985 case IsNaN(a) && IsNaN(b): 1986 return true 1987 case a == b: 1988 return Signbit(a) == Signbit(b) 1989 } 1990 return false 1991 } 1992 1993 func TestNaN(t *testing.T) { 1994 f64 := NaN() 1995 if f64 == f64 { 1996 t.Fatalf("NaN() returns %g, expected NaN", f64) 1997 } 1998 f32 := float32(f64) 1999 if f32 == f32 { 2000 t.Fatalf("float32(NaN()) is %g, expected NaN", f32) 2001 } 2002 } 2003 2004 func TestAcos(t *testing.T) { 2005 for i := 0; i < len(vf); i++ { 2006 a := vf[i] / 10 2007 if f := Acos(a); !close(acos[i], f) { 2008 t.Errorf("Acos(%g) = %g, want %g", a, f, acos[i]) 2009 } 2010 } 2011 for i := 0; i < len(vfacosSC); i++ { 2012 if f := Acos(vfacosSC[i]); !alike(acosSC[i], f) { 2013 t.Errorf("Acos(%g) = %g, want %g", vfacosSC[i], f, acosSC[i]) 2014 } 2015 } 2016 } 2017 2018 func TestAcosh(t *testing.T) { 2019 for i := 0; i < len(vf); i++ { 2020 a := 1 + Abs(vf[i]) 2021 if f := Acosh(a); !veryclose(acosh[i], f) { 2022 t.Errorf("Acosh(%g) = %g, want %g", a, f, acosh[i]) 2023 } 2024 } 2025 for i := 0; i < len(vfacoshSC); i++ { 2026 if f := Acosh(vfacoshSC[i]); !alike(acoshSC[i], f) { 2027 t.Errorf("Acosh(%g) = %g, want %g", vfacoshSC[i], f, acoshSC[i]) 2028 } 2029 } 2030 } 2031 2032 func TestAsin(t *testing.T) { 2033 for i := 0; i < len(vf); i++ { 2034 a := vf[i] / 10 2035 if f := Asin(a); !veryclose(asin[i], f) { 2036 t.Errorf("Asin(%g) = %g, want %g", a, f, asin[i]) 2037 } 2038 } 2039 for i := 0; i < len(vfasinSC); i++ { 2040 if f := Asin(vfasinSC[i]); !alike(asinSC[i], f) { 2041 t.Errorf("Asin(%g) = %g, want %g", vfasinSC[i], f, asinSC[i]) 2042 } 2043 } 2044 } 2045 2046 func TestAsinh(t *testing.T) { 2047 for i := 0; i < len(vf); i++ { 2048 if f := Asinh(vf[i]); !veryclose(asinh[i], f) { 2049 t.Errorf("Asinh(%g) = %g, want %g", vf[i], f, asinh[i]) 2050 } 2051 } 2052 for i := 0; i < len(vfasinhSC); i++ { 2053 if f := Asinh(vfasinhSC[i]); !alike(asinhSC[i], f) { 2054 t.Errorf("Asinh(%g) = %g, want %g", vfasinhSC[i], f, asinhSC[i]) 2055 } 2056 } 2057 } 2058 2059 func TestAtan(t *testing.T) { 2060 for i := 0; i < len(vf); i++ { 2061 if f := Atan(vf[i]); !veryclose(atan[i], f) { 2062 t.Errorf("Atan(%g) = %g, want %g", vf[i], f, atan[i]) 2063 } 2064 } 2065 for i := 0; i < len(vfatanSC); i++ { 2066 if f := Atan(vfatanSC[i]); !alike(atanSC[i], f) { 2067 t.Errorf("Atan(%g) = %g, want %g", vfatanSC[i], f, atanSC[i]) 2068 } 2069 } 2070 } 2071 2072 func TestAtanh(t *testing.T) { 2073 for i := 0; i < len(vf); i++ { 2074 a := vf[i] / 10 2075 if f := Atanh(a); !veryclose(atanh[i], f) { 2076 t.Errorf("Atanh(%g) = %g, want %g", a, f, atanh[i]) 2077 } 2078 } 2079 for i := 0; i < len(vfatanhSC); i++ { 2080 if f := Atanh(vfatanhSC[i]); !alike(atanhSC[i], f) { 2081 t.Errorf("Atanh(%g) = %g, want %g", vfatanhSC[i], f, atanhSC[i]) 2082 } 2083 } 2084 } 2085 2086 func TestAtan2(t *testing.T) { 2087 for i := 0; i < len(vf); i++ { 2088 if f := Atan2(10, vf[i]); !veryclose(atan2[i], f) { 2089 t.Errorf("Atan2(10, %g) = %g, want %g", vf[i], f, atan2[i]) 2090 } 2091 } 2092 for i := 0; i < len(vfatan2SC); i++ { 2093 if f := Atan2(vfatan2SC[i][0], vfatan2SC[i][1]); !alike(atan2SC[i], f) { 2094 t.Errorf("Atan2(%g, %g) = %g, want %g", vfatan2SC[i][0], vfatan2SC[i][1], f, atan2SC[i]) 2095 } 2096 } 2097 } 2098 2099 func TestCbrt(t *testing.T) { 2100 for i := 0; i < len(vf); i++ { 2101 if f := Cbrt(vf[i]); !veryclose(cbrt[i], f) { 2102 t.Errorf("Cbrt(%g) = %g, want %g", vf[i], f, cbrt[i]) 2103 } 2104 } 2105 for i := 0; i < len(vfcbrtSC); i++ { 2106 if f := Cbrt(vfcbrtSC[i]); !alike(cbrtSC[i], f) { 2107 t.Errorf("Cbrt(%g) = %g, want %g", vfcbrtSC[i], f, cbrtSC[i]) 2108 } 2109 } 2110 } 2111 2112 func TestCeil(t *testing.T) { 2113 for i := 0; i < len(vf); i++ { 2114 if f := Ceil(vf[i]); ceil[i] != f { 2115 t.Errorf("Ceil(%g) = %g, want %g", vf[i], f, ceil[i]) 2116 } 2117 } 2118 for i := 0; i < len(vfceilSC); i++ { 2119 if f := Ceil(vfceilSC[i]); !alike(ceilSC[i], f) { 2120 t.Errorf("Ceil(%g) = %g, want %g", vfceilSC[i], f, ceilSC[i]) 2121 } 2122 } 2123 } 2124 2125 func TestCopysign(t *testing.T) { 2126 for i := 0; i < len(vf); i++ { 2127 if f := Copysign(vf[i], -1); copysign[i] != f { 2128 t.Errorf("Copysign(%g, -1) = %g, want %g", vf[i], f, copysign[i]) 2129 } 2130 } 2131 for i := 0; i < len(vf); i++ { 2132 if f := Copysign(vf[i], 1); -copysign[i] != f { 2133 t.Errorf("Copysign(%g, 1) = %g, want %g", vf[i], f, -copysign[i]) 2134 } 2135 } 2136 for i := 0; i < len(vfcopysignSC); i++ { 2137 if f := Copysign(vfcopysignSC[i], -1); !alike(copysignSC[i], f) { 2138 t.Errorf("Copysign(%g, -1) = %g, want %g", vfcopysignSC[i], f, copysignSC[i]) 2139 } 2140 } 2141 } 2142 2143 func TestCos(t *testing.T) { 2144 for i := 0; i < len(vf); i++ { 2145 if f := Cos(vf[i]); !veryclose(cos[i], f) { 2146 t.Errorf("Cos(%g) = %g, want %g", vf[i], f, cos[i]) 2147 } 2148 } 2149 for i := 0; i < len(vfcosSC); i++ { 2150 if f := Cos(vfcosSC[i]); !alike(cosSC[i], f) { 2151 t.Errorf("Cos(%g) = %g, want %g", vfcosSC[i], f, cosSC[i]) 2152 } 2153 } 2154 } 2155 2156 func TestCosh(t *testing.T) { 2157 for i := 0; i < len(vf); i++ { 2158 if f := Cosh(vf[i]); !close(cosh[i], f) { 2159 t.Errorf("Cosh(%g) = %g, want %g", vf[i], f, cosh[i]) 2160 } 2161 } 2162 for i := 0; i < len(vfcoshSC); i++ { 2163 if f := Cosh(vfcoshSC[i]); !alike(coshSC[i], f) { 2164 t.Errorf("Cosh(%g) = %g, want %g", vfcoshSC[i], f, coshSC[i]) 2165 } 2166 } 2167 } 2168 2169 func TestErf(t *testing.T) { 2170 for i := 0; i < len(vf); i++ { 2171 a := vf[i] / 10 2172 if f := Erf(a); !veryclose(erf[i], f) { 2173 t.Errorf("Erf(%g) = %g, want %g", a, f, erf[i]) 2174 } 2175 } 2176 for i := 0; i < len(vferfSC); i++ { 2177 if f := Erf(vferfSC[i]); !alike(erfSC[i], f) { 2178 t.Errorf("Erf(%g) = %g, want %g", vferfSC[i], f, erfSC[i]) 2179 } 2180 } 2181 } 2182 2183 func TestErfc(t *testing.T) { 2184 for i := 0; i < len(vf); i++ { 2185 a := vf[i] / 10 2186 if f := Erfc(a); !veryclose(erfc[i], f) { 2187 t.Errorf("Erfc(%g) = %g, want %g", a, f, erfc[i]) 2188 } 2189 } 2190 for i := 0; i < len(vferfcSC); i++ { 2191 if f := Erfc(vferfcSC[i]); !alike(erfcSC[i], f) { 2192 t.Errorf("Erfc(%g) = %g, want %g", vferfcSC[i], f, erfcSC[i]) 2193 } 2194 } 2195 } 2196 2197 func TestErfinv(t *testing.T) { 2198 for i := 0; i < len(vf); i++ { 2199 a := vf[i] / 10 2200 if f := Erfinv(a); !veryclose(erfinv[i], f) { 2201 t.Errorf("Erfinv(%g) = %g, want %g", a, f, erfinv[i]) 2202 } 2203 } 2204 for i := 0; i < len(vferfinvSC); i++ { 2205 if f := Erfinv(vferfinvSC[i]); !alike(erfinvSC[i], f) { 2206 t.Errorf("Erfinv(%g) = %g, want %g", vferfinvSC[i], f, erfinvSC[i]) 2207 } 2208 } 2209 for x := -0.9; x <= 0.90; x += 1e-2 { 2210 if f := Erf(Erfinv(x)); !close(x, f) { 2211 t.Errorf("Erf(Erfinv(%g)) = %g, want %g", x, f, x) 2212 } 2213 } 2214 for x := -0.9; x <= 0.90; x += 1e-2 { 2215 if f := Erfinv(Erf(x)); !close(x, f) { 2216 t.Errorf("Erfinv(Erf(%g)) = %g, want %g", x, f, x) 2217 } 2218 } 2219 } 2220 2221 func TestErfcinv(t *testing.T) { 2222 for i := 0; i < len(vf); i++ { 2223 a := 1.0 - (vf[i] / 10) 2224 if f := Erfcinv(a); !veryclose(erfinv[i], f) { 2225 t.Errorf("Erfcinv(%g) = %g, want %g", a, f, erfinv[i]) 2226 } 2227 } 2228 for i := 0; i < len(vferfcinvSC); i++ { 2229 if f := Erfcinv(vferfcinvSC[i]); !alike(erfcinvSC[i], f) { 2230 t.Errorf("Erfcinv(%g) = %g, want %g", vferfcinvSC[i], f, erfcinvSC[i]) 2231 } 2232 } 2233 for x := 0.1; x <= 1.9; x += 1e-2 { 2234 if f := Erfc(Erfcinv(x)); !close(x, f) { 2235 t.Errorf("Erfc(Erfcinv(%g)) = %g, want %g", x, f, x) 2236 } 2237 } 2238 for x := 0.1; x <= 1.9; x += 1e-2 { 2239 if f := Erfcinv(Erfc(x)); !close(x, f) { 2240 t.Errorf("Erfcinv(Erfc(%g)) = %g, want %g", x, f, x) 2241 } 2242 } 2243 } 2244 2245 func TestExp(t *testing.T) { 2246 testExp(t, Exp, "Exp") 2247 testExp(t, ExpGo, "ExpGo") 2248 } 2249 2250 func testExp(t *testing.T, Exp func(float64) float64, name string) { 2251 for i := 0; i < len(vf); i++ { 2252 if f := Exp(vf[i]); !veryclose(exp[i], f) { 2253 t.Errorf("%s(%g) = %g, want %g", name, vf[i], f, exp[i]) 2254 } 2255 } 2256 for i := 0; i < len(vfexpSC); i++ { 2257 if f := Exp(vfexpSC[i]); !alike(expSC[i], f) { 2258 t.Errorf("%s(%g) = %g, want %g", name, vfexpSC[i], f, expSC[i]) 2259 } 2260 } 2261 } 2262 2263 func TestExpm1(t *testing.T) { 2264 for i := 0; i < len(vf); i++ { 2265 a := vf[i] / 100 2266 if f := Expm1(a); !veryclose(expm1[i], f) { 2267 t.Errorf("Expm1(%g) = %g, want %g", a, f, expm1[i]) 2268 } 2269 } 2270 for i := 0; i < len(vf); i++ { 2271 a := vf[i] * 10 2272 if f := Expm1(a); !close(expm1Large[i], f) { 2273 t.Errorf("Expm1(%g) = %g, want %g", a, f, expm1Large[i]) 2274 } 2275 } 2276 for i := 0; i < len(vfexpm1SC); i++ { 2277 if f := Expm1(vfexpm1SC[i]); !alike(expm1SC[i], f) { 2278 t.Errorf("Expm1(%g) = %g, want %g", vfexpm1SC[i], f, expm1SC[i]) 2279 } 2280 } 2281 } 2282 2283 func TestExp2(t *testing.T) { 2284 testExp2(t, Exp2, "Exp2") 2285 testExp2(t, Exp2Go, "Exp2Go") 2286 } 2287 2288 func testExp2(t *testing.T, Exp2 func(float64) float64, name string) { 2289 for i := 0; i < len(vf); i++ { 2290 if f := Exp2(vf[i]); !close(exp2[i], f) { 2291 t.Errorf("%s(%g) = %g, want %g", name, vf[i], f, exp2[i]) 2292 } 2293 } 2294 for i := 0; i < len(vfexp2SC); i++ { 2295 if f := Exp2(vfexp2SC[i]); !alike(exp2SC[i], f) { 2296 t.Errorf("%s(%g) = %g, want %g", name, vfexpSC[i], f, expSC[i]) 2297 } 2298 } 2299 for n := -1074; n < 1024; n++ { 2300 f := Exp2(float64(n)) 2301 vf := Ldexp(1, n) 2302 if f != vf { 2303 t.Errorf("%s(%d) = %g, want %g", name, n, f, vf) 2304 } 2305 } 2306 } 2307 2308 func TestAbs(t *testing.T) { 2309 for i := 0; i < len(vf); i++ { 2310 if f := Abs(vf[i]); fabs[i] != f { 2311 t.Errorf("Abs(%g) = %g, want %g", vf[i], f, fabs[i]) 2312 } 2313 } 2314 for i := 0; i < len(vffabsSC); i++ { 2315 if f := Abs(vffabsSC[i]); !alike(fabsSC[i], f) { 2316 t.Errorf("Abs(%g) = %g, want %g", vffabsSC[i], f, fabsSC[i]) 2317 } 2318 } 2319 } 2320 2321 func TestDim(t *testing.T) { 2322 for i := 0; i < len(vf); i++ { 2323 if f := Dim(vf[i], 0); fdim[i] != f { 2324 t.Errorf("Dim(%g, %g) = %g, want %g", vf[i], 0.0, f, fdim[i]) 2325 } 2326 } 2327 for i := 0; i < len(vffdimSC); i++ { 2328 if f := Dim(vffdimSC[i][0], vffdimSC[i][1]); !alike(fdimSC[i], f) { 2329 t.Errorf("Dim(%g, %g) = %g, want %g", vffdimSC[i][0], vffdimSC[i][1], f, fdimSC[i]) 2330 } 2331 } 2332 for i := 0; i < len(vffdim2SC); i++ { 2333 if f := Dim(vffdim2SC[i][0], vffdim2SC[i][1]); !alike(fdimSC[i], f) { 2334 t.Errorf("Dim(%g, %g) = %g, want %g", vffdim2SC[i][0], vffdim2SC[i][1], f, fdimSC[i]) 2335 } 2336 } 2337 } 2338 2339 func TestFloor(t *testing.T) { 2340 for i := 0; i < len(vf); i++ { 2341 if f := Floor(vf[i]); floor[i] != f { 2342 t.Errorf("Floor(%g) = %g, want %g", vf[i], f, floor[i]) 2343 } 2344 } 2345 for i := 0; i < len(vfceilSC); i++ { 2346 if f := Floor(vfceilSC[i]); !alike(ceilSC[i], f) { 2347 t.Errorf("Floor(%g) = %g, want %g", vfceilSC[i], f, ceilSC[i]) 2348 } 2349 } 2350 } 2351 2352 func TestMax(t *testing.T) { 2353 for i := 0; i < len(vf); i++ { 2354 if f := Max(vf[i], ceil[i]); ceil[i] != f { 2355 t.Errorf("Max(%g, %g) = %g, want %g", vf[i], ceil[i], f, ceil[i]) 2356 } 2357 } 2358 for i := 0; i < len(vffdimSC); i++ { 2359 if f := Max(vffdimSC[i][0], vffdimSC[i][1]); !alike(fmaxSC[i], f) { 2360 t.Errorf("Max(%g, %g) = %g, want %g", vffdimSC[i][0], vffdimSC[i][1], f, fmaxSC[i]) 2361 } 2362 } 2363 for i := 0; i < len(vffdim2SC); i++ { 2364 if f := Max(vffdim2SC[i][0], vffdim2SC[i][1]); !alike(fmaxSC[i], f) { 2365 t.Errorf("Max(%g, %g) = %g, want %g", vffdim2SC[i][0], vffdim2SC[i][1], f, fmaxSC[i]) 2366 } 2367 } 2368 } 2369 2370 func TestMin(t *testing.T) { 2371 for i := 0; i < len(vf); i++ { 2372 if f := Min(vf[i], floor[i]); floor[i] != f { 2373 t.Errorf("Min(%g, %g) = %g, want %g", vf[i], floor[i], f, floor[i]) 2374 } 2375 } 2376 for i := 0; i < len(vffdimSC); i++ { 2377 if f := Min(vffdimSC[i][0], vffdimSC[i][1]); !alike(fminSC[i], f) { 2378 t.Errorf("Min(%g, %g) = %g, want %g", vffdimSC[i][0], vffdimSC[i][1], f, fminSC[i]) 2379 } 2380 } 2381 for i := 0; i < len(vffdim2SC); i++ { 2382 if f := Min(vffdim2SC[i][0], vffdim2SC[i][1]); !alike(fminSC[i], f) { 2383 t.Errorf("Min(%g, %g) = %g, want %g", vffdim2SC[i][0], vffdim2SC[i][1], f, fminSC[i]) 2384 } 2385 } 2386 } 2387 2388 func TestMod(t *testing.T) { 2389 for i := 0; i < len(vf); i++ { 2390 if f := Mod(10, vf[i]); fmod[i] != f { 2391 t.Errorf("Mod(10, %g) = %g, want %g", vf[i], f, fmod[i]) 2392 } 2393 } 2394 for i := 0; i < len(vffmodSC); i++ { 2395 if f := Mod(vffmodSC[i][0], vffmodSC[i][1]); !alike(fmodSC[i], f) { 2396 t.Errorf("Mod(%g, %g) = %g, want %g", vffmodSC[i][0], vffmodSC[i][1], f, fmodSC[i]) 2397 } 2398 } 2399 } 2400 2401 func TestFrexp(t *testing.T) { 2402 for i := 0; i < len(vf); i++ { 2403 if f, j := Frexp(vf[i]); !veryclose(frexp[i].f, f) || frexp[i].i != j { 2404 t.Errorf("Frexp(%g) = %g, %d, want %g, %d", vf[i], f, j, frexp[i].f, frexp[i].i) 2405 } 2406 } 2407 for i := 0; i < len(vffrexpSC); i++ { 2408 if f, j := Frexp(vffrexpSC[i]); !alike(frexpSC[i].f, f) || frexpSC[i].i != j { 2409 t.Errorf("Frexp(%g) = %g, %d, want %g, %d", vffrexpSC[i], f, j, frexpSC[i].f, frexpSC[i].i) 2410 } 2411 } 2412 for i := 0; i < len(vffrexpBC); i++ { 2413 if f, j := Frexp(vffrexpBC[i]); !alike(frexpBC[i].f, f) || frexpBC[i].i != j { 2414 t.Errorf("Frexp(%g) = %g, %d, want %g, %d", vffrexpBC[i], f, j, frexpBC[i].f, frexpBC[i].i) 2415 } 2416 } 2417 } 2418 2419 func TestGamma(t *testing.T) { 2420 for i := 0; i < len(vf); i++ { 2421 if f := Gamma(vf[i]); !close(gamma[i], f) { 2422 t.Errorf("Gamma(%g) = %g, want %g", vf[i], f, gamma[i]) 2423 } 2424 } 2425 for _, g := range vfgamma { 2426 f := Gamma(g[0]) 2427 var ok bool 2428 if IsNaN(g[1]) || IsInf(g[1], 0) || g[1] == 0 || f == 0 { 2429 ok = alike(g[1], f) 2430 } else if g[0] > -50 && g[0] <= 171 { 2431 ok = veryclose(g[1], f) 2432 } else { 2433 ok = close(g[1], f) 2434 } 2435 if !ok { 2436 t.Errorf("Gamma(%g) = %g, want %g", g[0], f, g[1]) 2437 } 2438 } 2439 } 2440 2441 func TestHypot(t *testing.T) { 2442 for i := 0; i < len(vf); i++ { 2443 a := Abs(1e200 * tanh[i] * Sqrt(2)) 2444 if f := Hypot(1e200*tanh[i], 1e200*tanh[i]); !veryclose(a, f) { 2445 t.Errorf("Hypot(%g, %g) = %g, want %g", 1e200*tanh[i], 1e200*tanh[i], f, a) 2446 } 2447 } 2448 for i := 0; i < len(vfhypotSC); i++ { 2449 if f := Hypot(vfhypotSC[i][0], vfhypotSC[i][1]); !alike(hypotSC[i], f) { 2450 t.Errorf("Hypot(%g, %g) = %g, want %g", vfhypotSC[i][0], vfhypotSC[i][1], f, hypotSC[i]) 2451 } 2452 } 2453 } 2454 2455 func TestHypotGo(t *testing.T) { 2456 for i := 0; i < len(vf); i++ { 2457 a := Abs(1e200 * tanh[i] * Sqrt(2)) 2458 if f := HypotGo(1e200*tanh[i], 1e200*tanh[i]); !veryclose(a, f) { 2459 t.Errorf("HypotGo(%g, %g) = %g, want %g", 1e200*tanh[i], 1e200*tanh[i], f, a) 2460 } 2461 } 2462 for i := 0; i < len(vfhypotSC); i++ { 2463 if f := HypotGo(vfhypotSC[i][0], vfhypotSC[i][1]); !alike(hypotSC[i], f) { 2464 t.Errorf("HypotGo(%g, %g) = %g, want %g", vfhypotSC[i][0], vfhypotSC[i][1], f, hypotSC[i]) 2465 } 2466 } 2467 } 2468 2469 func TestIlogb(t *testing.T) { 2470 for i := 0; i < len(vf); i++ { 2471 a := frexp[i].i - 1 // adjust because fr in the interval [½, 1) 2472 if e := Ilogb(vf[i]); a != e { 2473 t.Errorf("Ilogb(%g) = %d, want %d", vf[i], e, a) 2474 } 2475 } 2476 for i := 0; i < len(vflogbSC); i++ { 2477 if e := Ilogb(vflogbSC[i]); ilogbSC[i] != e { 2478 t.Errorf("Ilogb(%g) = %d, want %d", vflogbSC[i], e, ilogbSC[i]) 2479 } 2480 } 2481 for i := 0; i < len(vffrexpBC); i++ { 2482 if e := Ilogb(vffrexpBC[i]); int(logbBC[i]) != e { 2483 t.Errorf("Ilogb(%g) = %d, want %d", vffrexpBC[i], e, int(logbBC[i])) 2484 } 2485 } 2486 } 2487 2488 func TestJ0(t *testing.T) { 2489 for i := 0; i < len(vf); i++ { 2490 if f := J0(vf[i]); !soclose(j0[i], f, 4e-14) { 2491 t.Errorf("J0(%g) = %g, want %g", vf[i], f, j0[i]) 2492 } 2493 } 2494 for i := 0; i < len(vfj0SC); i++ { 2495 if f := J0(vfj0SC[i]); !alike(j0SC[i], f) { 2496 t.Errorf("J0(%g) = %g, want %g", vfj0SC[i], f, j0SC[i]) 2497 } 2498 } 2499 } 2500 2501 func TestJ1(t *testing.T) { 2502 for i := 0; i < len(vf); i++ { 2503 if f := J1(vf[i]); !close(j1[i], f) { 2504 t.Errorf("J1(%g) = %g, want %g", vf[i], f, j1[i]) 2505 } 2506 } 2507 for i := 0; i < len(vfj0SC); i++ { 2508 if f := J1(vfj0SC[i]); !alike(j1SC[i], f) { 2509 t.Errorf("J1(%g) = %g, want %g", vfj0SC[i], f, j1SC[i]) 2510 } 2511 } 2512 } 2513 2514 func TestJn(t *testing.T) { 2515 for i := 0; i < len(vf); i++ { 2516 if f := Jn(2, vf[i]); !close(j2[i], f) { 2517 t.Errorf("Jn(2, %g) = %g, want %g", vf[i], f, j2[i]) 2518 } 2519 if f := Jn(-3, vf[i]); !close(jM3[i], f) { 2520 t.Errorf("Jn(-3, %g) = %g, want %g", vf[i], f, jM3[i]) 2521 } 2522 } 2523 for i := 0; i < len(vfj0SC); i++ { 2524 if f := Jn(2, vfj0SC[i]); !alike(j2SC[i], f) { 2525 t.Errorf("Jn(2, %g) = %g, want %g", vfj0SC[i], f, j2SC[i]) 2526 } 2527 if f := Jn(-3, vfj0SC[i]); !alike(jM3SC[i], f) { 2528 t.Errorf("Jn(-3, %g) = %g, want %g", vfj0SC[i], f, jM3SC[i]) 2529 } 2530 } 2531 } 2532 2533 func TestLdexp(t *testing.T) { 2534 for i := 0; i < len(vf); i++ { 2535 if f := Ldexp(frexp[i].f, frexp[i].i); !veryclose(vf[i], f) { 2536 t.Errorf("Ldexp(%g, %d) = %g, want %g", frexp[i].f, frexp[i].i, f, vf[i]) 2537 } 2538 } 2539 for i := 0; i < len(vffrexpSC); i++ { 2540 if f := Ldexp(frexpSC[i].f, frexpSC[i].i); !alike(vffrexpSC[i], f) { 2541 t.Errorf("Ldexp(%g, %d) = %g, want %g", frexpSC[i].f, frexpSC[i].i, f, vffrexpSC[i]) 2542 } 2543 } 2544 for i := 0; i < len(vfldexpSC); i++ { 2545 if f := Ldexp(vfldexpSC[i].f, vfldexpSC[i].i); !alike(ldexpSC[i], f) { 2546 t.Errorf("Ldexp(%g, %d) = %g, want %g", vfldexpSC[i].f, vfldexpSC[i].i, f, ldexpSC[i]) 2547 } 2548 } 2549 for i := 0; i < len(vffrexpBC); i++ { 2550 if f := Ldexp(frexpBC[i].f, frexpBC[i].i); !alike(vffrexpBC[i], f) { 2551 t.Errorf("Ldexp(%g, %d) = %g, want %g", frexpBC[i].f, frexpBC[i].i, f, vffrexpBC[i]) 2552 } 2553 } 2554 for i := 0; i < len(vfldexpBC); i++ { 2555 if f := Ldexp(vfldexpBC[i].f, vfldexpBC[i].i); !alike(ldexpBC[i], f) { 2556 t.Errorf("Ldexp(%g, %d) = %g, want %g", vfldexpBC[i].f, vfldexpBC[i].i, f, ldexpBC[i]) 2557 } 2558 } 2559 } 2560 2561 func TestLgamma(t *testing.T) { 2562 for i := 0; i < len(vf); i++ { 2563 if f, s := Lgamma(vf[i]); !close(lgamma[i].f, f) || lgamma[i].i != s { 2564 t.Errorf("Lgamma(%g) = %g, %d, want %g, %d", vf[i], f, s, lgamma[i].f, lgamma[i].i) 2565 } 2566 } 2567 for i := 0; i < len(vflgammaSC); i++ { 2568 if f, s := Lgamma(vflgammaSC[i]); !alike(lgammaSC[i].f, f) || lgammaSC[i].i != s { 2569 t.Errorf("Lgamma(%g) = %g, %d, want %g, %d", vflgammaSC[i], f, s, lgammaSC[i].f, lgammaSC[i].i) 2570 } 2571 } 2572 } 2573 2574 func TestLog(t *testing.T) { 2575 for i := 0; i < len(vf); i++ { 2576 a := Abs(vf[i]) 2577 if f := Log(a); log[i] != f { 2578 t.Errorf("Log(%g) = %g, want %g", a, f, log[i]) 2579 } 2580 } 2581 if f := Log(10); f != Ln10 { 2582 t.Errorf("Log(%g) = %g, want %g", 10.0, f, Ln10) 2583 } 2584 for i := 0; i < len(vflogSC); i++ { 2585 if f := Log(vflogSC[i]); !alike(logSC[i], f) { 2586 t.Errorf("Log(%g) = %g, want %g", vflogSC[i], f, logSC[i]) 2587 } 2588 } 2589 } 2590 2591 func TestLogb(t *testing.T) { 2592 for i := 0; i < len(vf); i++ { 2593 if f := Logb(vf[i]); logb[i] != f { 2594 t.Errorf("Logb(%g) = %g, want %g", vf[i], f, logb[i]) 2595 } 2596 } 2597 for i := 0; i < len(vflogbSC); i++ { 2598 if f := Logb(vflogbSC[i]); !alike(logbSC[i], f) { 2599 t.Errorf("Logb(%g) = %g, want %g", vflogbSC[i], f, logbSC[i]) 2600 } 2601 } 2602 for i := 0; i < len(vffrexpBC); i++ { 2603 if f := Logb(vffrexpBC[i]); !alike(logbBC[i], f) { 2604 t.Errorf("Logb(%g) = %g, want %g", vffrexpBC[i], f, logbBC[i]) 2605 } 2606 } 2607 } 2608 2609 func TestLog10(t *testing.T) { 2610 for i := 0; i < len(vf); i++ { 2611 a := Abs(vf[i]) 2612 if f := Log10(a); !veryclose(log10[i], f) { 2613 t.Errorf("Log10(%g) = %g, want %g", a, f, log10[i]) 2614 } 2615 } 2616 if f := Log10(E); f != Log10E { 2617 t.Errorf("Log10(%g) = %g, want %g", E, f, Log10E) 2618 } 2619 for i := 0; i < len(vflogSC); i++ { 2620 if f := Log10(vflogSC[i]); !alike(logSC[i], f) { 2621 t.Errorf("Log10(%g) = %g, want %g", vflogSC[i], f, logSC[i]) 2622 } 2623 } 2624 } 2625 2626 func TestLog1p(t *testing.T) { 2627 for i := 0; i < len(vf); i++ { 2628 a := vf[i] / 100 2629 if f := Log1p(a); !veryclose(log1p[i], f) { 2630 t.Errorf("Log1p(%g) = %g, want %g", a, f, log1p[i]) 2631 } 2632 } 2633 a := 9.0 2634 if f := Log1p(a); f != Ln10 { 2635 t.Errorf("Log1p(%g) = %g, want %g", a, f, Ln10) 2636 } 2637 for i := 0; i < len(vflogSC); i++ { 2638 if f := Log1p(vflog1pSC[i]); !alike(log1pSC[i], f) { 2639 t.Errorf("Log1p(%g) = %g, want %g", vflog1pSC[i], f, log1pSC[i]) 2640 } 2641 } 2642 } 2643 2644 func TestLog2(t *testing.T) { 2645 for i := 0; i < len(vf); i++ { 2646 a := Abs(vf[i]) 2647 if f := Log2(a); !veryclose(log2[i], f) { 2648 t.Errorf("Log2(%g) = %g, want %g", a, f, log2[i]) 2649 } 2650 } 2651 if f := Log2(E); f != Log2E { 2652 t.Errorf("Log2(%g) = %g, want %g", E, f, Log2E) 2653 } 2654 for i := 0; i < len(vflogSC); i++ { 2655 if f := Log2(vflogSC[i]); !alike(logSC[i], f) { 2656 t.Errorf("Log2(%g) = %g, want %g", vflogSC[i], f, logSC[i]) 2657 } 2658 } 2659 for i := -1074; i <= 1023; i++ { 2660 f := Ldexp(1, i) 2661 l := Log2(f) 2662 if l != float64(i) { 2663 t.Errorf("Log2(2**%d) = %g, want %d", i, l, i) 2664 } 2665 } 2666 } 2667 2668 func TestModf(t *testing.T) { 2669 for i := 0; i < len(vf); i++ { 2670 if f, g := Modf(vf[i]); !veryclose(modf[i][0], f) || !veryclose(modf[i][1], g) { 2671 t.Errorf("Modf(%g) = %g, %g, want %g, %g", vf[i], f, g, modf[i][0], modf[i][1]) 2672 } 2673 } 2674 for i := 0; i < len(vfmodfSC); i++ { 2675 if f, g := Modf(vfmodfSC[i]); !alike(modfSC[i][0], f) || !alike(modfSC[i][1], g) { 2676 t.Errorf("Modf(%g) = %g, %g, want %g, %g", vfmodfSC[i], f, g, modfSC[i][0], modfSC[i][1]) 2677 } 2678 } 2679 } 2680 2681 func TestNextafter32(t *testing.T) { 2682 for i := 0; i < len(vf); i++ { 2683 vfi := float32(vf[i]) 2684 if f := Nextafter32(vfi, 10); nextafter32[i] != f { 2685 t.Errorf("Nextafter32(%g, %g) = %g want %g", vfi, 10.0, f, nextafter32[i]) 2686 } 2687 } 2688 for i := 0; i < len(vfnextafter32SC); i++ { 2689 if f := Nextafter32(vfnextafter32SC[i][0], vfnextafter32SC[i][1]); !alike(float64(nextafter32SC[i]), float64(f)) { 2690 t.Errorf("Nextafter32(%g, %g) = %g want %g", vfnextafter32SC[i][0], vfnextafter32SC[i][1], f, nextafter32SC[i]) 2691 } 2692 } 2693 } 2694 2695 func TestNextafter64(t *testing.T) { 2696 for i := 0; i < len(vf); i++ { 2697 if f := Nextafter(vf[i], 10); nextafter64[i] != f { 2698 t.Errorf("Nextafter64(%g, %g) = %g want %g", vf[i], 10.0, f, nextafter64[i]) 2699 } 2700 } 2701 for i := 0; i < len(vfnextafter64SC); i++ { 2702 if f := Nextafter(vfnextafter64SC[i][0], vfnextafter64SC[i][1]); !alike(nextafter64SC[i], f) { 2703 t.Errorf("Nextafter64(%g, %g) = %g want %g", vfnextafter64SC[i][0], vfnextafter64SC[i][1], f, nextafter64SC[i]) 2704 } 2705 } 2706 } 2707 2708 func TestPow(t *testing.T) { 2709 for i := 0; i < len(vf); i++ { 2710 if f := Pow(10, vf[i]); !close(pow[i], f) { 2711 t.Errorf("Pow(10, %g) = %g, want %g", vf[i], f, pow[i]) 2712 } 2713 } 2714 for i := 0; i < len(vfpowSC); i++ { 2715 if f := Pow(vfpowSC[i][0], vfpowSC[i][1]); !alike(powSC[i], f) { 2716 t.Errorf("Pow(%g, %g) = %g, want %g", vfpowSC[i][0], vfpowSC[i][1], f, powSC[i]) 2717 } 2718 } 2719 } 2720 2721 func TestPow10(t *testing.T) { 2722 for i := 0; i < len(vfpow10SC); i++ { 2723 if f := Pow10(vfpow10SC[i]); !alike(pow10SC[i], f) { 2724 t.Errorf("Pow10(%d) = %g, want %g", vfpow10SC[i], f, pow10SC[i]) 2725 } 2726 } 2727 } 2728 2729 func TestRemainder(t *testing.T) { 2730 for i := 0; i < len(vf); i++ { 2731 if f := Remainder(10, vf[i]); remainder[i] != f { 2732 t.Errorf("Remainder(10, %g) = %g, want %g", vf[i], f, remainder[i]) 2733 } 2734 } 2735 for i := 0; i < len(vffmodSC); i++ { 2736 if f := Remainder(vffmodSC[i][0], vffmodSC[i][1]); !alike(fmodSC[i], f) { 2737 t.Errorf("Remainder(%g, %g) = %g, want %g", vffmodSC[i][0], vffmodSC[i][1], f, fmodSC[i]) 2738 } 2739 } 2740 } 2741 2742 func TestRound(t *testing.T) { 2743 for i := 0; i < len(vf); i++ { 2744 if f := Round(vf[i]); !alike(round[i], f) { 2745 t.Errorf("Round(%g) = %g, want %g", vf[i], f, round[i]) 2746 } 2747 } 2748 for i := 0; i < len(vfroundSC); i++ { 2749 if f := Round(vfroundSC[i][0]); !alike(vfroundSC[i][1], f) { 2750 t.Errorf("Round(%g) = %g, want %g", vfroundSC[i][0], f, vfroundSC[i][1]) 2751 } 2752 } 2753 } 2754 2755 func TestSignbit(t *testing.T) { 2756 for i := 0; i < len(vf); i++ { 2757 if f := Signbit(vf[i]); signbit[i] != f { 2758 t.Errorf("Signbit(%g) = %t, want %t", vf[i], f, signbit[i]) 2759 } 2760 } 2761 for i := 0; i < len(vfsignbitSC); i++ { 2762 if f := Signbit(vfsignbitSC[i]); signbitSC[i] != f { 2763 t.Errorf("Signbit(%g) = %t, want %t", vfsignbitSC[i], f, signbitSC[i]) 2764 } 2765 } 2766 } 2767 func TestSin(t *testing.T) { 2768 for i := 0; i < len(vf); i++ { 2769 if f := Sin(vf[i]); !veryclose(sin[i], f) { 2770 t.Errorf("Sin(%g) = %g, want %g", vf[i], f, sin[i]) 2771 } 2772 } 2773 for i := 0; i < len(vfsinSC); i++ { 2774 if f := Sin(vfsinSC[i]); !alike(sinSC[i], f) { 2775 t.Errorf("Sin(%g) = %g, want %g", vfsinSC[i], f, sinSC[i]) 2776 } 2777 } 2778 } 2779 2780 func TestSincos(t *testing.T) { 2781 for i := 0; i < len(vf); i++ { 2782 if s, c := Sincos(vf[i]); !veryclose(sin[i], s) || !veryclose(cos[i], c) { 2783 t.Errorf("Sincos(%g) = %g, %g want %g, %g", vf[i], s, c, sin[i], cos[i]) 2784 } 2785 } 2786 } 2787 2788 func TestSinh(t *testing.T) { 2789 for i := 0; i < len(vf); i++ { 2790 if f := Sinh(vf[i]); !close(sinh[i], f) { 2791 t.Errorf("Sinh(%g) = %g, want %g", vf[i], f, sinh[i]) 2792 } 2793 } 2794 for i := 0; i < len(vfsinhSC); i++ { 2795 if f := Sinh(vfsinhSC[i]); !alike(sinhSC[i], f) { 2796 t.Errorf("Sinh(%g) = %g, want %g", vfsinhSC[i], f, sinhSC[i]) 2797 } 2798 } 2799 } 2800 2801 func TestSqrt(t *testing.T) { 2802 for i := 0; i < len(vf); i++ { 2803 a := Abs(vf[i]) 2804 if f := SqrtGo(a); sqrt[i] != f { 2805 t.Errorf("SqrtGo(%g) = %g, want %g", a, f, sqrt[i]) 2806 } 2807 a = Abs(vf[i]) 2808 if f := Sqrt(a); sqrt[i] != f { 2809 t.Errorf("Sqrt(%g) = %g, want %g", a, f, sqrt[i]) 2810 } 2811 } 2812 for i := 0; i < len(vfsqrtSC); i++ { 2813 if f := SqrtGo(vfsqrtSC[i]); !alike(sqrtSC[i], f) { 2814 t.Errorf("SqrtGo(%g) = %g, want %g", vfsqrtSC[i], f, sqrtSC[i]) 2815 } 2816 if f := Sqrt(vfsqrtSC[i]); !alike(sqrtSC[i], f) { 2817 t.Errorf("Sqrt(%g) = %g, want %g", vfsqrtSC[i], f, sqrtSC[i]) 2818 } 2819 } 2820 } 2821 2822 func TestTan(t *testing.T) { 2823 for i := 0; i < len(vf); i++ { 2824 if f := Tan(vf[i]); !veryclose(tan[i], f) { 2825 t.Errorf("Tan(%g) = %g, want %g", vf[i], f, tan[i]) 2826 } 2827 } 2828 // same special cases as Sin 2829 for i := 0; i < len(vfsinSC); i++ { 2830 if f := Tan(vfsinSC[i]); !alike(sinSC[i], f) { 2831 t.Errorf("Tan(%g) = %g, want %g", vfsinSC[i], f, sinSC[i]) 2832 } 2833 } 2834 } 2835 2836 func TestTanh(t *testing.T) { 2837 for i := 0; i < len(vf); i++ { 2838 if f := Tanh(vf[i]); !veryclose(tanh[i], f) { 2839 t.Errorf("Tanh(%g) = %g, want %g", vf[i], f, tanh[i]) 2840 } 2841 } 2842 for i := 0; i < len(vftanhSC); i++ { 2843 if f := Tanh(vftanhSC[i]); !alike(tanhSC[i], f) { 2844 t.Errorf("Tanh(%g) = %g, want %g", vftanhSC[i], f, tanhSC[i]) 2845 } 2846 } 2847 } 2848 2849 func TestTrunc(t *testing.T) { 2850 for i := 0; i < len(vf); i++ { 2851 if f := Trunc(vf[i]); trunc[i] != f { 2852 t.Errorf("Trunc(%g) = %g, want %g", vf[i], f, trunc[i]) 2853 } 2854 } 2855 for i := 0; i < len(vfceilSC); i++ { 2856 if f := Trunc(vfceilSC[i]); !alike(ceilSC[i], f) { 2857 t.Errorf("Trunc(%g) = %g, want %g", vfceilSC[i], f, ceilSC[i]) 2858 } 2859 } 2860 } 2861 2862 func TestY0(t *testing.T) { 2863 for i := 0; i < len(vf); i++ { 2864 a := Abs(vf[i]) 2865 if f := Y0(a); !close(y0[i], f) { 2866 t.Errorf("Y0(%g) = %g, want %g", a, f, y0[i]) 2867 } 2868 } 2869 for i := 0; i < len(vfy0SC); i++ { 2870 if f := Y0(vfy0SC[i]); !alike(y0SC[i], f) { 2871 t.Errorf("Y0(%g) = %g, want %g", vfy0SC[i], f, y0SC[i]) 2872 } 2873 } 2874 } 2875 2876 func TestY1(t *testing.T) { 2877 for i := 0; i < len(vf); i++ { 2878 a := Abs(vf[i]) 2879 if f := Y1(a); !soclose(y1[i], f, 2e-14) { 2880 t.Errorf("Y1(%g) = %g, want %g", a, f, y1[i]) 2881 } 2882 } 2883 for i := 0; i < len(vfy0SC); i++ { 2884 if f := Y1(vfy0SC[i]); !alike(y1SC[i], f) { 2885 t.Errorf("Y1(%g) = %g, want %g", vfy0SC[i], f, y1SC[i]) 2886 } 2887 } 2888 } 2889 2890 func TestYn(t *testing.T) { 2891 for i := 0; i < len(vf); i++ { 2892 a := Abs(vf[i]) 2893 if f := Yn(2, a); !close(y2[i], f) { 2894 t.Errorf("Yn(2, %g) = %g, want %g", a, f, y2[i]) 2895 } 2896 if f := Yn(-3, a); !close(yM3[i], f) { 2897 t.Errorf("Yn(-3, %g) = %g, want %g", a, f, yM3[i]) 2898 } 2899 } 2900 for i := 0; i < len(vfy0SC); i++ { 2901 if f := Yn(2, vfy0SC[i]); !alike(y2SC[i], f) { 2902 t.Errorf("Yn(2, %g) = %g, want %g", vfy0SC[i], f, y2SC[i]) 2903 } 2904 if f := Yn(-3, vfy0SC[i]); !alike(yM3SC[i], f) { 2905 t.Errorf("Yn(-3, %g) = %g, want %g", vfy0SC[i], f, yM3SC[i]) 2906 } 2907 } 2908 if f := Yn(0, 0); !alike(Inf(-1), f) { 2909 t.Errorf("Yn(0, 0) = %g, want %g", f, Inf(-1)) 2910 } 2911 } 2912 2913 // Check that math functions of high angle values 2914 // return accurate results. [Since (vf[i] + large) - large != vf[i], 2915 // testing for Trig(vf[i] + large) == Trig(vf[i]), where large is 2916 // a multiple of 2*Pi, is misleading.] 2917 func TestLargeCos(t *testing.T) { 2918 large := float64(100000 * Pi) 2919 for i := 0; i < len(vf); i++ { 2920 f1 := cosLarge[i] 2921 f2 := Cos(vf[i] + large) 2922 if !close(f1, f2) { 2923 t.Errorf("Cos(%g) = %g, want %g", vf[i]+large, f2, f1) 2924 } 2925 } 2926 } 2927 2928 func TestLargeSin(t *testing.T) { 2929 large := float64(100000 * Pi) 2930 for i := 0; i < len(vf); i++ { 2931 f1 := sinLarge[i] 2932 f2 := Sin(vf[i] + large) 2933 if !close(f1, f2) { 2934 t.Errorf("Sin(%g) = %g, want %g", vf[i]+large, f2, f1) 2935 } 2936 } 2937 } 2938 2939 func TestLargeSincos(t *testing.T) { 2940 large := float64(100000 * Pi) 2941 for i := 0; i < len(vf); i++ { 2942 f1, g1 := sinLarge[i], cosLarge[i] 2943 f2, g2 := Sincos(vf[i] + large) 2944 if !close(f1, f2) || !close(g1, g2) { 2945 t.Errorf("Sincos(%g) = %g, %g, want %g, %g", vf[i]+large, f2, g2, f1, g1) 2946 } 2947 } 2948 } 2949 2950 func TestLargeTan(t *testing.T) { 2951 large := float64(100000 * Pi) 2952 for i := 0; i < len(vf); i++ { 2953 f1 := tanLarge[i] 2954 f2 := Tan(vf[i] + large) 2955 if !close(f1, f2) { 2956 t.Errorf("Tan(%g) = %g, want %g", vf[i]+large, f2, f1) 2957 } 2958 } 2959 } 2960 2961 // Check that math constants are accepted by compiler 2962 // and have right value (assumes strconv.ParseFloat works). 2963 // https://golang.org/issue/201 2964 2965 type floatTest struct { 2966 val interface{} 2967 name string 2968 str string 2969 } 2970 2971 var floatTests = []floatTest{ 2972 {float64(MaxFloat64), "MaxFloat64", "1.7976931348623157e+308"}, 2973 {float64(SmallestNonzeroFloat64), "SmallestNonzeroFloat64", "5e-324"}, 2974 {float32(MaxFloat32), "MaxFloat32", "3.4028235e+38"}, 2975 {float32(SmallestNonzeroFloat32), "SmallestNonzeroFloat32", "1e-45"}, 2976 } 2977 2978 func TestFloatMinMax(t *testing.T) { 2979 for _, tt := range floatTests { 2980 s := fmt.Sprint(tt.val) 2981 if s != tt.str { 2982 t.Errorf("Sprint(%v) = %s, want %s", tt.name, s, tt.str) 2983 } 2984 } 2985 } 2986 2987 // Benchmarks 2988 2989 // Global exported variables are used to store the 2990 // return values of functions measured in the benchmarks. 2991 // Storing the results in these variables prevents the compiler 2992 // from completely optimizing the benchmarked functions away. 2993 var ( 2994 GlobalI int 2995 GlobalB bool 2996 GlobalF float64 2997 ) 2998 2999 func BenchmarkAcos(b *testing.B) { 3000 x := 0.0 3001 for i := 0; i < b.N; i++ { 3002 x = Acos(.5) 3003 } 3004 GlobalF = x 3005 } 3006 3007 func BenchmarkAcosh(b *testing.B) { 3008 x := 0.0 3009 for i := 0; i < b.N; i++ { 3010 x = Acosh(1.5) 3011 } 3012 GlobalF = x 3013 } 3014 3015 func BenchmarkAsin(b *testing.B) { 3016 x := 0.0 3017 for i := 0; i < b.N; i++ { 3018 x = Asin(.5) 3019 } 3020 GlobalF = x 3021 } 3022 3023 func BenchmarkAsinh(b *testing.B) { 3024 x := 0.0 3025 for i := 0; i < b.N; i++ { 3026 x = Asinh(.5) 3027 } 3028 GlobalF = x 3029 } 3030 3031 func BenchmarkAtan(b *testing.B) { 3032 x := 0.0 3033 for i := 0; i < b.N; i++ { 3034 x = Atan(.5) 3035 } 3036 GlobalF = x 3037 } 3038 3039 func BenchmarkAtanh(b *testing.B) { 3040 x := 0.0 3041 for i := 0; i < b.N; i++ { 3042 x = Atanh(.5) 3043 } 3044 GlobalF = x 3045 } 3046 3047 func BenchmarkAtan2(b *testing.B) { 3048 x := 0.0 3049 for i := 0; i < b.N; i++ { 3050 x = Atan2(.5, 1) 3051 } 3052 GlobalF = x 3053 } 3054 3055 func BenchmarkCbrt(b *testing.B) { 3056 x := 0.0 3057 for i := 0; i < b.N; i++ { 3058 x = Cbrt(10) 3059 } 3060 GlobalF = x 3061 } 3062 3063 func BenchmarkCeil(b *testing.B) { 3064 x := 0.0 3065 for i := 0; i < b.N; i++ { 3066 x = Ceil(.5) 3067 } 3068 GlobalF = x 3069 } 3070 3071 func BenchmarkCopysign(b *testing.B) { 3072 x := 0.0 3073 for i := 0; i < b.N; i++ { 3074 x = Copysign(.5, -1) 3075 } 3076 GlobalF = x 3077 } 3078 3079 func BenchmarkCos(b *testing.B) { 3080 x := 0.0 3081 for i := 0; i < b.N; i++ { 3082 x = Cos(.5) 3083 } 3084 GlobalF = x 3085 } 3086 3087 func BenchmarkCosh(b *testing.B) { 3088 x := 0.0 3089 for i := 0; i < b.N; i++ { 3090 x = Cosh(2.5) 3091 } 3092 GlobalF = x 3093 } 3094 3095 func BenchmarkErf(b *testing.B) { 3096 x := 0.0 3097 for i := 0; i < b.N; i++ { 3098 x = Erf(.5) 3099 } 3100 GlobalF = x 3101 } 3102 3103 func BenchmarkErfc(b *testing.B) { 3104 x := 0.0 3105 for i := 0; i < b.N; i++ { 3106 x = Erfc(.5) 3107 } 3108 GlobalF = x 3109 } 3110 3111 func BenchmarkErfinv(b *testing.B) { 3112 x := 0.0 3113 for i := 0; i < b.N; i++ { 3114 x = Erfinv(.5) 3115 } 3116 GlobalF = x 3117 } 3118 3119 func BenchmarkErfcinv(b *testing.B) { 3120 x := 0.0 3121 for i := 0; i < b.N; i++ { 3122 x = Erfcinv(.5) 3123 } 3124 GlobalF = x 3125 } 3126 3127 func BenchmarkExp(b *testing.B) { 3128 x := 0.0 3129 for i := 0; i < b.N; i++ { 3130 x = Exp(.5) 3131 } 3132 GlobalF = x 3133 } 3134 3135 func BenchmarkExpGo(b *testing.B) { 3136 x := 0.0 3137 for i := 0; i < b.N; i++ { 3138 x = ExpGo(.5) 3139 } 3140 GlobalF = x 3141 } 3142 3143 func BenchmarkExpm1(b *testing.B) { 3144 x := 0.0 3145 for i := 0; i < b.N; i++ { 3146 x = Expm1(.5) 3147 } 3148 GlobalF = x 3149 } 3150 3151 func BenchmarkExp2(b *testing.B) { 3152 x := 0.0 3153 for i := 0; i < b.N; i++ { 3154 x = Exp2(.5) 3155 } 3156 GlobalF = x 3157 } 3158 3159 func BenchmarkExp2Go(b *testing.B) { 3160 x := 0.0 3161 for i := 0; i < b.N; i++ { 3162 x = Exp2Go(.5) 3163 } 3164 GlobalF = x 3165 } 3166 3167 func BenchmarkAbs(b *testing.B) { 3168 x := 0.0 3169 for i := 0; i < b.N; i++ { 3170 x = Abs(.5) 3171 } 3172 GlobalF = x 3173 3174 } 3175 3176 func BenchmarkDim(b *testing.B) { 3177 x := 0.0 3178 for i := 0; i < b.N; i++ { 3179 x = Dim(10, 3) 3180 } 3181 GlobalF = x 3182 } 3183 3184 func BenchmarkFloor(b *testing.B) { 3185 x := 0.0 3186 for i := 0; i < b.N; i++ { 3187 x = Floor(.5) 3188 } 3189 GlobalF = x 3190 } 3191 3192 func BenchmarkMax(b *testing.B) { 3193 x := 0.0 3194 for i := 0; i < b.N; i++ { 3195 x = Max(10, 3) 3196 } 3197 GlobalF = x 3198 } 3199 3200 func BenchmarkMin(b *testing.B) { 3201 x := 0.0 3202 for i := 0; i < b.N; i++ { 3203 x = Min(10, 3) 3204 } 3205 GlobalF = x 3206 } 3207 3208 func BenchmarkMod(b *testing.B) { 3209 x := 0.0 3210 for i := 0; i < b.N; i++ { 3211 x = Mod(10, 3) 3212 } 3213 GlobalF = x 3214 } 3215 3216 func BenchmarkFrexp(b *testing.B) { 3217 x := 0.0 3218 y := 0 3219 for i := 0; i < b.N; i++ { 3220 x, y = Frexp(8) 3221 } 3222 GlobalF = x 3223 GlobalI = y 3224 } 3225 3226 func BenchmarkGamma(b *testing.B) { 3227 x := 0.0 3228 for i := 0; i < b.N; i++ { 3229 x = Gamma(2.5) 3230 } 3231 GlobalF = x 3232 } 3233 3234 func BenchmarkHypot(b *testing.B) { 3235 x := 0.0 3236 for i := 0; i < b.N; i++ { 3237 x = Hypot(3, 4) 3238 } 3239 GlobalF = x 3240 } 3241 3242 func BenchmarkHypotGo(b *testing.B) { 3243 x := 0.0 3244 for i := 0; i < b.N; i++ { 3245 x = HypotGo(3, 4) 3246 } 3247 GlobalF = x 3248 } 3249 3250 func BenchmarkIlogb(b *testing.B) { 3251 x := 0 3252 for i := 0; i < b.N; i++ { 3253 x = Ilogb(.5) 3254 } 3255 GlobalI = x 3256 } 3257 3258 func BenchmarkJ0(b *testing.B) { 3259 x := 0.0 3260 for i := 0; i < b.N; i++ { 3261 x = J0(2.5) 3262 } 3263 GlobalF = x 3264 } 3265 3266 func BenchmarkJ1(b *testing.B) { 3267 x := 0.0 3268 for i := 0; i < b.N; i++ { 3269 x = J1(2.5) 3270 } 3271 GlobalF = x 3272 } 3273 3274 func BenchmarkJn(b *testing.B) { 3275 x := 0.0 3276 for i := 0; i < b.N; i++ { 3277 x = Jn(2, 2.5) 3278 } 3279 GlobalF = x 3280 } 3281 3282 func BenchmarkLdexp(b *testing.B) { 3283 x := 0.0 3284 for i := 0; i < b.N; i++ { 3285 x = Ldexp(.5, 2) 3286 } 3287 GlobalF = x 3288 } 3289 3290 func BenchmarkLgamma(b *testing.B) { 3291 x := 0.0 3292 y := 0 3293 for i := 0; i < b.N; i++ { 3294 x, y = Lgamma(2.5) 3295 } 3296 GlobalF = x 3297 GlobalI = y 3298 } 3299 3300 func BenchmarkLog(b *testing.B) { 3301 x := 0.0 3302 for i := 0; i < b.N; i++ { 3303 x = Log(.5) 3304 } 3305 GlobalF = x 3306 } 3307 3308 func BenchmarkLogb(b *testing.B) { 3309 x := 0.0 3310 for i := 0; i < b.N; i++ { 3311 x = Logb(.5) 3312 } 3313 GlobalF = x 3314 } 3315 3316 func BenchmarkLog1p(b *testing.B) { 3317 x := 0.0 3318 for i := 0; i < b.N; i++ { 3319 x = Log1p(.5) 3320 } 3321 GlobalF = x 3322 } 3323 3324 func BenchmarkLog10(b *testing.B) { 3325 x := 0.0 3326 for i := 0; i < b.N; i++ { 3327 x = Log10(.5) 3328 } 3329 GlobalF = x 3330 } 3331 3332 func BenchmarkLog2(b *testing.B) { 3333 x := 0.0 3334 for i := 0; i < b.N; i++ { 3335 x = Log2(.5) 3336 } 3337 GlobalF += x 3338 } 3339 3340 func BenchmarkModf(b *testing.B) { 3341 x := 0.0 3342 y := 0.0 3343 for i := 0; i < b.N; i++ { 3344 x, y = Modf(1.5) 3345 } 3346 GlobalF += x 3347 GlobalF += y 3348 } 3349 3350 func BenchmarkNextafter32(b *testing.B) { 3351 x := float32(0.0) 3352 for i := 0; i < b.N; i++ { 3353 x = Nextafter32(.5, 1) 3354 } 3355 GlobalF = float64(x) 3356 } 3357 3358 func BenchmarkNextafter64(b *testing.B) { 3359 x := 0.0 3360 for i := 0; i < b.N; i++ { 3361 x = Nextafter(.5, 1) 3362 } 3363 GlobalF = x 3364 } 3365 3366 func BenchmarkPowInt(b *testing.B) { 3367 x := 0.0 3368 for i := 0; i < b.N; i++ { 3369 x = Pow(2, 2) 3370 } 3371 GlobalF = x 3372 } 3373 3374 func BenchmarkPowFrac(b *testing.B) { 3375 x := 0.0 3376 for i := 0; i < b.N; i++ { 3377 x = Pow(2.5, 1.5) 3378 } 3379 GlobalF = x 3380 } 3381 3382 var pow10pos = int(300) 3383 3384 func BenchmarkPow10Pos(b *testing.B) { 3385 x := 0.0 3386 for i := 0; i < b.N; i++ { 3387 x = Pow10(pow10pos) 3388 } 3389 GlobalF = x 3390 } 3391 3392 var pow10neg = int(-300) 3393 3394 func BenchmarkPow10Neg(b *testing.B) { 3395 x := 0.0 3396 for i := 0; i < b.N; i++ { 3397 x = Pow10(pow10neg) 3398 } 3399 GlobalF = x 3400 } 3401 3402 var roundNeg = float64(-2.5) 3403 3404 func BenchmarkRound(b *testing.B) { 3405 x := 0.0 3406 for i := 0; i < b.N; i++ { 3407 x = Round(roundNeg) 3408 } 3409 GlobalF = x 3410 } 3411 3412 func BenchmarkRemainder(b *testing.B) { 3413 x := 0.0 3414 for i := 0; i < b.N; i++ { 3415 x = Remainder(10, 3) 3416 } 3417 GlobalF = x 3418 } 3419 3420 func BenchmarkSignbit(b *testing.B) { 3421 x := false 3422 for i := 0; i < b.N; i++ { 3423 x = Signbit(2.5) 3424 } 3425 GlobalB = x 3426 } 3427 3428 func BenchmarkSin(b *testing.B) { 3429 x := 0.0 3430 for i := 0; i < b.N; i++ { 3431 x = Sin(.5) 3432 } 3433 GlobalF = x 3434 } 3435 3436 func BenchmarkSincos(b *testing.B) { 3437 x := 0.0 3438 y := 0.0 3439 for i := 0; i < b.N; i++ { 3440 x, y = Sincos(.5) 3441 } 3442 GlobalF += x 3443 GlobalF += y 3444 } 3445 3446 func BenchmarkSinh(b *testing.B) { 3447 x := 0.0 3448 for i := 0; i < b.N; i++ { 3449 x = Sinh(2.5) 3450 } 3451 GlobalF = x 3452 } 3453 3454 func BenchmarkSqrtIndirect(b *testing.B) { 3455 x, y := 0.0, 10.0 3456 f := Sqrt 3457 for i := 0; i < b.N; i++ { 3458 x += f(y) 3459 } 3460 GlobalF = x 3461 } 3462 3463 func BenchmarkSqrtLatency(b *testing.B) { 3464 x := 10.0 3465 for i := 0; i < b.N; i++ { 3466 x = Sqrt(x) 3467 } 3468 GlobalF = x 3469 } 3470 3471 func BenchmarkSqrtIndirectLatency(b *testing.B) { 3472 x := 10.0 3473 f := Sqrt 3474 for i := 0; i < b.N; i++ { 3475 x = f(x) 3476 } 3477 GlobalF = x 3478 } 3479 3480 func BenchmarkSqrtGoLatency(b *testing.B) { 3481 x := 10.0 3482 for i := 0; i < b.N; i++ { 3483 x = SqrtGo(x) 3484 } 3485 GlobalF = x 3486 } 3487 3488 func isPrime(i int) bool { 3489 // Yes, this is a dumb way to write this code, 3490 // but calling Sqrt repeatedly in this way demonstrates 3491 // the benefit of using a direct SQRT instruction on systems 3492 // that have one, whereas the obvious loop seems not to 3493 // demonstrate such a benefit. 3494 for j := 2; float64(j) <= Sqrt(float64(i)); j++ { 3495 if i%j == 0 { 3496 return false 3497 } 3498 } 3499 return true 3500 } 3501 3502 func BenchmarkSqrtPrime(b *testing.B) { 3503 x := false 3504 for i := 0; i < b.N; i++ { 3505 x = isPrime(100003) 3506 } 3507 GlobalB = x 3508 } 3509 3510 func BenchmarkTan(b *testing.B) { 3511 x := 0.0 3512 for i := 0; i < b.N; i++ { 3513 x = Tan(.5) 3514 } 3515 GlobalF = x 3516 } 3517 3518 func BenchmarkTanh(b *testing.B) { 3519 x := 0.0 3520 for i := 0; i < b.N; i++ { 3521 x = Tanh(2.5) 3522 } 3523 GlobalF = x 3524 } 3525 func BenchmarkTrunc(b *testing.B) { 3526 x := 0.0 3527 for i := 0; i < b.N; i++ { 3528 x = Trunc(.5) 3529 } 3530 GlobalF = x 3531 } 3532 3533 func BenchmarkY0(b *testing.B) { 3534 x := 0.0 3535 for i := 0; i < b.N; i++ { 3536 x = Y0(2.5) 3537 } 3538 GlobalF = x 3539 } 3540 3541 func BenchmarkY1(b *testing.B) { 3542 x := 0.0 3543 for i := 0; i < b.N; i++ { 3544 x = Y1(2.5) 3545 } 3546 GlobalF = x 3547 } 3548 3549 func BenchmarkYn(b *testing.B) { 3550 x := 0.0 3551 for i := 0; i < b.N; i++ { 3552 x = Yn(2, 2.5) 3553 } 3554 GlobalF = x 3555 }