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