cmath_test.go 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  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. package cmplx
  5. import (
  6. "math"
  7. "testing"
  8. )
  9. // The higher-precision values in vc26 were used to derive the
  10. // input arguments vc (see also comment below). For reference
  11. // only (do not delete).
  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. // The expected results below were computed by the high precision calculators
  37. // at https://keisan.casio.com/. More exact input values (array vc[], above)
  38. // were obtained by printing them with "%.26f". The answers were calculated
  39. // to 26 digits (by using the "Digit number" drop-down control of each
  40. // calculator).
  41. var abs = []float64{
  42. 9.2022120669932650313380972e+00,
  43. 7.7438239742296106616261394e+00,
  44. 5.0182478202557746902556648e+00,
  45. 1.0861137372799545160704002e+01,
  46. 1.0070841084922199607011905e+01,
  47. 5.9922447613166942183705192e+00,
  48. 5.8978784056736762299945176e+00,
  49. 3.2822866700678709020367184e+00,
  50. 8.8756430028990417290744307e+00,
  51. 1.0011785496777731986390856e+01,
  52. }
  53. var acos = []complex128{
  54. (1.0017679804707456328694569 - 2.9138232718554953784519807i),
  55. (0.03606427612041407369636057 + 2.7358584434576260925091256i),
  56. (1.6249365462333796703711823 + 2.3159537454335901187730929i),
  57. (2.0485650849650740120660391 - 3.0795576791204117911123886i),
  58. (0.29621132089073067282488147 - 3.0007392508200622519398814i),
  59. (1.0664555914934156601503632 - 2.4872865024796011364747111i),
  60. (0.48681307452231387690013905 - 2.463655912283054555225301i),
  61. (0.6116977071277574248407752 - 1.8734458851737055262693056i),
  62. (1.3649311280370181331184214 + 2.8793528632328795424123832i),
  63. (2.6189310485682988308904501 - 2.9956543302898767795858704i),
  64. }
  65. var acosh = []complex128{
  66. (2.9138232718554953784519807 + 1.0017679804707456328694569i),
  67. (2.7358584434576260925091256 - 0.03606427612041407369636057i),
  68. (2.3159537454335901187730929 - 1.6249365462333796703711823i),
  69. (3.0795576791204117911123886 + 2.0485650849650740120660391i),
  70. (3.0007392508200622519398814 + 0.29621132089073067282488147i),
  71. (2.4872865024796011364747111 + 1.0664555914934156601503632i),
  72. (2.463655912283054555225301 + 0.48681307452231387690013905i),
  73. (1.8734458851737055262693056 + 0.6116977071277574248407752i),
  74. (2.8793528632328795424123832 - 1.3649311280370181331184214i),
  75. (2.9956543302898767795858704 + 2.6189310485682988308904501i),
  76. }
  77. var asin = []complex128{
  78. (0.56902834632415098636186476 + 2.9138232718554953784519807i),
  79. (1.5347320506744825455349611 - 2.7358584434576260925091256i),
  80. (-0.054140219438483051139860579 - 2.3159537454335901187730929i),
  81. (-0.47776875817017739283471738 + 3.0795576791204117911123886i),
  82. (1.2745850059041659464064402 + 3.0007392508200622519398814i),
  83. (0.50434073530148095908095852 + 2.4872865024796011364747111i),
  84. (1.0839832522725827423311826 + 2.463655912283054555225301i),
  85. (0.9590986196671391943905465 + 1.8734458851737055262693056i),
  86. (0.20586519875787848611290031 - 2.8793528632328795424123832i),
  87. (-1.0481347217734022116591284 + 2.9956543302898767795858704i),
  88. }
  89. var asinh = []complex128{
  90. (2.9113760469415295679342185 + 0.99639459545704326759805893i),
  91. (2.7441755423994259061579029 - 0.035468308789000500601119392i),
  92. (-2.2962136462520690506126678 - 1.5144663565690151885726707i),
  93. (-3.0771233459295725965402455 + 1.0895577967194013849422294i),
  94. (3.0048366100923647417557027 + 0.29346979169819220036454168i),
  95. (2.4800059370795363157364643 + 1.0545868606049165710424232i),
  96. (2.4718773838309585611141821 + 0.47502344364250803363708842i),
  97. (1.8910743588080159144378396 + 0.56882925572563602341139174i),
  98. (2.8735426423367341878069406 - 1.362376149648891420997548i),
  99. (-2.9981750586172477217567878 + 0.5183571985225367505624207i),
  100. }
  101. var atan = []complex128{
  102. (1.5115747079332741358607654 + 0.091324403603954494382276776i),
  103. (1.4424504323482602560806727 - 0.0045416132642803911503770933i),
  104. (-1.5593488703630532674484026 - 0.20163295409248362456446431i),
  105. (-1.5280619472445889867794105 + 0.081721556230672003746956324i),
  106. (1.4759909163240799678221039 + 0.028602969320691644358773586i),
  107. (1.4877353772046548932715555 + 0.14566877153207281663773599i),
  108. (1.4206983927779191889826 + 0.076830486127880702249439993i),
  109. (1.3162236060498933364869556 + 0.16031313000467530644933363i),
  110. (1.5473450684303703578810093 - 0.11064907507939082484935782i),
  111. (-1.4841462340185253987375812 + 0.049341850305024399493142411i),
  112. }
  113. var atanh = []complex128{
  114. (0.058375027938968509064640438 + 1.4793488495105334458167782i),
  115. (0.12977343497790381229915667 - 1.5661009410463561327262499i),
  116. (-0.010576456067347252072200088 - 1.3743698658402284549750563i),
  117. (-0.042218595678688358882784918 + 1.4891433968166405606692604i),
  118. (0.095218997991316722061828397 + 1.5416884098777110330499698i),
  119. (0.079965459366890323857556487 + 1.4252510353873192700350435i),
  120. (0.15051245471980726221708301 + 1.4907432533016303804884461i),
  121. (0.25082072933993987714470373 + 1.392057665392187516442986i),
  122. (0.022896108815797135846276662 - 1.4609224989282864208963021i),
  123. (-0.08665624101841876130537396 + 1.5207902036935093480142159i),
  124. }
  125. var conj = []complex128{
  126. (4.9790119248836735e+00 - 7.7388724745781045e+00i),
  127. (7.7388724745781045e+00 + 2.7688005719200159e-01i),
  128. (-2.7688005719200159e-01 + 5.0106036182710749e+00i),
  129. (-5.0106036182710749e+00 - 9.6362937071984173e+00i),
  130. (9.6362937071984173e+00 - 2.9263772392439646e+00i),
  131. (2.9263772392439646e+00 - 5.2290834314593066e+00i),
  132. (5.2290834314593066e+00 - 2.7279399104360102e+00i),
  133. (2.7279399104360102e+00 - 1.8253080916808550e+00i),
  134. (1.8253080916808550e+00 + 8.6859247685756013e+00i),
  135. (-8.6859247685756013e+00 - 4.9790119248836735e+00i),
  136. }
  137. var cos = []complex128{
  138. (3.024540920601483938336569e+02 + 1.1073797572517071650045357e+03i),
  139. (1.192858682649064973252758e-01 + 2.7857554122333065540970207e-01i),
  140. (7.2144394304528306603857962e+01 - 2.0500129667076044169954205e+01i),
  141. (2.24921952538403984190541e+03 - 7.317363745602773587049329e+03i),
  142. (-9.148222970032421760015498e+00 + 1.953124661113563541862227e+00i),
  143. (-9.116081175857732248227078e+01 - 1.992669213569952232487371e+01i),
  144. (3.795639179042704640002918e+00 + 6.623513350981458399309662e+00i),
  145. (-2.9144840732498869560679084e+00 - 1.214620271628002917638748e+00i),
  146. (-7.45123482501299743872481e+02 + 2.8641692314488080814066734e+03i),
  147. (-5.371977967039319076416747e+01 + 4.893348341339375830564624e+01i),
  148. }
  149. var cosh = []complex128{
  150. (8.34638383523018249366948e+00 + 7.2181057886425846415112064e+01i),
  151. (1.10421967379919366952251e+03 - 3.1379638689277575379469861e+02i),
  152. (3.051485206773701584738512e-01 - 2.6805384730105297848044485e-01i),
  153. (-7.33294728684187933370938e+01 + 1.574445942284918251038144e+01i),
  154. (-7.478643293945957535757355e+03 + 1.6348382209913353929473321e+03i),
  155. (4.622316522966235701630926e+00 - 8.088695185566375256093098e+00i),
  156. (-8.544333183278877406197712e+01 + 3.7505836120128166455231717e+01i),
  157. (-1.934457815021493925115198e+00 + 7.3725859611767228178358673e+00i),
  158. (-2.352958770061749348353548e+00 - 2.034982010440878358915409e+00i),
  159. (7.79756457532134748165069e+02 + 2.8549350716819176560377717e+03i),
  160. }
  161. var exp = []complex128{
  162. (1.669197736864670815125146e+01 + 1.4436895109507663689174096e+02i),
  163. (2.2084389286252583447276212e+03 - 6.2759289284909211238261917e+02i),
  164. (2.227538273122775173434327e-01 + 7.2468284028334191250470034e-01i),
  165. (-6.5182985958153548997881627e-03 - 1.39965837915193860879044e-03i),
  166. (-1.4957286524084015746110777e+04 + 3.269676455931135688988042e+03i),
  167. (9.218158701983105935659273e+00 - 1.6223985291084956009304582e+01i),
  168. (-1.7088175716853040841444505e+02 + 7.501382609870410713795546e+01i),
  169. (-3.852461315830959613132505e+00 + 1.4808420423156073221970892e+01i),
  170. (-4.586775503301407379786695e+00 - 4.178501081246873415144744e+00i),
  171. (4.451337963005453491095747e-05 - 1.62977574205442915935263e-04i),
  172. }
  173. var log = []complex128{
  174. (2.2194438972179194425697051e+00 + 9.9909115046919291062461269e-01i),
  175. (2.0468956191154167256337289e+00 - 3.5762575021856971295156489e-02i),
  176. (1.6130808329853860438751244e+00 - 1.6259990074019058442232221e+00i),
  177. (2.3851910394823008710032651e+00 + 2.0502936359659111755031062e+00i),
  178. (2.3096442270679923004800651e+00 + 2.9483213155446756211881774e-01i),
  179. (1.7904660933974656106951860e+00 + 1.0605860367252556281902109e+00i),
  180. (1.7745926939841751666177512e+00 + 4.8084556083358307819310911e-01i),
  181. (1.1885403350045342425648780e+00 + 5.8969634164776659423195222e-01i),
  182. (2.1833107837679082586772505e+00 - 1.3636647724582455028314573e+00i),
  183. (2.3037629487273259170991671e+00 + 2.6210913895386013290915234e+00i),
  184. }
  185. var log10 = []complex128{
  186. (9.6389223745559042474184943e-01 + 4.338997735671419492599631e-01i),
  187. (8.8895547241376579493490892e-01 - 1.5531488990643548254864806e-02i),
  188. (7.0055210462945412305244578e-01 - 7.0616239649481243222248404e-01i),
  189. (1.0358753067322445311676952e+00 + 8.9043121238134980156490909e-01i),
  190. (1.003065742975330237172029e+00 + 1.2804396782187887479857811e-01i),
  191. (7.7758954439739162532085157e-01 + 4.6060666333341810869055108e-01i),
  192. (7.7069581462315327037689152e-01 + 2.0882857371769952195512475e-01i),
  193. (5.1617650901191156135137239e-01 + 2.5610186717615977620363299e-01i),
  194. (9.4819982567026639742663212e-01 - 5.9223208584446952284914289e-01i),
  195. (1.0005115362454417135973429e+00 + 1.1383255270407412817250921e+00i),
  196. }
  197. type ff struct {
  198. r, theta float64
  199. }
  200. var polar = []ff{
  201. {9.2022120669932650313380972e+00, 9.9909115046919291062461269e-01},
  202. {7.7438239742296106616261394e+00, -3.5762575021856971295156489e-02},
  203. {5.0182478202557746902556648e+00, -1.6259990074019058442232221e+00},
  204. {1.0861137372799545160704002e+01, 2.0502936359659111755031062e+00},
  205. {1.0070841084922199607011905e+01, 2.9483213155446756211881774e-01},
  206. {5.9922447613166942183705192e+00, 1.0605860367252556281902109e+00},
  207. {5.8978784056736762299945176e+00, 4.8084556083358307819310911e-01},
  208. {3.2822866700678709020367184e+00, 5.8969634164776659423195222e-01},
  209. {8.8756430028990417290744307e+00, -1.3636647724582455028314573e+00},
  210. {1.0011785496777731986390856e+01, 2.6210913895386013290915234e+00},
  211. }
  212. var pow = []complex128{
  213. (-2.499956739197529585028819e+00 + 1.759751724335650228957144e+00i),
  214. (7.357094338218116311191939e+04 - 5.089973412479151648145882e+04i),
  215. (1.320777296067768517259592e+01 - 3.165621914333901498921986e+01i),
  216. (-3.123287828297300934072149e-07 - 1.9849567521490553032502223e-7i),
  217. (8.0622651468477229614813e+04 - 7.80028727944573092944363e+04i),
  218. (-1.0268824572103165858577141e+00 - 4.716844738244989776610672e-01i),
  219. (-4.35953819012244175753187e+01 + 2.2036445974645306917648585e+02i),
  220. (8.3556092283250594950239e-01 - 1.2261571947167240272593282e+01i),
  221. (1.582292972120769306069625e+03 + 1.273564263524278244782512e+04i),
  222. (6.592208301642122149025369e-08 + 2.584887236651661903526389e-08i),
  223. }
  224. var sin = []complex128{
  225. (-1.1073801774240233539648544e+03 + 3.024539773002502192425231e+02i),
  226. (1.0317037521400759359744682e+00 - 3.2208979799929570242818e-02i),
  227. (-2.0501952097271429804261058e+01 - 7.2137981348240798841800967e+01i),
  228. (7.3173638080346338642193078e+03 + 2.249219506193664342566248e+03i),
  229. (-1.964375633631808177565226e+00 - 9.0958264713870404464159683e+00i),
  230. (1.992783647158514838337674e+01 - 9.11555769410191350416942e+01i),
  231. (-6.680335650741921444300349e+00 + 3.763353833142432513086117e+00i),
  232. (1.2794028166657459148245993e+00 - 2.7669092099795781155109602e+00i),
  233. (2.8641693949535259594188879e+03 + 7.451234399649871202841615e+02i),
  234. (-4.893811726244659135553033e+01 - 5.371469305562194635957655e+01i),
  235. }
  236. var sinh = []complex128{
  237. (8.34559353341652565758198e+00 + 7.2187893208650790476628899e+01i),
  238. (1.1042192548260646752051112e+03 - 3.1379650595631635858792056e+02i),
  239. (-8.239469336509264113041849e-02 + 9.9273668758439489098514519e-01i),
  240. (7.332295456982297798219401e+01 - 1.574585908122833444899023e+01i),
  241. (-7.4786432301380582103534216e+03 + 1.63483823493980029604071e+03i),
  242. (4.595842179016870234028347e+00 - 8.135290105518580753211484e+00i),
  243. (-8.543842533574163435246793e+01 + 3.750798997857594068272375e+01i),
  244. (-1.918003500809465688017307e+00 + 7.4358344619793504041350251e+00i),
  245. (-2.233816733239658031433147e+00 - 2.143519070805995056229335e+00i),
  246. (-7.797564130187551181105341e+02 - 2.8549352346594918614806877e+03i),
  247. }
  248. var sqrt = []complex128{
  249. (2.6628203086086130543813948e+00 + 1.4531345674282185229796902e+00i),
  250. (2.7823278427251986247149295e+00 - 4.9756907317005224529115567e-02i),
  251. (1.5397025302089642757361015e+00 - 1.6271336573016637535695727e+00i),
  252. (1.7103411581506875260277898e+00 + 2.8170677122737589676157029e+00i),
  253. (3.1390392472953103383607947e+00 + 4.6612625849858653248980849e-01i),
  254. (2.1117080764822417640789287e+00 + 1.2381170223514273234967850e+00i),
  255. (2.3587032281672256703926939e+00 + 5.7827111903257349935720172e-01i),
  256. (1.7335262588873410476661577e+00 + 5.2647258220721269141550382e-01i),
  257. (2.3131094974708716531499282e+00 - 1.8775429304303785570775490e+00i),
  258. (8.1420535745048086240947359e-01 + 3.0575897587277248522656113e+00i),
  259. }
  260. var tan = []complex128{
  261. (-1.928757919086441129134525e-07 + 1.0000003267499169073251826e+00i),
  262. (1.242412685364183792138948e+00 - 3.17149693883133370106696e+00i),
  263. (-4.6745126251587795225571826e-05 - 9.9992439225263959286114298e-01i),
  264. (4.792363401193648192887116e-09 + 1.0000000070589333451557723e+00i),
  265. (2.345740824080089140287315e-03 + 9.947733046570988661022763e-01i),
  266. (-2.396030789494815566088809e-05 + 9.9994781345418591429826779e-01i),
  267. (-7.370204836644931340905303e-03 + 1.0043553413417138987717748e+00i),
  268. (-3.691803847992048527007457e-02 + 9.6475071993469548066328894e-01i),
  269. (-2.781955256713729368401878e-08 - 1.000000049848910609006646e+00i),
  270. (9.4281590064030478879791249e-05 + 9.9999119340863718183758545e-01i),
  271. }
  272. var tanh = []complex128{
  273. (1.0000921981225144748819918e+00 + 2.160986245871518020231507e-05i),
  274. (9.9999967727531993209562591e-01 - 1.9953763222959658873657676e-07i),
  275. (-1.765485739548037260789686e+00 + 1.7024216325552852445168471e+00i),
  276. (-9.999189442732736452807108e-01 + 3.64906070494473701938098e-05i),
  277. (9.9999999224622333738729767e-01 - 3.560088949517914774813046e-09i),
  278. (1.0029324933367326862499343e+00 - 4.948790309797102353137528e-03i),
  279. (9.9996113064788012488693567e-01 - 4.226995742097032481451259e-05i),
  280. (1.0074784189316340029873945e+00 - 4.194050814891697808029407e-03i),
  281. (9.9385534229718327109131502e-01 + 5.144217985914355502713437e-02i),
  282. (-1.0000000491604982429364892e+00 - 2.901873195374433112227349e-08i),
  283. }
  284. // huge values along the real axis for testing reducePi in Tan
  285. var hugeIn = []complex128{
  286. 1 << 28,
  287. 1 << 29,
  288. 1 << 30,
  289. 1 << 35,
  290. -1 << 120,
  291. 1 << 240,
  292. 1 << 300,
  293. -1 << 480,
  294. 1234567891234567 << 180,
  295. -1234567891234567 << 300,
  296. }
  297. // Results for tanHuge[i] calculated with https://github.com/robpike/ivy
  298. // using 4096 bits of working precision.
  299. var tanHuge = []complex128{
  300. 5.95641897939639421,
  301. -0.34551069233430392,
  302. -0.78469661331920043,
  303. 0.84276385870875983,
  304. 0.40806638884180424,
  305. -0.37603456702698076,
  306. 4.60901287677810962,
  307. 3.39135965054779932,
  308. -6.76813854009065030,
  309. -0.76417695016604922,
  310. }
  311. // special cases conform to C99 standard appendix G.6 Complex arithmetic
  312. var inf, nan = math.Inf(1), math.NaN()
  313. var vcAbsSC = []complex128{
  314. NaN(),
  315. }
  316. var absSC = []float64{
  317. math.NaN(),
  318. }
  319. var acosSC = []struct {
  320. in,
  321. want complex128
  322. }{
  323. // G.6.1.1
  324. {complex(zero, zero),
  325. complex(math.Pi/2, -zero)},
  326. {complex(-zero, zero),
  327. complex(math.Pi/2, -zero)},
  328. {complex(zero, nan),
  329. complex(math.Pi/2, nan)},
  330. {complex(-zero, nan),
  331. complex(math.Pi/2, nan)},
  332. {complex(1.0, inf),
  333. complex(math.Pi/2, -inf)},
  334. {complex(1.0, nan),
  335. NaN()},
  336. {complex(-inf, 1.0),
  337. complex(math.Pi, -inf)},
  338. {complex(inf, 1.0),
  339. complex(0.0, -inf)},
  340. {complex(-inf, inf),
  341. complex(3*math.Pi/4, -inf)},
  342. {complex(inf, inf),
  343. complex(math.Pi/4, -inf)},
  344. {complex(inf, nan),
  345. complex(nan, -inf)}, // imaginary sign unspecified
  346. {complex(-inf, nan),
  347. complex(nan, inf)}, // imaginary sign unspecified
  348. {complex(nan, 1.0),
  349. NaN()},
  350. {complex(nan, inf),
  351. complex(nan, -inf)},
  352. {NaN(),
  353. NaN()},
  354. }
  355. var acoshSC = []struct {
  356. in,
  357. want complex128
  358. }{
  359. // G.6.2.1
  360. {complex(zero, zero),
  361. complex(zero, math.Pi/2)},
  362. {complex(-zero, zero),
  363. complex(zero, math.Pi/2)},
  364. {complex(1.0, inf),
  365. complex(inf, math.Pi/2)},
  366. {complex(1.0, nan),
  367. NaN()},
  368. {complex(-inf, 1.0),
  369. complex(inf, math.Pi)},
  370. {complex(inf, 1.0),
  371. complex(inf, zero)},
  372. {complex(-inf, inf),
  373. complex(inf, 3*math.Pi/4)},
  374. {complex(inf, inf),
  375. complex(inf, math.Pi/4)},
  376. {complex(inf, nan),
  377. complex(inf, nan)},
  378. {complex(-inf, nan),
  379. complex(inf, nan)},
  380. {complex(nan, 1.0),
  381. NaN()},
  382. {complex(nan, inf),
  383. complex(inf, nan)},
  384. {NaN(),
  385. NaN()},
  386. }
  387. var asinSC = []struct {
  388. in,
  389. want complex128
  390. }{
  391. // Derived from Asin(z) = -i * Asinh(i * z), G.6 #7
  392. {complex(zero, zero),
  393. complex(zero, zero)},
  394. {complex(1.0, inf),
  395. complex(0, inf)},
  396. {complex(1.0, nan),
  397. NaN()},
  398. {complex(inf, 1),
  399. complex(math.Pi/2, inf)},
  400. {complex(inf, inf),
  401. complex(math.Pi/4, inf)},
  402. {complex(inf, nan),
  403. complex(nan, inf)}, // imaginary sign unspecified
  404. {complex(nan, zero),
  405. NaN()},
  406. {complex(nan, 1),
  407. NaN()},
  408. {complex(nan, inf),
  409. complex(nan, inf)},
  410. {NaN(),
  411. NaN()},
  412. }
  413. var asinhSC = []struct {
  414. in,
  415. want complex128
  416. }{
  417. // G.6.2.2
  418. {complex(zero, zero),
  419. complex(zero, zero)},
  420. {complex(1.0, inf),
  421. complex(inf, math.Pi/2)},
  422. {complex(1.0, nan),
  423. NaN()},
  424. {complex(inf, 1.0),
  425. complex(inf, zero)},
  426. {complex(inf, inf),
  427. complex(inf, math.Pi/4)},
  428. {complex(inf, nan),
  429. complex(inf, nan)},
  430. {complex(nan, zero),
  431. complex(nan, zero)},
  432. {complex(nan, 1.0),
  433. NaN()},
  434. {complex(nan, inf),
  435. complex(inf, nan)}, // sign of real part unspecified
  436. {NaN(),
  437. NaN()},
  438. }
  439. var atanSC = []struct {
  440. in,
  441. want complex128
  442. }{
  443. // Derived from Atan(z) = -i * Atanh(i * z), G.6 #7
  444. {complex(0, zero),
  445. complex(0, zero)},
  446. {complex(0, nan),
  447. NaN()},
  448. {complex(1.0, zero),
  449. complex(math.Pi/4, zero)},
  450. {complex(1.0, inf),
  451. complex(math.Pi/2, zero)},
  452. {complex(1.0, nan),
  453. NaN()},
  454. {complex(inf, 1),
  455. complex(math.Pi/2, zero)},
  456. {complex(inf, inf),
  457. complex(math.Pi/2, zero)},
  458. {complex(inf, nan),
  459. complex(math.Pi/2, zero)},
  460. {complex(nan, 1),
  461. NaN()},
  462. {complex(nan, inf),
  463. complex(nan, zero)},
  464. {NaN(),
  465. NaN()},
  466. }
  467. var atanhSC = []struct {
  468. in,
  469. want complex128
  470. }{
  471. // G.6.2.3
  472. {complex(zero, zero),
  473. complex(zero, zero)},
  474. {complex(zero, nan),
  475. complex(zero, nan)},
  476. {complex(1.0, zero),
  477. complex(inf, zero)},
  478. {complex(1.0, inf),
  479. complex(0, math.Pi/2)},
  480. {complex(1.0, nan),
  481. NaN()},
  482. {complex(inf, 1.0),
  483. complex(zero, math.Pi/2)},
  484. {complex(inf, inf),
  485. complex(zero, math.Pi/2)},
  486. {complex(inf, nan),
  487. complex(0, nan)},
  488. {complex(nan, 1.0),
  489. NaN()},
  490. {complex(nan, inf),
  491. complex(zero, math.Pi/2)}, // sign of real part not specified.
  492. {NaN(),
  493. NaN()},
  494. }
  495. var vcConjSC = []complex128{
  496. NaN(),
  497. }
  498. var conjSC = []complex128{
  499. NaN(),
  500. }
  501. var cosSC = []struct {
  502. in,
  503. want complex128
  504. }{
  505. // Derived from Cos(z) = Cosh(i * z), G.6 #7
  506. {complex(zero, zero),
  507. complex(1.0, -zero)},
  508. {complex(zero, inf),
  509. complex(inf, -zero)},
  510. {complex(zero, nan),
  511. complex(nan, zero)}, // imaginary sign unspecified
  512. {complex(1.0, inf),
  513. complex(inf, -inf)},
  514. {complex(1.0, nan),
  515. NaN()},
  516. {complex(inf, zero),
  517. complex(nan, -zero)},
  518. {complex(inf, 1.0),
  519. NaN()},
  520. {complex(inf, inf),
  521. complex(inf, nan)}, // real sign unspecified
  522. {complex(inf, nan),
  523. NaN()},
  524. {complex(nan, zero),
  525. complex(nan, -zero)}, // imaginary sign unspecified
  526. {complex(nan, 1.0),
  527. NaN()},
  528. {complex(nan, inf),
  529. complex(inf, nan)},
  530. {NaN(),
  531. NaN()},
  532. }
  533. var coshSC = []struct {
  534. in,
  535. want complex128
  536. }{
  537. // G.6.2.4
  538. {complex(zero, zero),
  539. complex(1.0, zero)},
  540. {complex(zero, inf),
  541. complex(nan, zero)}, // imaginary sign unspecified
  542. {complex(zero, nan),
  543. complex(nan, zero)}, // imaginary sign unspecified
  544. {complex(1.0, inf),
  545. NaN()},
  546. {complex(1.0, nan),
  547. NaN()},
  548. {complex(inf, zero),
  549. complex(inf, zero)},
  550. {complex(inf, 1.0),
  551. complex(inf*math.Cos(1.0), inf*math.Sin(1.0))}, // +inf cis(y)
  552. {complex(inf, inf),
  553. complex(inf, nan)}, // real sign unspecified
  554. {complex(inf, nan),
  555. complex(inf, nan)},
  556. {complex(nan, zero),
  557. complex(nan, zero)}, // imaginary sign unspecified
  558. {complex(nan, 1.0),
  559. NaN()},
  560. {complex(nan, inf),
  561. NaN()},
  562. {NaN(),
  563. NaN()},
  564. }
  565. var expSC = []struct {
  566. in,
  567. want complex128
  568. }{
  569. // G.6.3.1
  570. {complex(zero, zero),
  571. complex(1.0, zero)},
  572. {complex(-zero, zero),
  573. complex(1.0, zero)},
  574. {complex(1.0, inf),
  575. NaN()},
  576. {complex(1.0, nan),
  577. NaN()},
  578. {complex(inf, zero),
  579. complex(inf, zero)},
  580. {complex(-inf, 1.0),
  581. complex(math.Copysign(0.0, math.Cos(1.0)), math.Copysign(0.0, math.Sin(1.0)))}, // +0 cis(y)
  582. {complex(inf, 1.0),
  583. complex(inf*math.Cos(1.0), inf*math.Sin(1.0))}, // +inf cis(y)
  584. {complex(-inf, inf),
  585. complex(zero, zero)}, // real and imaginary sign unspecified
  586. {complex(inf, inf),
  587. complex(inf, nan)}, // real sign unspecified
  588. {complex(-inf, nan),
  589. complex(zero, zero)}, // real and imaginary sign unspecified
  590. {complex(inf, nan),
  591. complex(inf, nan)}, // real sign unspecified
  592. {complex(nan, zero),
  593. complex(nan, zero)},
  594. {complex(nan, 1.0),
  595. NaN()},
  596. {complex(nan, inf),
  597. NaN()},
  598. {NaN(),
  599. NaN()},
  600. }
  601. var vcIsNaNSC = []complex128{
  602. complex(math.Inf(-1), math.Inf(-1)),
  603. complex(math.Inf(-1), math.NaN()),
  604. complex(math.NaN(), math.Inf(-1)),
  605. complex(0, math.NaN()),
  606. complex(math.NaN(), 0),
  607. complex(math.Inf(1), math.Inf(1)),
  608. complex(math.Inf(1), math.NaN()),
  609. complex(math.NaN(), math.Inf(1)),
  610. complex(math.NaN(), math.NaN()),
  611. }
  612. var isNaNSC = []bool{
  613. false,
  614. false,
  615. false,
  616. true,
  617. true,
  618. false,
  619. false,
  620. false,
  621. true,
  622. }
  623. var logSC = []struct {
  624. in,
  625. want complex128
  626. }{
  627. // G.6.3.2
  628. {complex(zero, zero),
  629. complex(-inf, zero)},
  630. {complex(-zero, zero),
  631. complex(-inf, math.Pi)},
  632. {complex(1.0, inf),
  633. complex(inf, math.Pi/2)},
  634. {complex(1.0, nan),
  635. NaN()},
  636. {complex(-inf, 1.0),
  637. complex(inf, math.Pi)},
  638. {complex(inf, 1.0),
  639. complex(inf, 0.0)},
  640. {complex(-inf, inf),
  641. complex(inf, 3*math.Pi/4)},
  642. {complex(inf, inf),
  643. complex(inf, math.Pi/4)},
  644. {complex(-inf, nan),
  645. complex(inf, nan)},
  646. {complex(inf, nan),
  647. complex(inf, nan)},
  648. {complex(nan, 1.0),
  649. NaN()},
  650. {complex(nan, inf),
  651. complex(inf, nan)},
  652. {NaN(),
  653. NaN()},
  654. }
  655. var log10SC = []struct {
  656. in,
  657. want complex128
  658. }{
  659. // derived from Log special cases via Log10(x) = math.Log10E*Log(x)
  660. {complex(zero, zero),
  661. complex(-inf, zero)},
  662. {complex(-zero, zero),
  663. complex(-inf, float64(math.Log10E)*float64(math.Pi))},
  664. {complex(1.0, inf),
  665. complex(inf, float64(math.Log10E)*float64(math.Pi/2))},
  666. {complex(1.0, nan),
  667. NaN()},
  668. {complex(-inf, 1.0),
  669. complex(inf, float64(math.Log10E)*float64(math.Pi))},
  670. {complex(inf, 1.0),
  671. complex(inf, 0.0)},
  672. {complex(-inf, inf),
  673. complex(inf, float64(math.Log10E)*float64(3*math.Pi/4))},
  674. {complex(inf, inf),
  675. complex(inf, float64(math.Log10E)*float64(math.Pi/4))},
  676. {complex(-inf, nan),
  677. complex(inf, nan)},
  678. {complex(inf, nan),
  679. complex(inf, nan)},
  680. {complex(nan, 1.0),
  681. NaN()},
  682. {complex(nan, inf),
  683. complex(inf, nan)},
  684. {NaN(),
  685. NaN()},
  686. }
  687. var vcPolarSC = []complex128{
  688. NaN(),
  689. }
  690. var polarSC = []ff{
  691. {math.NaN(), math.NaN()},
  692. }
  693. var vcPowSC = [][2]complex128{
  694. {NaN(), NaN()},
  695. {0, NaN()},
  696. }
  697. var powSC = []complex128{
  698. NaN(),
  699. NaN(),
  700. }
  701. var sinSC = []struct {
  702. in,
  703. want complex128
  704. }{
  705. // Derived from Sin(z) = -i * Sinh(i * z), G.6 #7
  706. {complex(zero, zero),
  707. complex(zero, zero)},
  708. {complex(zero, inf),
  709. complex(zero, inf)},
  710. {complex(zero, nan),
  711. complex(zero, nan)},
  712. {complex(1.0, inf),
  713. complex(inf, inf)},
  714. {complex(1.0, nan),
  715. NaN()},
  716. {complex(inf, zero),
  717. complex(nan, zero)},
  718. {complex(inf, 1.0),
  719. NaN()},
  720. {complex(inf, inf),
  721. complex(nan, inf)},
  722. {complex(inf, nan),
  723. NaN()},
  724. {complex(nan, zero),
  725. complex(nan, zero)},
  726. {complex(nan, 1.0),
  727. NaN()},
  728. {complex(nan, inf),
  729. complex(nan, inf)},
  730. {NaN(),
  731. NaN()},
  732. }
  733. var sinhSC = []struct {
  734. in,
  735. want complex128
  736. }{
  737. // G.6.2.5
  738. {complex(zero, zero),
  739. complex(zero, zero)},
  740. {complex(zero, inf),
  741. complex(zero, nan)}, // real sign unspecified
  742. {complex(zero, nan),
  743. complex(zero, nan)}, // real sign unspecified
  744. {complex(1.0, inf),
  745. NaN()},
  746. {complex(1.0, nan),
  747. NaN()},
  748. {complex(inf, zero),
  749. complex(inf, zero)},
  750. {complex(inf, 1.0),
  751. complex(inf*math.Cos(1.0), inf*math.Sin(1.0))}, // +inf cis(y)
  752. {complex(inf, inf),
  753. complex(inf, nan)}, // real sign unspecified
  754. {complex(inf, nan),
  755. complex(inf, nan)}, // real sign unspecified
  756. {complex(nan, zero),
  757. complex(nan, zero)},
  758. {complex(nan, 1.0),
  759. NaN()},
  760. {complex(nan, inf),
  761. NaN()},
  762. {NaN(),
  763. NaN()},
  764. }
  765. var sqrtSC = []struct {
  766. in,
  767. want complex128
  768. }{
  769. // G.6.4.2
  770. {complex(zero, zero),
  771. complex(zero, zero)},
  772. {complex(-zero, zero),
  773. complex(zero, zero)},
  774. {complex(1.0, inf),
  775. complex(inf, inf)},
  776. {complex(nan, inf),
  777. complex(inf, inf)},
  778. {complex(1.0, nan),
  779. NaN()},
  780. {complex(-inf, 1.0),
  781. complex(zero, inf)},
  782. {complex(inf, 1.0),
  783. complex(inf, zero)},
  784. {complex(-inf, nan),
  785. complex(nan, inf)}, // imaginary sign unspecified
  786. {complex(inf, nan),
  787. complex(inf, nan)},
  788. {complex(nan, 1.0),
  789. NaN()},
  790. {NaN(),
  791. NaN()},
  792. }
  793. var tanSC = []struct {
  794. in,
  795. want complex128
  796. }{
  797. // Derived from Tan(z) = -i * Tanh(i * z), G.6 #7
  798. {complex(zero, zero),
  799. complex(zero, zero)},
  800. {complex(zero, nan),
  801. complex(zero, nan)},
  802. {complex(1.0, inf),
  803. complex(zero, 1.0)},
  804. {complex(1.0, nan),
  805. NaN()},
  806. {complex(inf, 1.0),
  807. NaN()},
  808. {complex(inf, inf),
  809. complex(zero, 1.0)},
  810. {complex(inf, nan),
  811. NaN()},
  812. {complex(nan, zero),
  813. NaN()},
  814. {complex(nan, 1.0),
  815. NaN()},
  816. {complex(nan, inf),
  817. complex(zero, 1.0)},
  818. {NaN(),
  819. NaN()},
  820. }
  821. var tanhSC = []struct {
  822. in,
  823. want complex128
  824. }{
  825. // G.6.2.6
  826. {complex(zero, zero),
  827. complex(zero, zero)},
  828. {complex(1.0, inf),
  829. NaN()},
  830. {complex(1.0, nan),
  831. NaN()},
  832. {complex(inf, 1.0),
  833. complex(1.0, math.Copysign(0.0, math.Sin(2*1.0)))}, // 1 + i 0 sin(2y)
  834. {complex(inf, inf),
  835. complex(1.0, zero)}, // imaginary sign unspecified
  836. {complex(inf, nan),
  837. complex(1.0, zero)}, // imaginary sign unspecified
  838. {complex(nan, zero),
  839. complex(nan, zero)},
  840. {complex(nan, 1.0),
  841. NaN()},
  842. {complex(nan, inf),
  843. NaN()},
  844. {NaN(),
  845. NaN()},
  846. }
  847. // branch cut continuity checks
  848. // points on each axis at |z| > 1 are checked for one-sided continuity from both the positive and negative side
  849. // all possible branch cuts for the elementary functions are at one of these points
  850. var zero = 0.0
  851. var eps = 1.0 / (1 << 53)
  852. var branchPoints = [][2]complex128{
  853. {complex(2.0, zero), complex(2.0, eps)},
  854. {complex(2.0, -zero), complex(2.0, -eps)},
  855. {complex(-2.0, zero), complex(-2.0, eps)},
  856. {complex(-2.0, -zero), complex(-2.0, -eps)},
  857. {complex(zero, 2.0), complex(eps, 2.0)},
  858. {complex(-zero, 2.0), complex(-eps, 2.0)},
  859. {complex(zero, -2.0), complex(eps, -2.0)},
  860. {complex(-zero, -2.0), complex(-eps, -2.0)},
  861. }
  862. // functions borrowed from pkg/math/all_test.go
  863. func tolerance(a, b, e float64) bool {
  864. d := a - b
  865. if d < 0 {
  866. d = -d
  867. }
  868. // note: b is correct (expected) value, a is actual value.
  869. // make error tolerance a fraction of b, not a.
  870. if b != 0 {
  871. e = e * b
  872. if e < 0 {
  873. e = -e
  874. }
  875. }
  876. return d < e
  877. }
  878. func veryclose(a, b float64) bool { return tolerance(a, b, 4e-16) }
  879. func alike(a, b float64) bool {
  880. switch {
  881. case a != a && b != b: // math.IsNaN(a) && math.IsNaN(b):
  882. return true
  883. case a == b:
  884. return math.Signbit(a) == math.Signbit(b)
  885. }
  886. return false
  887. }
  888. func cTolerance(a, b complex128, e float64) bool {
  889. d := Abs(a - b)
  890. if b != 0 {
  891. e = e * Abs(b)
  892. if e < 0 {
  893. e = -e
  894. }
  895. }
  896. return d < e
  897. }
  898. func cSoclose(a, b complex128, e float64) bool { return cTolerance(a, b, e) }
  899. func cVeryclose(a, b complex128) bool { return cTolerance(a, b, 4e-16) }
  900. func cAlike(a, b complex128) bool {
  901. var realAlike, imagAlike bool
  902. if isExact(real(b)) {
  903. realAlike = alike(real(a), real(b))
  904. } else {
  905. // Allow non-exact special cases to have errors in ULP.
  906. realAlike = veryclose(real(a), real(b))
  907. }
  908. if isExact(imag(b)) {
  909. imagAlike = alike(imag(a), imag(b))
  910. } else {
  911. // Allow non-exact special cases to have errors in ULP.
  912. imagAlike = veryclose(imag(a), imag(b))
  913. }
  914. return realAlike && imagAlike
  915. }
  916. func isExact(x float64) bool {
  917. // Special cases that should match exactly. Other cases are multiples
  918. // of Pi that may not be last bit identical on all platforms.
  919. return math.IsNaN(x) || math.IsInf(x, 0) || x == 0 || x == 1 || x == -1
  920. }
  921. func TestAbs(t *testing.T) {
  922. for i := 0; i < len(vc); i++ {
  923. if f := Abs(vc[i]); !veryclose(abs[i], f) {
  924. t.Errorf("Abs(%g) = %g, want %g", vc[i], f, abs[i])
  925. }
  926. }
  927. for i := 0; i < len(vcAbsSC); i++ {
  928. if f := Abs(vcAbsSC[i]); !alike(absSC[i], f) {
  929. t.Errorf("Abs(%g) = %g, want %g", vcAbsSC[i], f, absSC[i])
  930. }
  931. }
  932. }
  933. func TestAcos(t *testing.T) {
  934. for i := 0; i < len(vc); i++ {
  935. if f := Acos(vc[i]); !cSoclose(acos[i], f, 1e-14) {
  936. t.Errorf("Acos(%g) = %g, want %g", vc[i], f, acos[i])
  937. }
  938. }
  939. for _, v := range acosSC {
  940. if f := Acos(v.in); !cAlike(v.want, f) {
  941. t.Errorf("Acos(%g) = %g, want %g", v.in, f, v.want)
  942. }
  943. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  944. // Negating NaN is undefined with regard to the sign bit produced.
  945. continue
  946. }
  947. // Acos(Conj(z)) == Conj(Acos(z))
  948. if f := Acos(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  949. t.Errorf("Acos(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  950. }
  951. }
  952. for _, pt := range branchPoints {
  953. if f0, f1 := Acos(pt[0]), Acos(pt[1]); !cVeryclose(f0, f1) {
  954. t.Errorf("Acos(%g) not continuous, got %g want %g", pt[0], f0, f1)
  955. }
  956. }
  957. }
  958. func TestAcosh(t *testing.T) {
  959. for i := 0; i < len(vc); i++ {
  960. if f := Acosh(vc[i]); !cSoclose(acosh[i], f, 1e-14) {
  961. t.Errorf("Acosh(%g) = %g, want %g", vc[i], f, acosh[i])
  962. }
  963. }
  964. for _, v := range acoshSC {
  965. if f := Acosh(v.in); !cAlike(v.want, f) {
  966. t.Errorf("Acosh(%g) = %g, want %g", v.in, f, v.want)
  967. }
  968. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  969. // Negating NaN is undefined with regard to the sign bit produced.
  970. continue
  971. }
  972. // Acosh(Conj(z)) == Conj(Acosh(z))
  973. if f := Acosh(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  974. t.Errorf("Acosh(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  975. }
  976. }
  977. for _, pt := range branchPoints {
  978. if f0, f1 := Acosh(pt[0]), Acosh(pt[1]); !cVeryclose(f0, f1) {
  979. t.Errorf("Acosh(%g) not continuous, got %g want %g", pt[0], f0, f1)
  980. }
  981. }
  982. }
  983. func TestAsin(t *testing.T) {
  984. for i := 0; i < len(vc); i++ {
  985. if f := Asin(vc[i]); !cSoclose(asin[i], f, 1e-14) {
  986. t.Errorf("Asin(%g) = %g, want %g", vc[i], f, asin[i])
  987. }
  988. }
  989. for _, v := range asinSC {
  990. if f := Asin(v.in); !cAlike(v.want, f) {
  991. t.Errorf("Asin(%g) = %g, want %g", v.in, f, v.want)
  992. }
  993. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  994. // Negating NaN is undefined with regard to the sign bit produced.
  995. continue
  996. }
  997. // Asin(Conj(z)) == Asin(Sinh(z))
  998. if f := Asin(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  999. t.Errorf("Asin(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1000. }
  1001. if math.IsNaN(real(v.in)) || math.IsNaN(real(v.want)) {
  1002. // Negating NaN is undefined with regard to the sign bit produced.
  1003. continue
  1004. }
  1005. // Asin(-z) == -Asin(z)
  1006. if f := Asin(-v.in); !cAlike(-v.want, f) && !cAlike(v.in, -v.in) {
  1007. t.Errorf("Asin(%g) = %g, want %g", -v.in, f, -v.want)
  1008. }
  1009. }
  1010. for _, pt := range branchPoints {
  1011. if f0, f1 := Asin(pt[0]), Asin(pt[1]); !cVeryclose(f0, f1) {
  1012. t.Errorf("Asin(%g) not continuous, got %g want %g", pt[0], f0, f1)
  1013. }
  1014. }
  1015. }
  1016. func TestAsinh(t *testing.T) {
  1017. for i := 0; i < len(vc); i++ {
  1018. if f := Asinh(vc[i]); !cSoclose(asinh[i], f, 4e-15) {
  1019. t.Errorf("Asinh(%g) = %g, want %g", vc[i], f, asinh[i])
  1020. }
  1021. }
  1022. for _, v := range asinhSC {
  1023. if f := Asinh(v.in); !cAlike(v.want, f) {
  1024. t.Errorf("Asinh(%g) = %g, want %g", v.in, f, v.want)
  1025. }
  1026. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1027. // Negating NaN is undefined with regard to the sign bit produced.
  1028. continue
  1029. }
  1030. // Asinh(Conj(z)) == Asinh(Sinh(z))
  1031. if f := Asinh(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1032. t.Errorf("Asinh(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1033. }
  1034. if math.IsNaN(real(v.in)) || math.IsNaN(real(v.want)) {
  1035. // Negating NaN is undefined with regard to the sign bit produced.
  1036. continue
  1037. }
  1038. // Asinh(-z) == -Asinh(z)
  1039. if f := Asinh(-v.in); !cAlike(-v.want, f) && !cAlike(v.in, -v.in) {
  1040. t.Errorf("Asinh(%g) = %g, want %g", -v.in, f, -v.want)
  1041. }
  1042. }
  1043. for _, pt := range branchPoints {
  1044. if f0, f1 := Asinh(pt[0]), Asinh(pt[1]); !cVeryclose(f0, f1) {
  1045. t.Errorf("Asinh(%g) not continuous, got %g want %g", pt[0], f0, f1)
  1046. }
  1047. }
  1048. }
  1049. func TestAtan(t *testing.T) {
  1050. for i := 0; i < len(vc); i++ {
  1051. if f := Atan(vc[i]); !cVeryclose(atan[i], f) {
  1052. t.Errorf("Atan(%g) = %g, want %g", vc[i], f, atan[i])
  1053. }
  1054. }
  1055. for _, v := range atanSC {
  1056. if f := Atan(v.in); !cAlike(v.want, f) {
  1057. t.Errorf("Atan(%g) = %g, want %g", v.in, f, v.want)
  1058. }
  1059. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1060. // Negating NaN is undefined with regard to the sign bit produced.
  1061. continue
  1062. }
  1063. // Atan(Conj(z)) == Conj(Atan(z))
  1064. if f := Atan(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1065. t.Errorf("Atan(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1066. }
  1067. if math.IsNaN(real(v.in)) || math.IsNaN(real(v.want)) {
  1068. // Negating NaN is undefined with regard to the sign bit produced.
  1069. continue
  1070. }
  1071. // Atan(-z) == -Atan(z)
  1072. if f := Atan(-v.in); !cAlike(-v.want, f) && !cAlike(v.in, -v.in) {
  1073. t.Errorf("Atan(%g) = %g, want %g", -v.in, f, -v.want)
  1074. }
  1075. }
  1076. for _, pt := range branchPoints {
  1077. if f0, f1 := Atan(pt[0]), Atan(pt[1]); !cVeryclose(f0, f1) {
  1078. t.Errorf("Atan(%g) not continuous, got %g want %g", pt[0], f0, f1)
  1079. }
  1080. }
  1081. }
  1082. func TestAtanh(t *testing.T) {
  1083. for i := 0; i < len(vc); i++ {
  1084. if f := Atanh(vc[i]); !cVeryclose(atanh[i], f) {
  1085. t.Errorf("Atanh(%g) = %g, want %g", vc[i], f, atanh[i])
  1086. }
  1087. }
  1088. for _, v := range atanhSC {
  1089. if f := Atanh(v.in); !cAlike(v.want, f) {
  1090. t.Errorf("Atanh(%g) = %g, want %g", v.in, f, v.want)
  1091. }
  1092. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1093. // Negating NaN is undefined with regard to the sign bit produced.
  1094. continue
  1095. }
  1096. // Atanh(Conj(z)) == Conj(Atanh(z))
  1097. if f := Atanh(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1098. t.Errorf("Atanh(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1099. }
  1100. if math.IsNaN(real(v.in)) || math.IsNaN(real(v.want)) {
  1101. // Negating NaN is undefined with regard to the sign bit produced.
  1102. continue
  1103. }
  1104. // Atanh(-z) == -Atanh(z)
  1105. if f := Atanh(-v.in); !cAlike(-v.want, f) && !cAlike(v.in, -v.in) {
  1106. t.Errorf("Atanh(%g) = %g, want %g", -v.in, f, -v.want)
  1107. }
  1108. }
  1109. for _, pt := range branchPoints {
  1110. if f0, f1 := Atanh(pt[0]), Atanh(pt[1]); !cVeryclose(f0, f1) {
  1111. t.Errorf("Atanh(%g) not continuous, got %g want %g", pt[0], f0, f1)
  1112. }
  1113. }
  1114. }
  1115. func TestConj(t *testing.T) {
  1116. for i := 0; i < len(vc); i++ {
  1117. if f := Conj(vc[i]); !cVeryclose(conj[i], f) {
  1118. t.Errorf("Conj(%g) = %g, want %g", vc[i], f, conj[i])
  1119. }
  1120. }
  1121. for i := 0; i < len(vcConjSC); i++ {
  1122. if f := Conj(vcConjSC[i]); !cAlike(conjSC[i], f) {
  1123. t.Errorf("Conj(%g) = %g, want %g", vcConjSC[i], f, conjSC[i])
  1124. }
  1125. }
  1126. }
  1127. func TestCos(t *testing.T) {
  1128. for i := 0; i < len(vc); i++ {
  1129. if f := Cos(vc[i]); !cSoclose(cos[i], f, 3e-15) {
  1130. t.Errorf("Cos(%g) = %g, want %g", vc[i], f, cos[i])
  1131. }
  1132. }
  1133. for _, v := range cosSC {
  1134. if f := Cos(v.in); !cAlike(v.want, f) {
  1135. t.Errorf("Cos(%g) = %g, want %g", v.in, f, v.want)
  1136. }
  1137. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1138. // Negating NaN is undefined with regard to the sign bit produced.
  1139. continue
  1140. }
  1141. // Cos(Conj(z)) == Cos(Cosh(z))
  1142. if f := Cos(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1143. t.Errorf("Cos(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1144. }
  1145. if math.IsNaN(real(v.in)) || math.IsNaN(real(v.want)) {
  1146. // Negating NaN is undefined with regard to the sign bit produced.
  1147. continue
  1148. }
  1149. // Cos(-z) == Cos(z)
  1150. if f := Cos(-v.in); !cAlike(v.want, f) && !cAlike(v.in, -v.in) {
  1151. t.Errorf("Cos(%g) = %g, want %g", -v.in, f, v.want)
  1152. }
  1153. }
  1154. }
  1155. func TestCosh(t *testing.T) {
  1156. for i := 0; i < len(vc); i++ {
  1157. if f := Cosh(vc[i]); !cSoclose(cosh[i], f, 2e-15) {
  1158. t.Errorf("Cosh(%g) = %g, want %g", vc[i], f, cosh[i])
  1159. }
  1160. }
  1161. for _, v := range coshSC {
  1162. if f := Cosh(v.in); !cAlike(v.want, f) {
  1163. t.Errorf("Cosh(%g) = %g, want %g", v.in, f, v.want)
  1164. }
  1165. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1166. // Negating NaN is undefined with regard to the sign bit produced.
  1167. continue
  1168. }
  1169. // Cosh(Conj(z)) == Conj(Cosh(z))
  1170. if f := Cosh(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1171. t.Errorf("Cosh(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1172. }
  1173. if math.IsNaN(real(v.in)) || math.IsNaN(real(v.want)) {
  1174. // Negating NaN is undefined with regard to the sign bit produced.
  1175. continue
  1176. }
  1177. // Cosh(-z) == Cosh(z)
  1178. if f := Cosh(-v.in); !cAlike(v.want, f) && !cAlike(v.in, -v.in) {
  1179. t.Errorf("Cosh(%g) = %g, want %g", -v.in, f, v.want)
  1180. }
  1181. }
  1182. }
  1183. func TestExp(t *testing.T) {
  1184. for i := 0; i < len(vc); i++ {
  1185. if f := Exp(vc[i]); !cSoclose(exp[i], f, 1e-15) {
  1186. t.Errorf("Exp(%g) = %g, want %g", vc[i], f, exp[i])
  1187. }
  1188. }
  1189. for _, v := range expSC {
  1190. if f := Exp(v.in); !cAlike(v.want, f) {
  1191. t.Errorf("Exp(%g) = %g, want %g", v.in, f, v.want)
  1192. }
  1193. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1194. // Negating NaN is undefined with regard to the sign bit produced.
  1195. continue
  1196. }
  1197. // Exp(Conj(z)) == Exp(Cosh(z))
  1198. if f := Exp(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1199. t.Errorf("Exp(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1200. }
  1201. }
  1202. }
  1203. func TestIsNaN(t *testing.T) {
  1204. for i := 0; i < len(vcIsNaNSC); i++ {
  1205. if f := IsNaN(vcIsNaNSC[i]); isNaNSC[i] != f {
  1206. t.Errorf("IsNaN(%v) = %v, want %v", vcIsNaNSC[i], f, isNaNSC[i])
  1207. }
  1208. }
  1209. }
  1210. func TestLog(t *testing.T) {
  1211. for i := 0; i < len(vc); i++ {
  1212. if f := Log(vc[i]); !cVeryclose(log[i], f) {
  1213. t.Errorf("Log(%g) = %g, want %g", vc[i], f, log[i])
  1214. }
  1215. }
  1216. for _, v := range logSC {
  1217. if f := Log(v.in); !cAlike(v.want, f) {
  1218. t.Errorf("Log(%g) = %g, want %g", v.in, f, v.want)
  1219. }
  1220. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1221. // Negating NaN is undefined with regard to the sign bit produced.
  1222. continue
  1223. }
  1224. // Log(Conj(z)) == Conj(Log(z))
  1225. if f := Log(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1226. t.Errorf("Log(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1227. }
  1228. }
  1229. for _, pt := range branchPoints {
  1230. if f0, f1 := Log(pt[0]), Log(pt[1]); !cVeryclose(f0, f1) {
  1231. t.Errorf("Log(%g) not continuous, got %g want %g", pt[0], f0, f1)
  1232. }
  1233. }
  1234. }
  1235. func TestLog10(t *testing.T) {
  1236. for i := 0; i < len(vc); i++ {
  1237. if f := Log10(vc[i]); !cVeryclose(log10[i], f) {
  1238. t.Errorf("Log10(%g) = %g, want %g", vc[i], f, log10[i])
  1239. }
  1240. }
  1241. for _, v := range log10SC {
  1242. if f := Log10(v.in); !cAlike(v.want, f) {
  1243. t.Errorf("Log10(%g) = %g, want %g", v.in, f, v.want)
  1244. }
  1245. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1246. // Negating NaN is undefined with regard to the sign bit produced.
  1247. continue
  1248. }
  1249. // Log10(Conj(z)) == Conj(Log10(z))
  1250. if f := Log10(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1251. t.Errorf("Log10(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1252. }
  1253. }
  1254. }
  1255. func TestPolar(t *testing.T) {
  1256. for i := 0; i < len(vc); i++ {
  1257. if r, theta := Polar(vc[i]); !veryclose(polar[i].r, r) && !veryclose(polar[i].theta, theta) {
  1258. t.Errorf("Polar(%g) = %g, %g want %g, %g", vc[i], r, theta, polar[i].r, polar[i].theta)
  1259. }
  1260. }
  1261. for i := 0; i < len(vcPolarSC); i++ {
  1262. if r, theta := Polar(vcPolarSC[i]); !alike(polarSC[i].r, r) && !alike(polarSC[i].theta, theta) {
  1263. t.Errorf("Polar(%g) = %g, %g, want %g, %g", vcPolarSC[i], r, theta, polarSC[i].r, polarSC[i].theta)
  1264. }
  1265. }
  1266. }
  1267. func TestPow(t *testing.T) {
  1268. // Special cases for Pow(0, c).
  1269. var zero = complex(0, 0)
  1270. zeroPowers := [][2]complex128{
  1271. {0, 1 + 0i},
  1272. {1.5, 0 + 0i},
  1273. {-1.5, complex(math.Inf(0), 0)},
  1274. {-1.5 + 1.5i, Inf()},
  1275. }
  1276. for _, zp := range zeroPowers {
  1277. if f := Pow(zero, zp[0]); f != zp[1] {
  1278. t.Errorf("Pow(%g, %g) = %g, want %g", zero, zp[0], f, zp[1])
  1279. }
  1280. }
  1281. var a = complex(3.0, 3.0)
  1282. for i := 0; i < len(vc); i++ {
  1283. if f := Pow(a, vc[i]); !cSoclose(pow[i], f, 4e-15) {
  1284. t.Errorf("Pow(%g, %g) = %g, want %g", a, vc[i], f, pow[i])
  1285. }
  1286. }
  1287. for i := 0; i < len(vcPowSC); i++ {
  1288. if f := Pow(vcPowSC[i][0], vcPowSC[i][1]); !cAlike(powSC[i], f) {
  1289. t.Errorf("Pow(%g, %g) = %g, want %g", vcPowSC[i][0], vcPowSC[i][1], f, powSC[i])
  1290. }
  1291. }
  1292. for _, pt := range branchPoints {
  1293. if f0, f1 := Pow(pt[0], 0.1), Pow(pt[1], 0.1); !cVeryclose(f0, f1) {
  1294. t.Errorf("Pow(%g, 0.1) not continuous, got %g want %g", pt[0], f0, f1)
  1295. }
  1296. }
  1297. }
  1298. func TestRect(t *testing.T) {
  1299. for i := 0; i < len(vc); i++ {
  1300. if f := Rect(polar[i].r, polar[i].theta); !cVeryclose(vc[i], f) {
  1301. t.Errorf("Rect(%g, %g) = %g want %g", polar[i].r, polar[i].theta, f, vc[i])
  1302. }
  1303. }
  1304. for i := 0; i < len(vcPolarSC); i++ {
  1305. if f := Rect(polarSC[i].r, polarSC[i].theta); !cAlike(vcPolarSC[i], f) {
  1306. t.Errorf("Rect(%g, %g) = %g, want %g", polarSC[i].r, polarSC[i].theta, f, vcPolarSC[i])
  1307. }
  1308. }
  1309. }
  1310. func TestSin(t *testing.T) {
  1311. for i := 0; i < len(vc); i++ {
  1312. if f := Sin(vc[i]); !cSoclose(sin[i], f, 2e-15) {
  1313. t.Errorf("Sin(%g) = %g, want %g", vc[i], f, sin[i])
  1314. }
  1315. }
  1316. for _, v := range sinSC {
  1317. if f := Sin(v.in); !cAlike(v.want, f) {
  1318. t.Errorf("Sin(%g) = %g, want %g", v.in, f, v.want)
  1319. }
  1320. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1321. // Negating NaN is undefined with regard to the sign bit produced.
  1322. continue
  1323. }
  1324. // Sin(Conj(z)) == Conj(Sin(z))
  1325. if f := Sin(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1326. t.Errorf("Sinh(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1327. }
  1328. if math.IsNaN(real(v.in)) || math.IsNaN(real(v.want)) {
  1329. // Negating NaN is undefined with regard to the sign bit produced.
  1330. continue
  1331. }
  1332. // Sin(-z) == -Sin(z)
  1333. if f := Sin(-v.in); !cAlike(-v.want, f) && !cAlike(v.in, -v.in) {
  1334. t.Errorf("Sinh(%g) = %g, want %g", -v.in, f, -v.want)
  1335. }
  1336. }
  1337. }
  1338. func TestSinh(t *testing.T) {
  1339. for i := 0; i < len(vc); i++ {
  1340. if f := Sinh(vc[i]); !cSoclose(sinh[i], f, 2e-15) {
  1341. t.Errorf("Sinh(%g) = %g, want %g", vc[i], f, sinh[i])
  1342. }
  1343. }
  1344. for _, v := range sinhSC {
  1345. if f := Sinh(v.in); !cAlike(v.want, f) {
  1346. t.Errorf("Sinh(%g) = %g, want %g", v.in, f, v.want)
  1347. }
  1348. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1349. // Negating NaN is undefined with regard to the sign bit produced.
  1350. continue
  1351. }
  1352. // Sinh(Conj(z)) == Conj(Sinh(z))
  1353. if f := Sinh(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1354. t.Errorf("Sinh(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1355. }
  1356. if math.IsNaN(real(v.in)) || math.IsNaN(real(v.want)) {
  1357. // Negating NaN is undefined with regard to the sign bit produced.
  1358. continue
  1359. }
  1360. // Sinh(-z) == -Sinh(z)
  1361. if f := Sinh(-v.in); !cAlike(-v.want, f) && !cAlike(v.in, -v.in) {
  1362. t.Errorf("Sinh(%g) = %g, want %g", -v.in, f, -v.want)
  1363. }
  1364. }
  1365. }
  1366. func TestSqrt(t *testing.T) {
  1367. for i := 0; i < len(vc); i++ {
  1368. if f := Sqrt(vc[i]); !cVeryclose(sqrt[i], f) {
  1369. t.Errorf("Sqrt(%g) = %g, want %g", vc[i], f, sqrt[i])
  1370. }
  1371. }
  1372. for _, v := range sqrtSC {
  1373. if f := Sqrt(v.in); !cAlike(v.want, f) {
  1374. t.Errorf("Sqrt(%g) = %g, want %g", v.in, f, v.want)
  1375. }
  1376. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1377. // Negating NaN is undefined with regard to the sign bit produced.
  1378. continue
  1379. }
  1380. // Sqrt(Conj(z)) == Conj(Sqrt(z))
  1381. if f := Sqrt(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1382. t.Errorf("Sqrt(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1383. }
  1384. }
  1385. for _, pt := range branchPoints {
  1386. if f0, f1 := Sqrt(pt[0]), Sqrt(pt[1]); !cVeryclose(f0, f1) {
  1387. t.Errorf("Sqrt(%g) not continuous, got %g want %g", pt[0], f0, f1)
  1388. }
  1389. }
  1390. }
  1391. func TestTan(t *testing.T) {
  1392. for i := 0; i < len(vc); i++ {
  1393. if f := Tan(vc[i]); !cSoclose(tan[i], f, 3e-15) {
  1394. t.Errorf("Tan(%g) = %g, want %g", vc[i], f, tan[i])
  1395. }
  1396. }
  1397. for _, v := range tanSC {
  1398. if f := Tan(v.in); !cAlike(v.want, f) {
  1399. t.Errorf("Tan(%g) = %g, want %g", v.in, f, v.want)
  1400. }
  1401. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1402. // Negating NaN is undefined with regard to the sign bit produced.
  1403. continue
  1404. }
  1405. // Tan(Conj(z)) == Conj(Tan(z))
  1406. if f := Tan(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1407. t.Errorf("Tan(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1408. }
  1409. if math.IsNaN(real(v.in)) || math.IsNaN(real(v.want)) {
  1410. // Negating NaN is undefined with regard to the sign bit produced.
  1411. continue
  1412. }
  1413. // Tan(-z) == -Tan(z)
  1414. if f := Tan(-v.in); !cAlike(-v.want, f) && !cAlike(v.in, -v.in) {
  1415. t.Errorf("Tan(%g) = %g, want %g", -v.in, f, -v.want)
  1416. }
  1417. }
  1418. }
  1419. func TestTanh(t *testing.T) {
  1420. for i := 0; i < len(vc); i++ {
  1421. if f := Tanh(vc[i]); !cSoclose(tanh[i], f, 2e-15) {
  1422. t.Errorf("Tanh(%g) = %g, want %g", vc[i], f, tanh[i])
  1423. }
  1424. }
  1425. for _, v := range tanhSC {
  1426. if f := Tanh(v.in); !cAlike(v.want, f) {
  1427. t.Errorf("Tanh(%g) = %g, want %g", v.in, f, v.want)
  1428. }
  1429. if math.IsNaN(imag(v.in)) || math.IsNaN(imag(v.want)) {
  1430. // Negating NaN is undefined with regard to the sign bit produced.
  1431. continue
  1432. }
  1433. // Tanh(Conj(z)) == Conj(Tanh(z))
  1434. if f := Tanh(Conj(v.in)); !cAlike(Conj(v.want), f) && !cAlike(v.in, Conj(v.in)) {
  1435. t.Errorf("Tanh(%g) = %g, want %g", Conj(v.in), f, Conj(v.want))
  1436. }
  1437. if math.IsNaN(real(v.in)) || math.IsNaN(real(v.want)) {
  1438. // Negating NaN is undefined with regard to the sign bit produced.
  1439. continue
  1440. }
  1441. // Tanh(-z) == -Tanh(z)
  1442. if f := Tanh(-v.in); !cAlike(-v.want, f) && !cAlike(v.in, -v.in) {
  1443. t.Errorf("Tanh(%g) = %g, want %g", -v.in, f, -v.want)
  1444. }
  1445. }
  1446. }
  1447. // See issue 17577
  1448. func TestInfiniteLoopIntanSeries(t *testing.T) {
  1449. want := Inf()
  1450. if got := Cot(0); got != want {
  1451. t.Errorf("Cot(0): got %g, want %g", got, want)
  1452. }
  1453. }
  1454. func BenchmarkAbs(b *testing.B) {
  1455. for i := 0; i < b.N; i++ {
  1456. Abs(complex(2.5, 3.5))
  1457. }
  1458. }
  1459. func BenchmarkAcos(b *testing.B) {
  1460. for i := 0; i < b.N; i++ {
  1461. Acos(complex(2.5, 3.5))
  1462. }
  1463. }
  1464. func BenchmarkAcosh(b *testing.B) {
  1465. for i := 0; i < b.N; i++ {
  1466. Acosh(complex(2.5, 3.5))
  1467. }
  1468. }
  1469. func BenchmarkAsin(b *testing.B) {
  1470. for i := 0; i < b.N; i++ {
  1471. Asin(complex(2.5, 3.5))
  1472. }
  1473. }
  1474. func BenchmarkAsinh(b *testing.B) {
  1475. for i := 0; i < b.N; i++ {
  1476. Asinh(complex(2.5, 3.5))
  1477. }
  1478. }
  1479. func BenchmarkAtan(b *testing.B) {
  1480. for i := 0; i < b.N; i++ {
  1481. Atan(complex(2.5, 3.5))
  1482. }
  1483. }
  1484. func BenchmarkAtanh(b *testing.B) {
  1485. for i := 0; i < b.N; i++ {
  1486. Atanh(complex(2.5, 3.5))
  1487. }
  1488. }
  1489. func BenchmarkConj(b *testing.B) {
  1490. for i := 0; i < b.N; i++ {
  1491. Conj(complex(2.5, 3.5))
  1492. }
  1493. }
  1494. func BenchmarkCos(b *testing.B) {
  1495. for i := 0; i < b.N; i++ {
  1496. Cos(complex(2.5, 3.5))
  1497. }
  1498. }
  1499. func BenchmarkCosh(b *testing.B) {
  1500. for i := 0; i < b.N; i++ {
  1501. Cosh(complex(2.5, 3.5))
  1502. }
  1503. }
  1504. func BenchmarkExp(b *testing.B) {
  1505. for i := 0; i < b.N; i++ {
  1506. Exp(complex(2.5, 3.5))
  1507. }
  1508. }
  1509. func BenchmarkLog(b *testing.B) {
  1510. for i := 0; i < b.N; i++ {
  1511. Log(complex(2.5, 3.5))
  1512. }
  1513. }
  1514. func BenchmarkLog10(b *testing.B) {
  1515. for i := 0; i < b.N; i++ {
  1516. Log10(complex(2.5, 3.5))
  1517. }
  1518. }
  1519. func BenchmarkPhase(b *testing.B) {
  1520. for i := 0; i < b.N; i++ {
  1521. Phase(complex(2.5, 3.5))
  1522. }
  1523. }
  1524. func BenchmarkPolar(b *testing.B) {
  1525. for i := 0; i < b.N; i++ {
  1526. Polar(complex(2.5, 3.5))
  1527. }
  1528. }
  1529. func BenchmarkPow(b *testing.B) {
  1530. for i := 0; i < b.N; i++ {
  1531. Pow(complex(2.5, 3.5), complex(2.5, 3.5))
  1532. }
  1533. }
  1534. func BenchmarkRect(b *testing.B) {
  1535. for i := 0; i < b.N; i++ {
  1536. Rect(2.5, 1.5)
  1537. }
  1538. }
  1539. func BenchmarkSin(b *testing.B) {
  1540. for i := 0; i < b.N; i++ {
  1541. Sin(complex(2.5, 3.5))
  1542. }
  1543. }
  1544. func BenchmarkSinh(b *testing.B) {
  1545. for i := 0; i < b.N; i++ {
  1546. Sinh(complex(2.5, 3.5))
  1547. }
  1548. }
  1549. func BenchmarkSqrt(b *testing.B) {
  1550. for i := 0; i < b.N; i++ {
  1551. Sqrt(complex(2.5, 3.5))
  1552. }
  1553. }
  1554. func BenchmarkTan(b *testing.B) {
  1555. for i := 0; i < b.N; i++ {
  1556. Tan(complex(2.5, 3.5))
  1557. }
  1558. }
  1559. func BenchmarkTanh(b *testing.B) {
  1560. for i := 0; i < b.N; i++ {
  1561. Tanh(complex(2.5, 3.5))
  1562. }
  1563. }