1 // Copyright 2010 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 cmplx 6 7 import ( 8 "math" 9 "testing" 10 ) 11 12 var vc26 = []complex128{ 13 (4.97901192488367350108546816 + 7.73887247457810456552351752i), 14 (7.73887247457810456552351752 - 0.27688005719200159404635997i), 15 (-0.27688005719200159404635997 - 5.01060361827107492160848778i), 16 (-5.01060361827107492160848778 + 9.63629370719841737980004837i), 17 (9.63629370719841737980004837 + 2.92637723924396464525443662i), 18 (2.92637723924396464525443662 + 5.22908343145930665230025625i), 19 (5.22908343145930665230025625 + 2.72793991043601025126008608i), 20 (2.72793991043601025126008608 + 1.82530809168085506044576505i), 21 (1.82530809168085506044576505 - 8.68592476857560136238589621i), 22 (-8.68592476857560136238589621 + 4.97901192488367350108546816i), 23 } 24 var vc = []complex128{ 25 (4.9790119248836735e+00 + 7.7388724745781045e+00i), 26 (7.7388724745781045e+00 - 2.7688005719200159e-01i), 27 (-2.7688005719200159e-01 - 5.0106036182710749e+00i), 28 (-5.0106036182710749e+00 + 9.6362937071984173e+00i), 29 (9.6362937071984173e+00 + 2.9263772392439646e+00i), 30 (2.9263772392439646e+00 + 5.2290834314593066e+00i), 31 (5.2290834314593066e+00 + 2.7279399104360102e+00i), 32 (2.7279399104360102e+00 + 1.8253080916808550e+00i), 33 (1.8253080916808550e+00 - 8.6859247685756013e+00i), 34 (-8.6859247685756013e+00 + 4.9790119248836735e+00i), 35 } 36 37 // The expected results below were computed by the high precision calculators 38 // at http://keisan.casio.com/. More exact input values (array vc[], above) 39 // were obtained by printing them with "%.26f". The answers were calculated 40 // to 26 digits (by using the "Digit number" drop-down control of each 41 // calculator). 42 43 var abs = []float64{ 44 9.2022120669932650313380972e+00, 45 7.7438239742296106616261394e+00, 46 5.0182478202557746902556648e+00, 47 1.0861137372799545160704002e+01, 48 1.0070841084922199607011905e+01, 49 5.9922447613166942183705192e+00, 50 5.8978784056736762299945176e+00, 51 3.2822866700678709020367184e+00, 52 8.8756430028990417290744307e+00, 53 1.0011785496777731986390856e+01, 54 } 55 56 var acos = []complex128{ 57 (1.0017679804707456328694569 - 2.9138232718554953784519807i), 58 (0.03606427612041407369636057 + 2.7358584434576260925091256i), 59 (1.6249365462333796703711823 + 2.3159537454335901187730929i), 60 (2.0485650849650740120660391 - 3.0795576791204117911123886i), 61 (0.29621132089073067282488147 - 3.0007392508200622519398814i), 62 (1.0664555914934156601503632 - 2.4872865024796011364747111i), 63 (0.48681307452231387690013905 - 2.463655912283054555225301i), 64 (0.6116977071277574248407752 - 1.8734458851737055262693056i), 65 (1.3649311280370181331184214 + 2.8793528632328795424123832i), 66 (2.6189310485682988308904501 - 2.9956543302898767795858704i), 67 } 68 var acosh = []complex128{ 69 (2.9138232718554953784519807 + 1.0017679804707456328694569i), 70 (2.7358584434576260925091256 - 0.03606427612041407369636057i), 71 (2.3159537454335901187730929 - 1.6249365462333796703711823i), 72 (3.0795576791204117911123886 + 2.0485650849650740120660391i), 73 (3.0007392508200622519398814 + 0.29621132089073067282488147i), 74 (2.4872865024796011364747111 + 1.0664555914934156601503632i), 75 (2.463655912283054555225301 + 0.48681307452231387690013905i), 76 (1.8734458851737055262693056 + 0.6116977071277574248407752i), 77 (2.8793528632328795424123832 - 1.3649311280370181331184214i), 78 (2.9956543302898767795858704 + 2.6189310485682988308904501i), 79 } 80 var asin = []complex128{ 81 (0.56902834632415098636186476 + 2.9138232718554953784519807i), 82 (1.5347320506744825455349611 - 2.7358584434576260925091256i), 83 (-0.054140219438483051139860579 - 2.3159537454335901187730929i), 84 (-0.47776875817017739283471738 + 3.0795576791204117911123886i), 85 (1.2745850059041659464064402 + 3.0007392508200622519398814i), 86 (0.50434073530148095908095852 + 2.4872865024796011364747111i), 87 (1.0839832522725827423311826 + 2.463655912283054555225301i), 88 (0.9590986196671391943905465 + 1.8734458851737055262693056i), 89 (0.20586519875787848611290031 - 2.8793528632328795424123832i), 90 (-1.0481347217734022116591284 + 2.9956543302898767795858704i), 91 } 92 var asinh = []complex128{ 93 (2.9113760469415295679342185 + 0.99639459545704326759805893i), 94 (2.7441755423994259061579029 - 0.035468308789000500601119392i), 95 (-2.2962136462520690506126678 - 1.5144663565690151885726707i), 96 (-3.0771233459295725965402455 + 1.0895577967194013849422294i), 97 (3.0048366100923647417557027 + 0.29346979169819220036454168i), 98 (2.4800059370795363157364643 + 1.0545868606049165710424232i), 99 (2.4718773838309585611141821 + 0.47502344364250803363708842i), 100 (1.8910743588080159144378396 + 0.56882925572563602341139174i), 101 (2.8735426423367341878069406 - 1.362376149648891420997548i), 102 (-2.9981750586172477217567878 + 0.5183571985225367505624207i), 103 } 104 var atan = []complex128{ 105 (1.5115747079332741358607654 + 0.091324403603954494382276776i), 106 (1.4424504323482602560806727 - 0.0045416132642803911503770933i), 107 (-1.5593488703630532674484026 - 0.20163295409248362456446431i), 108 (-1.5280619472445889867794105 + 0.081721556230672003746956324i), 109 (1.4759909163240799678221039 + 0.028602969320691644358773586i), 110 (1.4877353772046548932715555 + 0.14566877153207281663773599i), 111 (1.4206983927779191889826 + 0.076830486127880702249439993i), 112 (1.3162236060498933364869556 + 0.16031313000467530644933363i), 113 (1.5473450684303703578810093 - 0.11064907507939082484935782i), 114 (-1.4841462340185253987375812 + 0.049341850305024399493142411i), 115 } 116 var atanh = []complex128{ 117 (0.058375027938968509064640438 + 1.4793488495105334458167782i), 118 (0.12977343497790381229915667 - 1.5661009410463561327262499i), 119 (-0.010576456067347252072200088 - 1.3743698658402284549750563i), 120 (-0.042218595678688358882784918 + 1.4891433968166405606692604i), 121 (0.095218997991316722061828397 + 1.5416884098777110330499698i), 122 (0.079965459366890323857556487 + 1.4252510353873192700350435i), 123 (0.15051245471980726221708301 + 1.4907432533016303804884461i), 124 (0.25082072933993987714470373 + 1.392057665392187516442986i), 125 (0.022896108815797135846276662 - 1.4609224989282864208963021i), 126 (-0.08665624101841876130537396 + 1.5207902036935093480142159i), 127 } 128 var conj = []complex128{ 129 (4.9790119248836735e+00 - 7.7388724745781045e+00i), 130 (7.7388724745781045e+00 + 2.7688005719200159e-01i), 131 (-2.7688005719200159e-01 + 5.0106036182710749e+00i), 132 (-5.0106036182710749e+00 - 9.6362937071984173e+00i), 133 (9.6362937071984173e+00 - 2.9263772392439646e+00i), 134 (2.9263772392439646e+00 - 5.2290834314593066e+00i), 135 (5.2290834314593066e+00 - 2.7279399104360102e+00i), 136 (2.7279399104360102e+00 - 1.8253080916808550e+00i), 137 (1.8253080916808550e+00 + 8.6859247685756013e+00i), 138 (-8.6859247685756013e+00 - 4.9790119248836735e+00i), 139 } 140 var cos = []complex128{ 141 (3.024540920601483938336569e+02 + 1.1073797572517071650045357e+03i), 142 (1.192858682649064973252758e-01 + 2.7857554122333065540970207e-01i), 143 (7.2144394304528306603857962e+01 - 2.0500129667076044169954205e+01i), 144 (2.24921952538403984190541e+03 - 7.317363745602773587049329e+03i), 145 (-9.148222970032421760015498e+00 + 1.953124661113563541862227e+00i), 146 (-9.116081175857732248227078e+01 - 1.992669213569952232487371e+01i), 147 (3.795639179042704640002918e+00 + 6.623513350981458399309662e+00i), 148 (-2.9144840732498869560679084e+00 - 1.214620271628002917638748e+00i), 149 (-7.45123482501299743872481e+02 + 2.8641692314488080814066734e+03i), 150 (-5.371977967039319076416747e+01 + 4.893348341339375830564624e+01i), 151 } 152 var cosh = []complex128{ 153 (8.34638383523018249366948e+00 + 7.2181057886425846415112064e+01i), 154 (1.10421967379919366952251e+03 - 3.1379638689277575379469861e+02i), 155 (3.051485206773701584738512e-01 - 2.6805384730105297848044485e-01i), 156 (-7.33294728684187933370938e+01 + 1.574445942284918251038144e+01i), 157 (-7.478643293945957535757355e+03 + 1.6348382209913353929473321e+03i), 158 (4.622316522966235701630926e+00 - 8.088695185566375256093098e+00i), 159 (-8.544333183278877406197712e+01 + 3.7505836120128166455231717e+01i), 160 (-1.934457815021493925115198e+00 + 7.3725859611767228178358673e+00i), 161 (-2.352958770061749348353548e+00 - 2.034982010440878358915409e+00i), 162 (7.79756457532134748165069e+02 + 2.8549350716819176560377717e+03i), 163 } 164 var exp = []complex128{ 165 (1.669197736864670815125146e+01 + 1.4436895109507663689174096e+02i), 166 (2.2084389286252583447276212e+03 - 6.2759289284909211238261917e+02i), 167 (2.227538273122775173434327e-01 + 7.2468284028334191250470034e-01i), 168 (-6.5182985958153548997881627e-03 - 1.39965837915193860879044e-03i), 169 (-1.4957286524084015746110777e+04 + 3.269676455931135688988042e+03i), 170 (9.218158701983105935659273e+00 - 1.6223985291084956009304582e+01i), 171 (-1.7088175716853040841444505e+02 + 7.501382609870410713795546e+01i), 172 (-3.852461315830959613132505e+00 + 1.4808420423156073221970892e+01i), 173 (-4.586775503301407379786695e+00 - 4.178501081246873415144744e+00i), 174 (4.451337963005453491095747e-05 - 1.62977574205442915935263e-04i), 175 } 176 var log = []complex128{ 177 (2.2194438972179194425697051e+00 + 9.9909115046919291062461269e-01i), 178 (2.0468956191154167256337289e+00 - 3.5762575021856971295156489e-02i), 179 (1.6130808329853860438751244e+00 - 1.6259990074019058442232221e+00i), 180 (2.3851910394823008710032651e+00 + 2.0502936359659111755031062e+00i), 181 (2.3096442270679923004800651e+00 + 2.9483213155446756211881774e-01i), 182 (1.7904660933974656106951860e+00 + 1.0605860367252556281902109e+00i), 183 (1.7745926939841751666177512e+00 + 4.8084556083358307819310911e-01i), 184 (1.1885403350045342425648780e+00 + 5.8969634164776659423195222e-01i), 185 (2.1833107837679082586772505e+00 - 1.3636647724582455028314573e+00i), 186 (2.3037629487273259170991671e+00 + 2.6210913895386013290915234e+00i), 187 } 188 var log10 = []complex128{ 189 (9.6389223745559042474184943e-01 + 4.338997735671419492599631e-01i), 190 (8.8895547241376579493490892e-01 - 1.5531488990643548254864806e-02i), 191 (7.0055210462945412305244578e-01 - 7.0616239649481243222248404e-01i), 192 (1.0358753067322445311676952e+00 + 8.9043121238134980156490909e-01i), 193 (1.003065742975330237172029e+00 + 1.2804396782187887479857811e-01i), 194 (7.7758954439739162532085157e-01 + 4.6060666333341810869055108e-01i), 195 (7.7069581462315327037689152e-01 + 2.0882857371769952195512475e-01i), 196 (5.1617650901191156135137239e-01 + 2.5610186717615977620363299e-01i), 197 (9.4819982567026639742663212e-01 - 5.9223208584446952284914289e-01i), 198 (1.0005115362454417135973429e+00 + 1.1383255270407412817250921e+00i), 199 } 200 201 type ff struct { 202 r, theta float64 203 } 204 205 var polar = []ff{ 206 {9.2022120669932650313380972e+00, 9.9909115046919291062461269e-01}, 207 {7.7438239742296106616261394e+00, -3.5762575021856971295156489e-02}, 208 {5.0182478202557746902556648e+00, -1.6259990074019058442232221e+00}, 209 {1.0861137372799545160704002e+01, 2.0502936359659111755031062e+00}, 210 {1.0070841084922199607011905e+01, 2.9483213155446756211881774e-01}, 211 {5.9922447613166942183705192e+00, 1.0605860367252556281902109e+00}, 212 {5.8978784056736762299945176e+00, 4.8084556083358307819310911e-01}, 213 {3.2822866700678709020367184e+00, 5.8969634164776659423195222e-01}, 214 {8.8756430028990417290744307e+00, -1.3636647724582455028314573e+00}, 215 {1.0011785496777731986390856e+01, 2.6210913895386013290915234e+00}, 216 } 217 var pow = []complex128{ 218 (-2.499956739197529585028819e+00 + 1.759751724335650228957144e+00i), 219 (7.357094338218116311191939e+04 - 5.089973412479151648145882e+04i), 220 (1.320777296067768517259592e+01 - 3.165621914333901498921986e+01i), 221 (-3.123287828297300934072149e-07 - 1.9849567521490553032502223E-7i), 222 (8.0622651468477229614813e+04 - 7.80028727944573092944363e+04i), 223 (-1.0268824572103165858577141e+00 - 4.716844738244989776610672e-01i), 224 (-4.35953819012244175753187e+01 + 2.2036445974645306917648585e+02i), 225 (8.3556092283250594950239e-01 - 1.2261571947167240272593282e+01i), 226 (1.582292972120769306069625e+03 + 1.273564263524278244782512e+04i), 227 (6.592208301642122149025369e-08 + 2.584887236651661903526389e-08i), 228 } 229 var sin = []complex128{ 230 (-1.1073801774240233539648544e+03 + 3.024539773002502192425231e+02i), 231 (1.0317037521400759359744682e+00 - 3.2208979799929570242818e-02i), 232 (-2.0501952097271429804261058e+01 - 7.2137981348240798841800967e+01i), 233 (7.3173638080346338642193078e+03 + 2.249219506193664342566248e+03i), 234 (-1.964375633631808177565226e+00 - 9.0958264713870404464159683e+00i), 235 (1.992783647158514838337674e+01 - 9.11555769410191350416942e+01i), 236 (-6.680335650741921444300349e+00 + 3.763353833142432513086117e+00i), 237 (1.2794028166657459148245993e+00 - 2.7669092099795781155109602e+00i), 238 (2.8641693949535259594188879e+03 + 7.451234399649871202841615e+02i), 239 (-4.893811726244659135553033e+01 - 5.371469305562194635957655e+01i), 240 } 241 var sinh = []complex128{ 242 (8.34559353341652565758198e+00 + 7.2187893208650790476628899e+01i), 243 (1.1042192548260646752051112e+03 - 3.1379650595631635858792056e+02i), 244 (-8.239469336509264113041849e-02 + 9.9273668758439489098514519e-01i), 245 (7.332295456982297798219401e+01 - 1.574585908122833444899023e+01i), 246 (-7.4786432301380582103534216e+03 + 1.63483823493980029604071e+03i), 247 (4.595842179016870234028347e+00 - 8.135290105518580753211484e+00i), 248 (-8.543842533574163435246793e+01 + 3.750798997857594068272375e+01i), 249 (-1.918003500809465688017307e+00 + 7.4358344619793504041350251e+00i), 250 (-2.233816733239658031433147e+00 - 2.143519070805995056229335e+00i), 251 (-7.797564130187551181105341e+02 - 2.8549352346594918614806877e+03i), 252 } 253 var sqrt = []complex128{ 254 (2.6628203086086130543813948e+00 + 1.4531345674282185229796902e+00i), 255 (2.7823278427251986247149295e+00 - 4.9756907317005224529115567e-02i), 256 (1.5397025302089642757361015e+00 - 1.6271336573016637535695727e+00i), 257 (1.7103411581506875260277898e+00 + 2.8170677122737589676157029e+00i), 258 (3.1390392472953103383607947e+00 + 4.6612625849858653248980849e-01i), 259 (2.1117080764822417640789287e+00 + 1.2381170223514273234967850e+00i), 260 (2.3587032281672256703926939e+00 + 5.7827111903257349935720172e-01i), 261 (1.7335262588873410476661577e+00 + 5.2647258220721269141550382e-01i), 262 (2.3131094974708716531499282e+00 - 1.8775429304303785570775490e+00i), 263 (8.1420535745048086240947359e-01 + 3.0575897587277248522656113e+00i), 264 } 265 var tan = []complex128{ 266 (-1.928757919086441129134525e-07 + 1.0000003267499169073251826e+00i), 267 (1.242412685364183792138948e+00 - 3.17149693883133370106696e+00i), 268 (-4.6745126251587795225571826e-05 - 9.9992439225263959286114298e-01i), 269 (4.792363401193648192887116e-09 + 1.0000000070589333451557723e+00i), 270 (2.345740824080089140287315e-03 + 9.947733046570988661022763e-01i), 271 (-2.396030789494815566088809e-05 + 9.9994781345418591429826779e-01i), 272 (-7.370204836644931340905303e-03 + 1.0043553413417138987717748e+00i), 273 (-3.691803847992048527007457e-02 + 9.6475071993469548066328894e-01i), 274 (-2.781955256713729368401878e-08 - 1.000000049848910609006646e+00i), 275 (9.4281590064030478879791249e-05 + 9.9999119340863718183758545e-01i), 276 } 277 var tanh = []complex128{ 278 (1.0000921981225144748819918e+00 + 2.160986245871518020231507e-05i), 279 (9.9999967727531993209562591e-01 - 1.9953763222959658873657676e-07i), 280 (-1.765485739548037260789686e+00 + 1.7024216325552852445168471e+00i), 281 (-9.999189442732736452807108e-01 + 3.64906070494473701938098e-05i), 282 (9.9999999224622333738729767e-01 - 3.560088949517914774813046e-09i), 283 (1.0029324933367326862499343e+00 - 4.948790309797102353137528e-03i), 284 (9.9996113064788012488693567e-01 - 4.226995742097032481451259e-05i), 285 (1.0074784189316340029873945e+00 - 4.194050814891697808029407e-03i), 286 (9.9385534229718327109131502e-01 + 5.144217985914355502713437e-02i), 287 (-1.0000000491604982429364892e+00 - 2.901873195374433112227349e-08i), 288 } 289 290 // special cases 291 var vcAbsSC = []complex128{ 292 NaN(), 293 } 294 var absSC = []float64{ 295 math.NaN(), 296 } 297 var vcAcosSC = []complex128{ 298 NaN(), 299 } 300 var acosSC = []complex128{ 301 NaN(), 302 } 303 var vcAcoshSC = []complex128{ 304 NaN(), 305 } 306 var acoshSC = []complex128{ 307 NaN(), 308 } 309 var vcAsinSC = []complex128{ 310 NaN(), 311 } 312 var asinSC = []complex128{ 313 NaN(), 314 } 315 var vcAsinhSC = []complex128{ 316 NaN(), 317 } 318 var asinhSC = []complex128{ 319 NaN(), 320 } 321 var vcAtanSC = []complex128{ 322 NaN(), 323 } 324 var atanSC = []complex128{ 325 NaN(), 326 } 327 var vcAtanhSC = []complex128{ 328 NaN(), 329 } 330 var atanhSC = []complex128{ 331 NaN(), 332 } 333 var vcConjSC = []complex128{ 334 NaN(), 335 } 336 var conjSC = []complex128{ 337 NaN(), 338 } 339 var vcCosSC = []complex128{ 340 NaN(), 341 } 342 var cosSC = []complex128{ 343 NaN(), 344 } 345 var vcCoshSC = []complex128{ 346 NaN(), 347 } 348 var coshSC = []complex128{ 349 NaN(), 350 } 351 var vcExpSC = []complex128{ 352 NaN(), 353 } 354 var expSC = []complex128{ 355 NaN(), 356 } 357 var vcIsNaNSC = []complex128{ 358 complex(math.Inf(-1), math.Inf(-1)), 359 complex(math.Inf(-1), math.NaN()), 360 complex(math.NaN(), math.Inf(-1)), 361 complex(0, math.NaN()), 362 complex(math.NaN(), 0), 363 complex(math.Inf(1), math.Inf(1)), 364 complex(math.Inf(1), math.NaN()), 365 complex(math.NaN(), math.Inf(1)), 366 complex(math.NaN(), math.NaN()), 367 } 368 var isNaNSC = []bool{ 369 false, 370 false, 371 false, 372 true, 373 true, 374 false, 375 false, 376 false, 377 true, 378 } 379 var vcLogSC = []complex128{ 380 NaN(), 381 } 382 var logSC = []complex128{ 383 NaN(), 384 } 385 var vcLog10SC = []complex128{ 386 NaN(), 387 } 388 var log10SC = []complex128{ 389 NaN(), 390 } 391 var vcPolarSC = []complex128{ 392 NaN(), 393 } 394 var polarSC = []ff{ 395 {math.NaN(), math.NaN()}, 396 } 397 var vcPowSC = [][2]complex128{ 398 {NaN(), NaN()}, 399 } 400 var powSC = []complex128{ 401 NaN(), 402 } 403 var vcSinSC = []complex128{ 404 NaN(), 405 } 406 var sinSC = []complex128{ 407 NaN(), 408 } 409 var vcSinhSC = []complex128{ 410 NaN(), 411 } 412 var sinhSC = []complex128{ 413 NaN(), 414 } 415 var vcSqrtSC = []complex128{ 416 NaN(), 417 } 418 var sqrtSC = []complex128{ 419 NaN(), 420 } 421 var vcTanSC = []complex128{ 422 NaN(), 423 } 424 var tanSC = []complex128{ 425 NaN(), 426 } 427 var vcTanhSC = []complex128{ 428 NaN(), 429 } 430 var tanhSC = []complex128{ 431 NaN(), 432 } 433 434 // functions borrowed from pkg/math/all_test.go 435 func tolerance(a, b, e float64) bool { 436 d := a - b 437 if d < 0 { 438 d = -d 439 } 440 441 if a != 0 { 442 e = e * a 443 if e < 0 { 444 e = -e 445 } 446 } 447 return d < e 448 } 449 func soclose(a, b, e float64) bool { return tolerance(a, b, e) } 450 func veryclose(a, b float64) bool { return tolerance(a, b, 4e-16) } 451 func alike(a, b float64) bool { 452 switch { 453 case a != a && b != b: // math.IsNaN(a) && math.IsNaN(b): 454 return true 455 case a == b: 456 return math.Signbit(a) == math.Signbit(b) 457 } 458 return false 459 } 460 461 func cTolerance(a, b complex128, e float64) bool { 462 d := Abs(a - b) 463 if a != 0 { 464 e = e * Abs(a) 465 if e < 0 { 466 e = -e 467 } 468 } 469 return d < e 470 } 471 func cSoclose(a, b complex128, e float64) bool { return cTolerance(a, b, e) } 472 func cVeryclose(a, b complex128) bool { return cTolerance(a, b, 4e-16) } 473 func cAlike(a, b complex128) bool { 474 switch { 475 case IsNaN(a) && IsNaN(b): 476 return true 477 case a == b: 478 return math.Signbit(real(a)) == math.Signbit(real(b)) && math.Signbit(imag(a)) == math.Signbit(imag(b)) 479 } 480 return false 481 } 482 483 func TestAbs(t *testing.T) { 484 for i := 0; i < len(vc); i++ { 485 if f := Abs(vc[i]); !veryclose(abs[i], f) { 486 t.Errorf("Abs(%g) = %g, want %g", vc[i], f, abs[i]) 487 } 488 } 489 for i := 0; i < len(vcAbsSC); i++ { 490 if f := Abs(vcAbsSC[i]); !alike(absSC[i], f) { 491 t.Errorf("Abs(%g) = %g, want %g", vcAbsSC[i], f, absSC[i]) 492 } 493 } 494 } 495 func TestAcos(t *testing.T) { 496 for i := 0; i < len(vc); i++ { 497 if f := Acos(vc[i]); !cSoclose(acos[i], f, 1e-14) { 498 t.Errorf("Acos(%g) = %g, want %g", vc[i], f, acos[i]) 499 } 500 } 501 for i := 0; i < len(vcAcosSC); i++ { 502 if f := Acos(vcAcosSC[i]); !cAlike(acosSC[i], f) { 503 t.Errorf("Acos(%g) = %g, want %g", vcAcosSC[i], f, acosSC[i]) 504 } 505 } 506 } 507 func TestAcosh(t *testing.T) { 508 for i := 0; i < len(vc); i++ { 509 if f := Acosh(vc[i]); !cSoclose(acosh[i], f, 1e-14) { 510 t.Errorf("Acosh(%g) = %g, want %g", vc[i], f, acosh[i]) 511 } 512 } 513 for i := 0; i < len(vcAcoshSC); i++ { 514 if f := Acosh(vcAcoshSC[i]); !cAlike(acoshSC[i], f) { 515 t.Errorf("Acosh(%g) = %g, want %g", vcAcoshSC[i], f, acoshSC[i]) 516 } 517 } 518 } 519 func TestAsin(t *testing.T) { 520 for i := 0; i < len(vc); i++ { 521 if f := Asin(vc[i]); !cSoclose(asin[i], f, 1e-14) { 522 t.Errorf("Asin(%g) = %g, want %g", vc[i], f, asin[i]) 523 } 524 } 525 for i := 0; i < len(vcAsinSC); i++ { 526 if f := Asin(vcAsinSC[i]); !cAlike(asinSC[i], f) { 527 t.Errorf("Asin(%g) = %g, want %g", vcAsinSC[i], f, asinSC[i]) 528 } 529 } 530 } 531 func TestAsinh(t *testing.T) { 532 for i := 0; i < len(vc); i++ { 533 if f := Asinh(vc[i]); !cSoclose(asinh[i], f, 4e-15) { 534 t.Errorf("Asinh(%g) = %g, want %g", vc[i], f, asinh[i]) 535 } 536 } 537 for i := 0; i < len(vcAsinhSC); i++ { 538 if f := Asinh(vcAsinhSC[i]); !cAlike(asinhSC[i], f) { 539 t.Errorf("Asinh(%g) = %g, want %g", vcAsinhSC[i], f, asinhSC[i]) 540 } 541 } 542 } 543 func TestAtan(t *testing.T) { 544 for i := 0; i < len(vc); i++ { 545 if f := Atan(vc[i]); !cVeryclose(atan[i], f) { 546 t.Errorf("Atan(%g) = %g, want %g", vc[i], f, atan[i]) 547 } 548 } 549 for i := 0; i < len(vcAtanSC); i++ { 550 if f := Atan(vcAtanSC[i]); !cAlike(atanSC[i], f) { 551 t.Errorf("Atan(%g) = %g, want %g", vcAtanSC[i], f, atanSC[i]) 552 } 553 } 554 } 555 func TestAtanh(t *testing.T) { 556 for i := 0; i < len(vc); i++ { 557 if f := Atanh(vc[i]); !cVeryclose(atanh[i], f) { 558 t.Errorf("Atanh(%g) = %g, want %g", vc[i], f, atanh[i]) 559 } 560 } 561 for i := 0; i < len(vcAtanhSC); i++ { 562 if f := Atanh(vcAtanhSC[i]); !cAlike(atanhSC[i], f) { 563 t.Errorf("Atanh(%g) = %g, want %g", vcAtanhSC[i], f, atanhSC[i]) 564 } 565 } 566 } 567 func TestConj(t *testing.T) { 568 for i := 0; i < len(vc); i++ { 569 if f := Conj(vc[i]); !cVeryclose(conj[i], f) { 570 t.Errorf("Conj(%g) = %g, want %g", vc[i], f, conj[i]) 571 } 572 } 573 for i := 0; i < len(vcConjSC); i++ { 574 if f := Conj(vcConjSC[i]); !cAlike(conjSC[i], f) { 575 t.Errorf("Conj(%g) = %g, want %g", vcConjSC[i], f, conjSC[i]) 576 } 577 } 578 } 579 func TestCos(t *testing.T) { 580 for i := 0; i < len(vc); i++ { 581 if f := Cos(vc[i]); !cSoclose(cos[i], f, 3e-15) { 582 t.Errorf("Cos(%g) = %g, want %g", vc[i], f, cos[i]) 583 } 584 } 585 for i := 0; i < len(vcCosSC); i++ { 586 if f := Cos(vcCosSC[i]); !cAlike(cosSC[i], f) { 587 t.Errorf("Cos(%g) = %g, want %g", vcCosSC[i], f, cosSC[i]) 588 } 589 } 590 } 591 func TestCosh(t *testing.T) { 592 for i := 0; i < len(vc); i++ { 593 if f := Cosh(vc[i]); !cSoclose(cosh[i], f, 2e-15) { 594 t.Errorf("Cosh(%g) = %g, want %g", vc[i], f, cosh[i]) 595 } 596 } 597 for i := 0; i < len(vcCoshSC); i++ { 598 if f := Cosh(vcCoshSC[i]); !cAlike(coshSC[i], f) { 599 t.Errorf("Cosh(%g) = %g, want %g", vcCoshSC[i], f, coshSC[i]) 600 } 601 } 602 } 603 func TestExp(t *testing.T) { 604 for i := 0; i < len(vc); i++ { 605 if f := Exp(vc[i]); !cSoclose(exp[i], f, 1e-15) { 606 t.Errorf("Exp(%g) = %g, want %g", vc[i], f, exp[i]) 607 } 608 } 609 for i := 0; i < len(vcExpSC); i++ { 610 if f := Exp(vcExpSC[i]); !cAlike(expSC[i], f) { 611 t.Errorf("Exp(%g) = %g, want %g", vcExpSC[i], f, expSC[i]) 612 } 613 } 614 } 615 func TestIsNaN(t *testing.T) { 616 for i := 0; i < len(vcIsNaNSC); i++ { 617 if f := IsNaN(vcIsNaNSC[i]); isNaNSC[i] != f { 618 t.Errorf("IsNaN(%v) = %v, want %v", vcIsNaNSC[i], f, isNaNSC[i]) 619 } 620 } 621 } 622 func TestLog(t *testing.T) { 623 for i := 0; i < len(vc); i++ { 624 if f := Log(vc[i]); !cVeryclose(log[i], f) { 625 t.Errorf("Log(%g) = %g, want %g", vc[i], f, log[i]) 626 } 627 } 628 for i := 0; i < len(vcLogSC); i++ { 629 if f := Log(vcLogSC[i]); !cAlike(logSC[i], f) { 630 t.Errorf("Log(%g) = %g, want %g", vcLogSC[i], f, logSC[i]) 631 } 632 } 633 } 634 func TestLog10(t *testing.T) { 635 for i := 0; i < len(vc); i++ { 636 if f := Log10(vc[i]); !cVeryclose(log10[i], f) { 637 t.Errorf("Log10(%g) = %g, want %g", vc[i], f, log10[i]) 638 } 639 } 640 for i := 0; i < len(vcLog10SC); i++ { 641 if f := Log10(vcLog10SC[i]); !cAlike(log10SC[i], f) { 642 t.Errorf("Log10(%g) = %g, want %g", vcLog10SC[i], f, log10SC[i]) 643 } 644 } 645 } 646 func TestPolar(t *testing.T) { 647 for i := 0; i < len(vc); i++ { 648 if r, theta := Polar(vc[i]); !veryclose(polar[i].r, r) && !veryclose(polar[i].theta, theta) { 649 t.Errorf("Polar(%g) = %g, %g want %g, %g", vc[i], r, theta, polar[i].r, polar[i].theta) 650 } 651 } 652 for i := 0; i < len(vcPolarSC); i++ { 653 if r, theta := Polar(vcPolarSC[i]); !alike(polarSC[i].r, r) && !alike(polarSC[i].theta, theta) { 654 t.Errorf("Polar(%g) = %g, %g, want %g, %g", vcPolarSC[i], r, theta, polarSC[i].r, polarSC[i].theta) 655 } 656 } 657 } 658 func TestPow(t *testing.T) { 659 // Special cases for Pow(0, c). 660 var zero = complex(0, 0) 661 zeroPowers := [][2]complex128{ 662 {0, 1 + 0i}, 663 {1.5, 0 + 0i}, 664 {-1.5, complex(math.Inf(0), 0)}, 665 {-1.5 + 1.5i, Inf()}, 666 } 667 for _, zp := range zeroPowers { 668 if f := Pow(zero, zp[0]); f != zp[1] { 669 t.Errorf("Pow(%g, %g) = %g, want %g", zero, zp[0], f, zp[1]) 670 } 671 } 672 var a = complex(3.0, 3.0) 673 for i := 0; i < len(vc); i++ { 674 if f := Pow(a, vc[i]); !cSoclose(pow[i], f, 4e-15) { 675 t.Errorf("Pow(%g, %g) = %g, want %g", a, vc[i], f, pow[i]) 676 } 677 } 678 for i := 0; i < len(vcPowSC); i++ { 679 if f := Pow(vcPowSC[i][0], vcPowSC[i][0]); !cAlike(powSC[i], f) { 680 t.Errorf("Pow(%g, %g) = %g, want %g", vcPowSC[i][0], vcPowSC[i][0], f, powSC[i]) 681 } 682 } 683 } 684 func TestRect(t *testing.T) { 685 for i := 0; i < len(vc); i++ { 686 if f := Rect(polar[i].r, polar[i].theta); !cVeryclose(vc[i], f) { 687 t.Errorf("Rect(%g, %g) = %g want %g", polar[i].r, polar[i].theta, f, vc[i]) 688 } 689 } 690 for i := 0; i < len(vcPolarSC); i++ { 691 if f := Rect(polarSC[i].r, polarSC[i].theta); !cAlike(vcPolarSC[i], f) { 692 t.Errorf("Rect(%g, %g) = %g, want %g", polarSC[i].r, polarSC[i].theta, f, vcPolarSC[i]) 693 } 694 } 695 } 696 func TestSin(t *testing.T) { 697 for i := 0; i < len(vc); i++ { 698 if f := Sin(vc[i]); !cSoclose(sin[i], f, 2e-15) { 699 t.Errorf("Sin(%g) = %g, want %g", vc[i], f, sin[i]) 700 } 701 } 702 for i := 0; i < len(vcSinSC); i++ { 703 if f := Sin(vcSinSC[i]); !cAlike(sinSC[i], f) { 704 t.Errorf("Sin(%g) = %g, want %g", vcSinSC[i], f, sinSC[i]) 705 } 706 } 707 } 708 func TestSinh(t *testing.T) { 709 for i := 0; i < len(vc); i++ { 710 if f := Sinh(vc[i]); !cSoclose(sinh[i], f, 2e-15) { 711 t.Errorf("Sinh(%g) = %g, want %g", vc[i], f, sinh[i]) 712 } 713 } 714 for i := 0; i < len(vcSinhSC); i++ { 715 if f := Sinh(vcSinhSC[i]); !cAlike(sinhSC[i], f) { 716 t.Errorf("Sinh(%g) = %g, want %g", vcSinhSC[i], f, sinhSC[i]) 717 } 718 } 719 } 720 func TestSqrt(t *testing.T) { 721 for i := 0; i < len(vc); i++ { 722 if f := Sqrt(vc[i]); !cVeryclose(sqrt[i], f) { 723 t.Errorf("Sqrt(%g) = %g, want %g", vc[i], f, sqrt[i]) 724 } 725 } 726 for i := 0; i < len(vcSqrtSC); i++ { 727 if f := Sqrt(vcSqrtSC[i]); !cAlike(sqrtSC[i], f) { 728 t.Errorf("Sqrt(%g) = %g, want %g", vcSqrtSC[i], f, sqrtSC[i]) 729 } 730 } 731 } 732 func TestTan(t *testing.T) { 733 for i := 0; i < len(vc); i++ { 734 if f := Tan(vc[i]); !cSoclose(tan[i], f, 3e-15) { 735 t.Errorf("Tan(%g) = %g, want %g", vc[i], f, tan[i]) 736 } 737 } 738 for i := 0; i < len(vcTanSC); i++ { 739 if f := Tan(vcTanSC[i]); !cAlike(tanSC[i], f) { 740 t.Errorf("Tan(%g) = %g, want %g", vcTanSC[i], f, tanSC[i]) 741 } 742 } 743 } 744 func TestTanh(t *testing.T) { 745 for i := 0; i < len(vc); i++ { 746 if f := Tanh(vc[i]); !cSoclose(tanh[i], f, 2e-15) { 747 t.Errorf("Tanh(%g) = %g, want %g", vc[i], f, tanh[i]) 748 } 749 } 750 for i := 0; i < len(vcTanhSC); i++ { 751 if f := Tanh(vcTanhSC[i]); !cAlike(tanhSC[i], f) { 752 t.Errorf("Tanh(%g) = %g, want %g", vcTanhSC[i], f, tanhSC[i]) 753 } 754 } 755 } 756 757 func BenchmarkAbs(b *testing.B) { 758 for i := 0; i < b.N; i++ { 759 Abs(complex(2.5, 3.5)) 760 } 761 } 762 func BenchmarkAcos(b *testing.B) { 763 for i := 0; i < b.N; i++ { 764 Acos(complex(2.5, 3.5)) 765 } 766 } 767 func BenchmarkAcosh(b *testing.B) { 768 for i := 0; i < b.N; i++ { 769 Acosh(complex(2.5, 3.5)) 770 } 771 } 772 func BenchmarkAsin(b *testing.B) { 773 for i := 0; i < b.N; i++ { 774 Asin(complex(2.5, 3.5)) 775 } 776 } 777 func BenchmarkAsinh(b *testing.B) { 778 for i := 0; i < b.N; i++ { 779 Asinh(complex(2.5, 3.5)) 780 } 781 } 782 func BenchmarkAtan(b *testing.B) { 783 for i := 0; i < b.N; i++ { 784 Atan(complex(2.5, 3.5)) 785 } 786 } 787 func BenchmarkAtanh(b *testing.B) { 788 for i := 0; i < b.N; i++ { 789 Atanh(complex(2.5, 3.5)) 790 } 791 } 792 func BenchmarkConj(b *testing.B) { 793 for i := 0; i < b.N; i++ { 794 Conj(complex(2.5, 3.5)) 795 } 796 } 797 func BenchmarkCos(b *testing.B) { 798 for i := 0; i < b.N; i++ { 799 Cos(complex(2.5, 3.5)) 800 } 801 } 802 func BenchmarkCosh(b *testing.B) { 803 for i := 0; i < b.N; i++ { 804 Cosh(complex(2.5, 3.5)) 805 } 806 } 807 func BenchmarkExp(b *testing.B) { 808 for i := 0; i < b.N; i++ { 809 Exp(complex(2.5, 3.5)) 810 } 811 } 812 func BenchmarkLog(b *testing.B) { 813 for i := 0; i < b.N; i++ { 814 Log(complex(2.5, 3.5)) 815 } 816 } 817 func BenchmarkLog10(b *testing.B) { 818 for i := 0; i < b.N; i++ { 819 Log10(complex(2.5, 3.5)) 820 } 821 } 822 func BenchmarkPhase(b *testing.B) { 823 for i := 0; i < b.N; i++ { 824 Phase(complex(2.5, 3.5)) 825 } 826 } 827 func BenchmarkPolar(b *testing.B) { 828 for i := 0; i < b.N; i++ { 829 Polar(complex(2.5, 3.5)) 830 } 831 } 832 func BenchmarkPow(b *testing.B) { 833 for i := 0; i < b.N; i++ { 834 Pow(complex(2.5, 3.5), complex(2.5, 3.5)) 835 } 836 } 837 func BenchmarkRect(b *testing.B) { 838 for i := 0; i < b.N; i++ { 839 Rect(2.5, 1.5) 840 } 841 } 842 func BenchmarkSin(b *testing.B) { 843 for i := 0; i < b.N; i++ { 844 Sin(complex(2.5, 3.5)) 845 } 846 } 847 func BenchmarkSinh(b *testing.B) { 848 for i := 0; i < b.N; i++ { 849 Sinh(complex(2.5, 3.5)) 850 } 851 } 852 func BenchmarkSqrt(b *testing.B) { 853 for i := 0; i < b.N; i++ { 854 Sqrt(complex(2.5, 3.5)) 855 } 856 } 857 func BenchmarkTan(b *testing.B) { 858 for i := 0; i < b.N; i++ { 859 Tan(complex(2.5, 3.5)) 860 } 861 } 862 func BenchmarkTanh(b *testing.B) { 863 for i := 0; i < b.N; i++ { 864 Tanh(complex(2.5, 3.5)) 865 } 866 } 867