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