complex 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979
  1. // The template and inlines for the -*- C++ -*- complex number classes.
  2. // Copyright (C) 1997-2016 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file include/complex
  21. * This is a Standard C++ Library header.
  22. */
  23. //
  24. // ISO C++ 14882: 26.2 Complex Numbers
  25. // Note: this is not a conforming implementation.
  26. // Initially implemented by Ulrich Drepper <drepper@cygnus.com>
  27. // Improved by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
  28. //
  29. #ifndef _GLIBCXX_COMPLEX
  30. #define _GLIBCXX_COMPLEX 1
  31. #pragma GCC system_header
  32. #include <bits/c++config.h>
  33. #include <bits/cpp_type_traits.h>
  34. #include <ext/type_traits.h>
  35. #include <cmath>
  36. #include <sstream>
  37. // Get rid of a macro possibly defined in <complex.h>
  38. #undef complex
  39. namespace std _GLIBCXX_VISIBILITY(default)
  40. {
  41. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  42. /**
  43. * @defgroup complex_numbers Complex Numbers
  44. * @ingroup numerics
  45. *
  46. * Classes and functions for complex numbers.
  47. * @{
  48. */
  49. // Forward declarations.
  50. template<typename _Tp> class complex;
  51. template<> class complex<float>;
  52. template<> class complex<double>;
  53. template<> class complex<long double>;
  54. /// Return magnitude of @a z.
  55. template<typename _Tp> _Tp abs(const complex<_Tp>&);
  56. /// Return phase angle of @a z.
  57. template<typename _Tp> _Tp arg(const complex<_Tp>&);
  58. /// Return @a z magnitude squared.
  59. template<typename _Tp> _Tp norm(const complex<_Tp>&);
  60. /// Return complex conjugate of @a z.
  61. template<typename _Tp> complex<_Tp> conj(const complex<_Tp>&);
  62. /// Return complex with magnitude @a rho and angle @a theta.
  63. template<typename _Tp> complex<_Tp> polar(const _Tp&, const _Tp& = 0);
  64. // Transcendentals:
  65. /// Return complex cosine of @a z.
  66. template<typename _Tp> complex<_Tp> cos(const complex<_Tp>&);
  67. /// Return complex hyperbolic cosine of @a z.
  68. template<typename _Tp> complex<_Tp> cosh(const complex<_Tp>&);
  69. /// Return complex base e exponential of @a z.
  70. template<typename _Tp> complex<_Tp> exp(const complex<_Tp>&);
  71. /// Return complex natural logarithm of @a z.
  72. template<typename _Tp> complex<_Tp> log(const complex<_Tp>&);
  73. /// Return complex base 10 logarithm of @a z.
  74. template<typename _Tp> complex<_Tp> log10(const complex<_Tp>&);
  75. /// Return @a x to the @a y'th power.
  76. template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, int);
  77. /// Return @a x to the @a y'th power.
  78. template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, const _Tp&);
  79. /// Return @a x to the @a y'th power.
  80. template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&,
  81. const complex<_Tp>&);
  82. /// Return @a x to the @a y'th power.
  83. template<typename _Tp> complex<_Tp> pow(const _Tp&, const complex<_Tp>&);
  84. /// Return complex sine of @a z.
  85. template<typename _Tp> complex<_Tp> sin(const complex<_Tp>&);
  86. /// Return complex hyperbolic sine of @a z.
  87. template<typename _Tp> complex<_Tp> sinh(const complex<_Tp>&);
  88. /// Return complex square root of @a z.
  89. template<typename _Tp> complex<_Tp> sqrt(const complex<_Tp>&);
  90. /// Return complex tangent of @a z.
  91. template<typename _Tp> complex<_Tp> tan(const complex<_Tp>&);
  92. /// Return complex hyperbolic tangent of @a z.
  93. template<typename _Tp> complex<_Tp> tanh(const complex<_Tp>&);
  94. // 26.2.2 Primary template class complex
  95. /**
  96. * Template to represent complex numbers.
  97. *
  98. * Specializations for float, double, and long double are part of the
  99. * library. Results with any other type are not guaranteed.
  100. *
  101. * @param Tp Type of real and imaginary values.
  102. */
  103. template<typename _Tp>
  104. struct complex
  105. {
  106. /// Value typedef.
  107. typedef _Tp value_type;
  108. /// Default constructor. First parameter is x, second parameter is y.
  109. /// Unspecified parameters default to 0.
  110. _GLIBCXX_CONSTEXPR complex(const _Tp& __r = _Tp(), const _Tp& __i = _Tp())
  111. : _M_real(__r), _M_imag(__i) { }
  112. // Let the compiler synthesize the copy constructor
  113. #if __cplusplus >= 201103L
  114. constexpr complex(const complex&) = default;
  115. #endif
  116. /// Converting constructor.
  117. template<typename _Up>
  118. _GLIBCXX_CONSTEXPR complex(const complex<_Up>& __z)
  119. : _M_real(__z.real()), _M_imag(__z.imag()) { }
  120. #if __cplusplus >= 201103L
  121. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  122. // DR 387. std::complex over-encapsulated.
  123. _GLIBCXX_ABI_TAG_CXX11
  124. constexpr _Tp
  125. real() const { return _M_real; }
  126. _GLIBCXX_ABI_TAG_CXX11
  127. constexpr _Tp
  128. imag() const { return _M_imag; }
  129. #else
  130. /// Return real part of complex number.
  131. _Tp&
  132. real() { return _M_real; }
  133. /// Return real part of complex number.
  134. const _Tp&
  135. real() const { return _M_real; }
  136. /// Return imaginary part of complex number.
  137. _Tp&
  138. imag() { return _M_imag; }
  139. /// Return imaginary part of complex number.
  140. const _Tp&
  141. imag() const { return _M_imag; }
  142. #endif
  143. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  144. // DR 387. std::complex over-encapsulated.
  145. void
  146. real(_Tp __val) { _M_real = __val; }
  147. void
  148. imag(_Tp __val) { _M_imag = __val; }
  149. /// Assign a scalar to this complex number.
  150. complex<_Tp>& operator=(const _Tp&);
  151. /// Add a scalar to this complex number.
  152. // 26.2.5/1
  153. complex<_Tp>&
  154. operator+=(const _Tp& __t)
  155. {
  156. _M_real += __t;
  157. return *this;
  158. }
  159. /// Subtract a scalar from this complex number.
  160. // 26.2.5/3
  161. complex<_Tp>&
  162. operator-=(const _Tp& __t)
  163. {
  164. _M_real -= __t;
  165. return *this;
  166. }
  167. /// Multiply this complex number by a scalar.
  168. complex<_Tp>& operator*=(const _Tp&);
  169. /// Divide this complex number by a scalar.
  170. complex<_Tp>& operator/=(const _Tp&);
  171. // Let the compiler synthesize the copy assignment operator
  172. #if __cplusplus >= 201103L
  173. complex& operator=(const complex&) = default;
  174. #endif
  175. /// Assign another complex number to this one.
  176. template<typename _Up>
  177. complex<_Tp>& operator=(const complex<_Up>&);
  178. /// Add another complex number to this one.
  179. template<typename _Up>
  180. complex<_Tp>& operator+=(const complex<_Up>&);
  181. /// Subtract another complex number from this one.
  182. template<typename _Up>
  183. complex<_Tp>& operator-=(const complex<_Up>&);
  184. /// Multiply this complex number by another.
  185. template<typename _Up>
  186. complex<_Tp>& operator*=(const complex<_Up>&);
  187. /// Divide this complex number by another.
  188. template<typename _Up>
  189. complex<_Tp>& operator/=(const complex<_Up>&);
  190. _GLIBCXX_CONSTEXPR complex __rep() const
  191. { return *this; }
  192. private:
  193. _Tp _M_real;
  194. _Tp _M_imag;
  195. };
  196. template<typename _Tp>
  197. complex<_Tp>&
  198. complex<_Tp>::operator=(const _Tp& __t)
  199. {
  200. _M_real = __t;
  201. _M_imag = _Tp();
  202. return *this;
  203. }
  204. // 26.2.5/5
  205. template<typename _Tp>
  206. complex<_Tp>&
  207. complex<_Tp>::operator*=(const _Tp& __t)
  208. {
  209. _M_real *= __t;
  210. _M_imag *= __t;
  211. return *this;
  212. }
  213. // 26.2.5/7
  214. template<typename _Tp>
  215. complex<_Tp>&
  216. complex<_Tp>::operator/=(const _Tp& __t)
  217. {
  218. _M_real /= __t;
  219. _M_imag /= __t;
  220. return *this;
  221. }
  222. template<typename _Tp>
  223. template<typename _Up>
  224. complex<_Tp>&
  225. complex<_Tp>::operator=(const complex<_Up>& __z)
  226. {
  227. _M_real = __z.real();
  228. _M_imag = __z.imag();
  229. return *this;
  230. }
  231. // 26.2.5/9
  232. template<typename _Tp>
  233. template<typename _Up>
  234. complex<_Tp>&
  235. complex<_Tp>::operator+=(const complex<_Up>& __z)
  236. {
  237. _M_real += __z.real();
  238. _M_imag += __z.imag();
  239. return *this;
  240. }
  241. // 26.2.5/11
  242. template<typename _Tp>
  243. template<typename _Up>
  244. complex<_Tp>&
  245. complex<_Tp>::operator-=(const complex<_Up>& __z)
  246. {
  247. _M_real -= __z.real();
  248. _M_imag -= __z.imag();
  249. return *this;
  250. }
  251. // 26.2.5/13
  252. // XXX: This is a grammar school implementation.
  253. template<typename _Tp>
  254. template<typename _Up>
  255. complex<_Tp>&
  256. complex<_Tp>::operator*=(const complex<_Up>& __z)
  257. {
  258. const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
  259. _M_imag = _M_real * __z.imag() + _M_imag * __z.real();
  260. _M_real = __r;
  261. return *this;
  262. }
  263. // 26.2.5/15
  264. // XXX: This is a grammar school implementation.
  265. template<typename _Tp>
  266. template<typename _Up>
  267. complex<_Tp>&
  268. complex<_Tp>::operator/=(const complex<_Up>& __z)
  269. {
  270. const _Tp __r = _M_real * __z.real() + _M_imag * __z.imag();
  271. const _Tp __n = std::norm(__z);
  272. _M_imag = (_M_imag * __z.real() - _M_real * __z.imag()) / __n;
  273. _M_real = __r / __n;
  274. return *this;
  275. }
  276. // Operators:
  277. //@{
  278. /// Return new complex value @a x plus @a y.
  279. template<typename _Tp>
  280. inline complex<_Tp>
  281. operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
  282. {
  283. complex<_Tp> __r = __x;
  284. __r += __y;
  285. return __r;
  286. }
  287. template<typename _Tp>
  288. inline complex<_Tp>
  289. operator+(const complex<_Tp>& __x, const _Tp& __y)
  290. {
  291. complex<_Tp> __r = __x;
  292. __r += __y;
  293. return __r;
  294. }
  295. template<typename _Tp>
  296. inline complex<_Tp>
  297. operator+(const _Tp& __x, const complex<_Tp>& __y)
  298. {
  299. complex<_Tp> __r = __y;
  300. __r += __x;
  301. return __r;
  302. }
  303. //@}
  304. //@{
  305. /// Return new complex value @a x minus @a y.
  306. template<typename _Tp>
  307. inline complex<_Tp>
  308. operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
  309. {
  310. complex<_Tp> __r = __x;
  311. __r -= __y;
  312. return __r;
  313. }
  314. template<typename _Tp>
  315. inline complex<_Tp>
  316. operator-(const complex<_Tp>& __x, const _Tp& __y)
  317. {
  318. complex<_Tp> __r = __x;
  319. __r -= __y;
  320. return __r;
  321. }
  322. template<typename _Tp>
  323. inline complex<_Tp>
  324. operator-(const _Tp& __x, const complex<_Tp>& __y)
  325. {
  326. complex<_Tp> __r(__x, -__y.imag());
  327. __r -= __y.real();
  328. return __r;
  329. }
  330. //@}
  331. //@{
  332. /// Return new complex value @a x times @a y.
  333. template<typename _Tp>
  334. inline complex<_Tp>
  335. operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
  336. {
  337. complex<_Tp> __r = __x;
  338. __r *= __y;
  339. return __r;
  340. }
  341. template<typename _Tp>
  342. inline complex<_Tp>
  343. operator*(const complex<_Tp>& __x, const _Tp& __y)
  344. {
  345. complex<_Tp> __r = __x;
  346. __r *= __y;
  347. return __r;
  348. }
  349. template<typename _Tp>
  350. inline complex<_Tp>
  351. operator*(const _Tp& __x, const complex<_Tp>& __y)
  352. {
  353. complex<_Tp> __r = __y;
  354. __r *= __x;
  355. return __r;
  356. }
  357. //@}
  358. //@{
  359. /// Return new complex value @a x divided by @a y.
  360. template<typename _Tp>
  361. inline complex<_Tp>
  362. operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
  363. {
  364. complex<_Tp> __r = __x;
  365. __r /= __y;
  366. return __r;
  367. }
  368. template<typename _Tp>
  369. inline complex<_Tp>
  370. operator/(const complex<_Tp>& __x, const _Tp& __y)
  371. {
  372. complex<_Tp> __r = __x;
  373. __r /= __y;
  374. return __r;
  375. }
  376. template<typename _Tp>
  377. inline complex<_Tp>
  378. operator/(const _Tp& __x, const complex<_Tp>& __y)
  379. {
  380. complex<_Tp> __r = __x;
  381. __r /= __y;
  382. return __r;
  383. }
  384. //@}
  385. /// Return @a x.
  386. template<typename _Tp>
  387. inline complex<_Tp>
  388. operator+(const complex<_Tp>& __x)
  389. { return __x; }
  390. /// Return complex negation of @a x.
  391. template<typename _Tp>
  392. inline complex<_Tp>
  393. operator-(const complex<_Tp>& __x)
  394. { return complex<_Tp>(-__x.real(), -__x.imag()); }
  395. //@{
  396. /// Return true if @a x is equal to @a y.
  397. template<typename _Tp>
  398. inline _GLIBCXX_CONSTEXPR bool
  399. operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
  400. { return __x.real() == __y.real() && __x.imag() == __y.imag(); }
  401. template<typename _Tp>
  402. inline _GLIBCXX_CONSTEXPR bool
  403. operator==(const complex<_Tp>& __x, const _Tp& __y)
  404. { return __x.real() == __y && __x.imag() == _Tp(); }
  405. template<typename _Tp>
  406. inline _GLIBCXX_CONSTEXPR bool
  407. operator==(const _Tp& __x, const complex<_Tp>& __y)
  408. { return __x == __y.real() && _Tp() == __y.imag(); }
  409. //@}
  410. //@{
  411. /// Return false if @a x is equal to @a y.
  412. template<typename _Tp>
  413. inline _GLIBCXX_CONSTEXPR bool
  414. operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
  415. { return __x.real() != __y.real() || __x.imag() != __y.imag(); }
  416. template<typename _Tp>
  417. inline _GLIBCXX_CONSTEXPR bool
  418. operator!=(const complex<_Tp>& __x, const _Tp& __y)
  419. { return __x.real() != __y || __x.imag() != _Tp(); }
  420. template<typename _Tp>
  421. inline _GLIBCXX_CONSTEXPR bool
  422. operator!=(const _Tp& __x, const complex<_Tp>& __y)
  423. { return __x != __y.real() || _Tp() != __y.imag(); }
  424. //@}
  425. /// Extraction operator for complex values.
  426. template<typename _Tp, typename _CharT, class _Traits>
  427. basic_istream<_CharT, _Traits>&
  428. operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
  429. {
  430. _Tp __re_x, __im_x;
  431. _CharT __ch;
  432. __is >> __ch;
  433. if (__ch == '(')
  434. {
  435. __is >> __re_x >> __ch;
  436. if (__ch == ',')
  437. {
  438. __is >> __im_x >> __ch;
  439. if (__ch == ')')
  440. __x = complex<_Tp>(__re_x, __im_x);
  441. else
  442. __is.setstate(ios_base::failbit);
  443. }
  444. else if (__ch == ')')
  445. __x = __re_x;
  446. else
  447. __is.setstate(ios_base::failbit);
  448. }
  449. else
  450. {
  451. __is.putback(__ch);
  452. __is >> __re_x;
  453. __x = __re_x;
  454. }
  455. return __is;
  456. }
  457. /// Insertion operator for complex values.
  458. template<typename _Tp, typename _CharT, class _Traits>
  459. basic_ostream<_CharT, _Traits>&
  460. operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
  461. {
  462. basic_ostringstream<_CharT, _Traits> __s;
  463. __s.flags(__os.flags());
  464. __s.imbue(__os.getloc());
  465. __s.precision(__os.precision());
  466. __s << '(' << __x.real() << ',' << __x.imag() << ')';
  467. return __os << __s.str();
  468. }
  469. // Values
  470. #if __cplusplus >= 201103L
  471. template<typename _Tp>
  472. constexpr _Tp
  473. real(const complex<_Tp>& __z)
  474. { return __z.real(); }
  475. template<typename _Tp>
  476. constexpr _Tp
  477. imag(const complex<_Tp>& __z)
  478. { return __z.imag(); }
  479. #else
  480. template<typename _Tp>
  481. inline _Tp&
  482. real(complex<_Tp>& __z)
  483. { return __z.real(); }
  484. template<typename _Tp>
  485. inline const _Tp&
  486. real(const complex<_Tp>& __z)
  487. { return __z.real(); }
  488. template<typename _Tp>
  489. inline _Tp&
  490. imag(complex<_Tp>& __z)
  491. { return __z.imag(); }
  492. template<typename _Tp>
  493. inline const _Tp&
  494. imag(const complex<_Tp>& __z)
  495. { return __z.imag(); }
  496. #endif
  497. // 26.2.7/3 abs(__z): Returns the magnitude of __z.
  498. template<typename _Tp>
  499. inline _Tp
  500. __complex_abs(const complex<_Tp>& __z)
  501. {
  502. _Tp __x = __z.real();
  503. _Tp __y = __z.imag();
  504. const _Tp __s = std::max(abs(__x), abs(__y));
  505. if (__s == _Tp()) // well ...
  506. return __s;
  507. __x /= __s;
  508. __y /= __s;
  509. return __s * sqrt(__x * __x + __y * __y);
  510. }
  511. #if _GLIBCXX_USE_C99_COMPLEX
  512. inline float
  513. __complex_abs(__complex__ float __z) { return __builtin_cabsf(__z); }
  514. inline double
  515. __complex_abs(__complex__ double __z) { return __builtin_cabs(__z); }
  516. inline long double
  517. __complex_abs(const __complex__ long double& __z)
  518. { return __builtin_cabsl(__z); }
  519. template<typename _Tp>
  520. inline _Tp
  521. abs(const complex<_Tp>& __z) { return __complex_abs(__z.__rep()); }
  522. #else
  523. template<typename _Tp>
  524. inline _Tp
  525. abs(const complex<_Tp>& __z) { return __complex_abs(__z); }
  526. #endif
  527. // 26.2.7/4: arg(__z): Returns the phase angle of __z.
  528. template<typename _Tp>
  529. inline _Tp
  530. __complex_arg(const complex<_Tp>& __z)
  531. { return atan2(__z.imag(), __z.real()); }
  532. #if _GLIBCXX_USE_C99_COMPLEX
  533. inline float
  534. __complex_arg(__complex__ float __z) { return __builtin_cargf(__z); }
  535. inline double
  536. __complex_arg(__complex__ double __z) { return __builtin_carg(__z); }
  537. inline long double
  538. __complex_arg(const __complex__ long double& __z)
  539. { return __builtin_cargl(__z); }
  540. template<typename _Tp>
  541. inline _Tp
  542. arg(const complex<_Tp>& __z) { return __complex_arg(__z.__rep()); }
  543. #else
  544. template<typename _Tp>
  545. inline _Tp
  546. arg(const complex<_Tp>& __z) { return __complex_arg(__z); }
  547. #endif
  548. // 26.2.7/5: norm(__z) returns the squared magnitude of __z.
  549. // As defined, norm() is -not- a norm is the common mathematical
  550. // sense used in numerics. The helper class _Norm_helper<> tries to
  551. // distinguish between builtin floating point and the rest, so as
  552. // to deliver an answer as close as possible to the real value.
  553. template<bool>
  554. struct _Norm_helper
  555. {
  556. template<typename _Tp>
  557. static inline _Tp _S_do_it(const complex<_Tp>& __z)
  558. {
  559. const _Tp __x = __z.real();
  560. const _Tp __y = __z.imag();
  561. return __x * __x + __y * __y;
  562. }
  563. };
  564. template<>
  565. struct _Norm_helper<true>
  566. {
  567. template<typename _Tp>
  568. static inline _Tp _S_do_it(const complex<_Tp>& __z)
  569. {
  570. _Tp __res = std::abs(__z);
  571. return __res * __res;
  572. }
  573. };
  574. template<typename _Tp>
  575. inline _Tp
  576. norm(const complex<_Tp>& __z)
  577. {
  578. return _Norm_helper<__is_floating<_Tp>::__value
  579. && !_GLIBCXX_FAST_MATH>::_S_do_it(__z);
  580. }
  581. template<typename _Tp>
  582. inline complex<_Tp>
  583. polar(const _Tp& __rho, const _Tp& __theta)
  584. {
  585. __glibcxx_assert( __rho >= 0 );
  586. return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta));
  587. }
  588. template<typename _Tp>
  589. inline complex<_Tp>
  590. conj(const complex<_Tp>& __z)
  591. { return complex<_Tp>(__z.real(), -__z.imag()); }
  592. // Transcendentals
  593. // 26.2.8/1 cos(__z): Returns the cosine of __z.
  594. template<typename _Tp>
  595. inline complex<_Tp>
  596. __complex_cos(const complex<_Tp>& __z)
  597. {
  598. const _Tp __x = __z.real();
  599. const _Tp __y = __z.imag();
  600. return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y));
  601. }
  602. #if _GLIBCXX_USE_C99_COMPLEX
  603. inline __complex__ float
  604. __complex_cos(__complex__ float __z) { return __builtin_ccosf(__z); }
  605. inline __complex__ double
  606. __complex_cos(__complex__ double __z) { return __builtin_ccos(__z); }
  607. inline __complex__ long double
  608. __complex_cos(const __complex__ long double& __z)
  609. { return __builtin_ccosl(__z); }
  610. template<typename _Tp>
  611. inline complex<_Tp>
  612. cos(const complex<_Tp>& __z) { return __complex_cos(__z.__rep()); }
  613. #else
  614. template<typename _Tp>
  615. inline complex<_Tp>
  616. cos(const complex<_Tp>& __z) { return __complex_cos(__z); }
  617. #endif
  618. // 26.2.8/2 cosh(__z): Returns the hyperbolic cosine of __z.
  619. template<typename _Tp>
  620. inline complex<_Tp>
  621. __complex_cosh(const complex<_Tp>& __z)
  622. {
  623. const _Tp __x = __z.real();
  624. const _Tp __y = __z.imag();
  625. return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y));
  626. }
  627. #if _GLIBCXX_USE_C99_COMPLEX
  628. inline __complex__ float
  629. __complex_cosh(__complex__ float __z) { return __builtin_ccoshf(__z); }
  630. inline __complex__ double
  631. __complex_cosh(__complex__ double __z) { return __builtin_ccosh(__z); }
  632. inline __complex__ long double
  633. __complex_cosh(const __complex__ long double& __z)
  634. { return __builtin_ccoshl(__z); }
  635. template<typename _Tp>
  636. inline complex<_Tp>
  637. cosh(const complex<_Tp>& __z) { return __complex_cosh(__z.__rep()); }
  638. #else
  639. template<typename _Tp>
  640. inline complex<_Tp>
  641. cosh(const complex<_Tp>& __z) { return __complex_cosh(__z); }
  642. #endif
  643. // 26.2.8/3 exp(__z): Returns the complex base e exponential of x
  644. template<typename _Tp>
  645. inline complex<_Tp>
  646. __complex_exp(const complex<_Tp>& __z)
  647. { return std::polar<_Tp>(exp(__z.real()), __z.imag()); }
  648. #if _GLIBCXX_USE_C99_COMPLEX
  649. inline __complex__ float
  650. __complex_exp(__complex__ float __z) { return __builtin_cexpf(__z); }
  651. inline __complex__ double
  652. __complex_exp(__complex__ double __z) { return __builtin_cexp(__z); }
  653. inline __complex__ long double
  654. __complex_exp(const __complex__ long double& __z)
  655. { return __builtin_cexpl(__z); }
  656. template<typename _Tp>
  657. inline complex<_Tp>
  658. exp(const complex<_Tp>& __z) { return __complex_exp(__z.__rep()); }
  659. #else
  660. template<typename _Tp>
  661. inline complex<_Tp>
  662. exp(const complex<_Tp>& __z) { return __complex_exp(__z); }
  663. #endif
  664. // 26.2.8/5 log(__z): Returns the natural complex logarithm of __z.
  665. // The branch cut is along the negative axis.
  666. template<typename _Tp>
  667. inline complex<_Tp>
  668. __complex_log(const complex<_Tp>& __z)
  669. { return complex<_Tp>(log(std::abs(__z)), std::arg(__z)); }
  670. #if _GLIBCXX_USE_C99_COMPLEX
  671. inline __complex__ float
  672. __complex_log(__complex__ float __z) { return __builtin_clogf(__z); }
  673. inline __complex__ double
  674. __complex_log(__complex__ double __z) { return __builtin_clog(__z); }
  675. inline __complex__ long double
  676. __complex_log(const __complex__ long double& __z)
  677. { return __builtin_clogl(__z); }
  678. template<typename _Tp>
  679. inline complex<_Tp>
  680. log(const complex<_Tp>& __z) { return __complex_log(__z.__rep()); }
  681. #else
  682. template<typename _Tp>
  683. inline complex<_Tp>
  684. log(const complex<_Tp>& __z) { return __complex_log(__z); }
  685. #endif
  686. template<typename _Tp>
  687. inline complex<_Tp>
  688. log10(const complex<_Tp>& __z)
  689. { return std::log(__z) / log(_Tp(10.0)); }
  690. // 26.2.8/10 sin(__z): Returns the sine of __z.
  691. template<typename _Tp>
  692. inline complex<_Tp>
  693. __complex_sin(const complex<_Tp>& __z)
  694. {
  695. const _Tp __x = __z.real();
  696. const _Tp __y = __z.imag();
  697. return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y));
  698. }
  699. #if _GLIBCXX_USE_C99_COMPLEX
  700. inline __complex__ float
  701. __complex_sin(__complex__ float __z) { return __builtin_csinf(__z); }
  702. inline __complex__ double
  703. __complex_sin(__complex__ double __z) { return __builtin_csin(__z); }
  704. inline __complex__ long double
  705. __complex_sin(const __complex__ long double& __z)
  706. { return __builtin_csinl(__z); }
  707. template<typename _Tp>
  708. inline complex<_Tp>
  709. sin(const complex<_Tp>& __z) { return __complex_sin(__z.__rep()); }
  710. #else
  711. template<typename _Tp>
  712. inline complex<_Tp>
  713. sin(const complex<_Tp>& __z) { return __complex_sin(__z); }
  714. #endif
  715. // 26.2.8/11 sinh(__z): Returns the hyperbolic sine of __z.
  716. template<typename _Tp>
  717. inline complex<_Tp>
  718. __complex_sinh(const complex<_Tp>& __z)
  719. {
  720. const _Tp __x = __z.real();
  721. const _Tp __y = __z.imag();
  722. return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y));
  723. }
  724. #if _GLIBCXX_USE_C99_COMPLEX
  725. inline __complex__ float
  726. __complex_sinh(__complex__ float __z) { return __builtin_csinhf(__z); }
  727. inline __complex__ double
  728. __complex_sinh(__complex__ double __z) { return __builtin_csinh(__z); }
  729. inline __complex__ long double
  730. __complex_sinh(const __complex__ long double& __z)
  731. { return __builtin_csinhl(__z); }
  732. template<typename _Tp>
  733. inline complex<_Tp>
  734. sinh(const complex<_Tp>& __z) { return __complex_sinh(__z.__rep()); }
  735. #else
  736. template<typename _Tp>
  737. inline complex<_Tp>
  738. sinh(const complex<_Tp>& __z) { return __complex_sinh(__z); }
  739. #endif
  740. // 26.2.8/13 sqrt(__z): Returns the complex square root of __z.
  741. // The branch cut is on the negative axis.
  742. template<typename _Tp>
  743. complex<_Tp>
  744. __complex_sqrt(const complex<_Tp>& __z)
  745. {
  746. _Tp __x = __z.real();
  747. _Tp __y = __z.imag();
  748. if (__x == _Tp())
  749. {
  750. _Tp __t = sqrt(abs(__y) / 2);
  751. return complex<_Tp>(__t, __y < _Tp() ? -__t : __t);
  752. }
  753. else
  754. {
  755. _Tp __t = sqrt(2 * (std::abs(__z) + abs(__x)));
  756. _Tp __u = __t / 2;
  757. return __x > _Tp()
  758. ? complex<_Tp>(__u, __y / __t)
  759. : complex<_Tp>(abs(__y) / __t, __y < _Tp() ? -__u : __u);
  760. }
  761. }
  762. #if _GLIBCXX_USE_C99_COMPLEX
  763. inline __complex__ float
  764. __complex_sqrt(__complex__ float __z) { return __builtin_csqrtf(__z); }
  765. inline __complex__ double
  766. __complex_sqrt(__complex__ double __z) { return __builtin_csqrt(__z); }
  767. inline __complex__ long double
  768. __complex_sqrt(const __complex__ long double& __z)
  769. { return __builtin_csqrtl(__z); }
  770. template<typename _Tp>
  771. inline complex<_Tp>
  772. sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z.__rep()); }
  773. #else
  774. template<typename _Tp>
  775. inline complex<_Tp>
  776. sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z); }
  777. #endif
  778. // 26.2.8/14 tan(__z): Return the complex tangent of __z.
  779. template<typename _Tp>
  780. inline complex<_Tp>
  781. __complex_tan(const complex<_Tp>& __z)
  782. { return std::sin(__z) / std::cos(__z); }
  783. #if _GLIBCXX_USE_C99_COMPLEX
  784. inline __complex__ float
  785. __complex_tan(__complex__ float __z) { return __builtin_ctanf(__z); }
  786. inline __complex__ double
  787. __complex_tan(__complex__ double __z) { return __builtin_ctan(__z); }
  788. inline __complex__ long double
  789. __complex_tan(const __complex__ long double& __z)
  790. { return __builtin_ctanl(__z); }
  791. template<typename _Tp>
  792. inline complex<_Tp>
  793. tan(const complex<_Tp>& __z) { return __complex_tan(__z.__rep()); }
  794. #else
  795. template<typename _Tp>
  796. inline complex<_Tp>
  797. tan(const complex<_Tp>& __z) { return __complex_tan(__z); }
  798. #endif
  799. // 26.2.8/15 tanh(__z): Returns the hyperbolic tangent of __z.
  800. template<typename _Tp>
  801. inline complex<_Tp>
  802. __complex_tanh(const complex<_Tp>& __z)
  803. { return std::sinh(__z) / std::cosh(__z); }
  804. #if _GLIBCXX_USE_C99_COMPLEX
  805. inline __complex__ float
  806. __complex_tanh(__complex__ float __z) { return __builtin_ctanhf(__z); }
  807. inline __complex__ double
  808. __complex_tanh(__complex__ double __z) { return __builtin_ctanh(__z); }
  809. inline __complex__ long double
  810. __complex_tanh(const __complex__ long double& __z)
  811. { return __builtin_ctanhl(__z); }
  812. template<typename _Tp>
  813. inline complex<_Tp>
  814. tanh(const complex<_Tp>& __z) { return __complex_tanh(__z.__rep()); }
  815. #else
  816. template<typename _Tp>
  817. inline complex<_Tp>
  818. tanh(const complex<_Tp>& __z) { return __complex_tanh(__z); }
  819. #endif
  820. // 26.2.8/9 pow(__x, __y): Returns the complex power base of __x
  821. // raised to the __y-th power. The branch
  822. // cut is on the negative axis.
  823. template<typename _Tp>
  824. complex<_Tp>
  825. __complex_pow_unsigned(complex<_Tp> __x, unsigned __n)
  826. {
  827. complex<_Tp> __y = __n % 2 ? __x : complex<_Tp>(1);
  828. while (__n >>= 1)
  829. {
  830. __x *= __x;
  831. if (__n % 2)
  832. __y *= __x;
  833. }
  834. return __y;
  835. }
  836. // In C++11 mode we used to implement the resolution of
  837. // DR 844. complex pow return type is ambiguous.
  838. // thus the following overload was disabled in that mode. However, doing
  839. // that causes all sorts of issues, see, for example:
  840. // http://gcc.gnu.org/ml/libstdc++/2013-01/msg00058.html
  841. // and also PR57974.
  842. template<typename _Tp>
  843. inline complex<_Tp>
  844. pow(const complex<_Tp>& __z, int __n)
  845. {
  846. return __n < 0
  847. ? complex<_Tp>(1) / std::__complex_pow_unsigned(__z, -(unsigned)__n)
  848. : std::__complex_pow_unsigned(__z, __n);
  849. }
  850. template<typename _Tp>
  851. complex<_Tp>
  852. pow(const complex<_Tp>& __x, const _Tp& __y)
  853. {
  854. #if ! _GLIBCXX_USE_C99_COMPLEX
  855. if (__x == _Tp())
  856. return _Tp();
  857. #endif
  858. if (__x.imag() == _Tp() && __x.real() > _Tp())
  859. return pow(__x.real(), __y);
  860. complex<_Tp> __t = std::log(__x);
  861. return std::polar<_Tp>(exp(__y * __t.real()), __y * __t.imag());
  862. }
  863. template<typename _Tp>
  864. inline complex<_Tp>
  865. __complex_pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
  866. { return __x == _Tp() ? _Tp() : std::exp(__y * std::log(__x)); }
  867. #if _GLIBCXX_USE_C99_COMPLEX
  868. inline __complex__ float
  869. __complex_pow(__complex__ float __x, __complex__ float __y)
  870. { return __builtin_cpowf(__x, __y); }
  871. inline __complex__ double
  872. __complex_pow(__complex__ double __x, __complex__ double __y)
  873. { return __builtin_cpow(__x, __y); }
  874. inline __complex__ long double
  875. __complex_pow(const __complex__ long double& __x,
  876. const __complex__ long double& __y)
  877. { return __builtin_cpowl(__x, __y); }
  878. template<typename _Tp>
  879. inline complex<_Tp>
  880. pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
  881. { return __complex_pow(__x.__rep(), __y.__rep()); }
  882. #else
  883. template<typename _Tp>
  884. inline complex<_Tp>
  885. pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
  886. { return __complex_pow(__x, __y); }
  887. #endif
  888. template<typename _Tp>
  889. inline complex<_Tp>
  890. pow(const _Tp& __x, const complex<_Tp>& __y)
  891. {
  892. return __x > _Tp() ? std::polar<_Tp>(pow(__x, __y.real()),
  893. __y.imag() * log(__x))
  894. : std::pow(complex<_Tp>(__x), __y);
  895. }
  896. /// 26.2.3 complex specializations
  897. /// complex<float> specialization
  898. template<>
  899. struct complex<float>
  900. {
  901. typedef float value_type;
  902. typedef __complex__ float _ComplexT;
  903. _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
  904. _GLIBCXX_CONSTEXPR complex(float __r = 0.0f, float __i = 0.0f)
  905. #if __cplusplus >= 201103L
  906. : _M_value{ __r, __i } { }
  907. #else
  908. {
  909. __real__ _M_value = __r;
  910. __imag__ _M_value = __i;
  911. }
  912. #endif
  913. explicit _GLIBCXX_CONSTEXPR complex(const complex<double>&);
  914. explicit _GLIBCXX_CONSTEXPR complex(const complex<long double>&);
  915. #if __cplusplus >= 201103L
  916. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  917. // DR 387. std::complex over-encapsulated.
  918. __attribute ((__abi_tag__ ("cxx11")))
  919. constexpr float
  920. real() const { return __real__ _M_value; }
  921. __attribute ((__abi_tag__ ("cxx11")))
  922. constexpr float
  923. imag() const { return __imag__ _M_value; }
  924. #else
  925. float&
  926. real() { return __real__ _M_value; }
  927. const float&
  928. real() const { return __real__ _M_value; }
  929. float&
  930. imag() { return __imag__ _M_value; }
  931. const float&
  932. imag() const { return __imag__ _M_value; }
  933. #endif
  934. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  935. // DR 387. std::complex over-encapsulated.
  936. void
  937. real(float __val) { __real__ _M_value = __val; }
  938. void
  939. imag(float __val) { __imag__ _M_value = __val; }
  940. complex&
  941. operator=(float __f)
  942. {
  943. _M_value = __f;
  944. return *this;
  945. }
  946. complex&
  947. operator+=(float __f)
  948. {
  949. _M_value += __f;
  950. return *this;
  951. }
  952. complex&
  953. operator-=(float __f)
  954. {
  955. _M_value -= __f;
  956. return *this;
  957. }
  958. complex&
  959. operator*=(float __f)
  960. {
  961. _M_value *= __f;
  962. return *this;
  963. }
  964. complex&
  965. operator/=(float __f)
  966. {
  967. _M_value /= __f;
  968. return *this;
  969. }
  970. // Let the compiler synthesize the copy and assignment
  971. // operator. It always does a pretty good job.
  972. // complex& operator=(const complex&);
  973. template<typename _Tp>
  974. complex&
  975. operator=(const complex<_Tp>& __z)
  976. {
  977. __real__ _M_value = __z.real();
  978. __imag__ _M_value = __z.imag();
  979. return *this;
  980. }
  981. template<typename _Tp>
  982. complex&
  983. operator+=(const complex<_Tp>& __z)
  984. {
  985. __real__ _M_value += __z.real();
  986. __imag__ _M_value += __z.imag();
  987. return *this;
  988. }
  989. template<class _Tp>
  990. complex&
  991. operator-=(const complex<_Tp>& __z)
  992. {
  993. __real__ _M_value -= __z.real();
  994. __imag__ _M_value -= __z.imag();
  995. return *this;
  996. }
  997. template<class _Tp>
  998. complex&
  999. operator*=(const complex<_Tp>& __z)
  1000. {
  1001. _ComplexT __t;
  1002. __real__ __t = __z.real();
  1003. __imag__ __t = __z.imag();
  1004. _M_value *= __t;
  1005. return *this;
  1006. }
  1007. template<class _Tp>
  1008. complex&
  1009. operator/=(const complex<_Tp>& __z)
  1010. {
  1011. _ComplexT __t;
  1012. __real__ __t = __z.real();
  1013. __imag__ __t = __z.imag();
  1014. _M_value /= __t;
  1015. return *this;
  1016. }
  1017. _GLIBCXX_CONSTEXPR _ComplexT __rep() const { return _M_value; }
  1018. private:
  1019. _ComplexT _M_value;
  1020. };
  1021. /// 26.2.3 complex specializations
  1022. /// complex<double> specialization
  1023. template<>
  1024. struct complex<double>
  1025. {
  1026. typedef double value_type;
  1027. typedef __complex__ double _ComplexT;
  1028. _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
  1029. _GLIBCXX_CONSTEXPR complex(double __r = 0.0, double __i = 0.0)
  1030. #if __cplusplus >= 201103L
  1031. : _M_value{ __r, __i } { }
  1032. #else
  1033. {
  1034. __real__ _M_value = __r;
  1035. __imag__ _M_value = __i;
  1036. }
  1037. #endif
  1038. _GLIBCXX_CONSTEXPR complex(const complex<float>& __z)
  1039. : _M_value(__z.__rep()) { }
  1040. explicit _GLIBCXX_CONSTEXPR complex(const complex<long double>&);
  1041. #if __cplusplus >= 201103L
  1042. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1043. // DR 387. std::complex over-encapsulated.
  1044. __attribute ((__abi_tag__ ("cxx11")))
  1045. constexpr double
  1046. real() const { return __real__ _M_value; }
  1047. __attribute ((__abi_tag__ ("cxx11")))
  1048. constexpr double
  1049. imag() const { return __imag__ _M_value; }
  1050. #else
  1051. double&
  1052. real() { return __real__ _M_value; }
  1053. const double&
  1054. real() const { return __real__ _M_value; }
  1055. double&
  1056. imag() { return __imag__ _M_value; }
  1057. const double&
  1058. imag() const { return __imag__ _M_value; }
  1059. #endif
  1060. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1061. // DR 387. std::complex over-encapsulated.
  1062. void
  1063. real(double __val) { __real__ _M_value = __val; }
  1064. void
  1065. imag(double __val) { __imag__ _M_value = __val; }
  1066. complex&
  1067. operator=(double __d)
  1068. {
  1069. _M_value = __d;
  1070. return *this;
  1071. }
  1072. complex&
  1073. operator+=(double __d)
  1074. {
  1075. _M_value += __d;
  1076. return *this;
  1077. }
  1078. complex&
  1079. operator-=(double __d)
  1080. {
  1081. _M_value -= __d;
  1082. return *this;
  1083. }
  1084. complex&
  1085. operator*=(double __d)
  1086. {
  1087. _M_value *= __d;
  1088. return *this;
  1089. }
  1090. complex&
  1091. operator/=(double __d)
  1092. {
  1093. _M_value /= __d;
  1094. return *this;
  1095. }
  1096. // The compiler will synthesize this, efficiently.
  1097. // complex& operator=(const complex&);
  1098. template<typename _Tp>
  1099. complex&
  1100. operator=(const complex<_Tp>& __z)
  1101. {
  1102. __real__ _M_value = __z.real();
  1103. __imag__ _M_value = __z.imag();
  1104. return *this;
  1105. }
  1106. template<typename _Tp>
  1107. complex&
  1108. operator+=(const complex<_Tp>& __z)
  1109. {
  1110. __real__ _M_value += __z.real();
  1111. __imag__ _M_value += __z.imag();
  1112. return *this;
  1113. }
  1114. template<typename _Tp>
  1115. complex&
  1116. operator-=(const complex<_Tp>& __z)
  1117. {
  1118. __real__ _M_value -= __z.real();
  1119. __imag__ _M_value -= __z.imag();
  1120. return *this;
  1121. }
  1122. template<typename _Tp>
  1123. complex&
  1124. operator*=(const complex<_Tp>& __z)
  1125. {
  1126. _ComplexT __t;
  1127. __real__ __t = __z.real();
  1128. __imag__ __t = __z.imag();
  1129. _M_value *= __t;
  1130. return *this;
  1131. }
  1132. template<typename _Tp>
  1133. complex&
  1134. operator/=(const complex<_Tp>& __z)
  1135. {
  1136. _ComplexT __t;
  1137. __real__ __t = __z.real();
  1138. __imag__ __t = __z.imag();
  1139. _M_value /= __t;
  1140. return *this;
  1141. }
  1142. _GLIBCXX_CONSTEXPR _ComplexT __rep() const { return _M_value; }
  1143. private:
  1144. _ComplexT _M_value;
  1145. };
  1146. /// 26.2.3 complex specializations
  1147. /// complex<long double> specialization
  1148. template<>
  1149. struct complex<long double>
  1150. {
  1151. typedef long double value_type;
  1152. typedef __complex__ long double _ComplexT;
  1153. _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
  1154. _GLIBCXX_CONSTEXPR complex(long double __r = 0.0L,
  1155. long double __i = 0.0L)
  1156. #if __cplusplus >= 201103L
  1157. : _M_value{ __r, __i } { }
  1158. #else
  1159. {
  1160. __real__ _M_value = __r;
  1161. __imag__ _M_value = __i;
  1162. }
  1163. #endif
  1164. _GLIBCXX_CONSTEXPR complex(const complex<float>& __z)
  1165. : _M_value(__z.__rep()) { }
  1166. _GLIBCXX_CONSTEXPR complex(const complex<double>& __z)
  1167. : _M_value(__z.__rep()) { }
  1168. #if __cplusplus >= 201103L
  1169. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1170. // DR 387. std::complex over-encapsulated.
  1171. __attribute ((__abi_tag__ ("cxx11")))
  1172. constexpr long double
  1173. real() const { return __real__ _M_value; }
  1174. __attribute ((__abi_tag__ ("cxx11")))
  1175. constexpr long double
  1176. imag() const { return __imag__ _M_value; }
  1177. #else
  1178. long double&
  1179. real() { return __real__ _M_value; }
  1180. const long double&
  1181. real() const { return __real__ _M_value; }
  1182. long double&
  1183. imag() { return __imag__ _M_value; }
  1184. const long double&
  1185. imag() const { return __imag__ _M_value; }
  1186. #endif
  1187. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1188. // DR 387. std::complex over-encapsulated.
  1189. void
  1190. real(long double __val) { __real__ _M_value = __val; }
  1191. void
  1192. imag(long double __val) { __imag__ _M_value = __val; }
  1193. complex&
  1194. operator=(long double __r)
  1195. {
  1196. _M_value = __r;
  1197. return *this;
  1198. }
  1199. complex&
  1200. operator+=(long double __r)
  1201. {
  1202. _M_value += __r;
  1203. return *this;
  1204. }
  1205. complex&
  1206. operator-=(long double __r)
  1207. {
  1208. _M_value -= __r;
  1209. return *this;
  1210. }
  1211. complex&
  1212. operator*=(long double __r)
  1213. {
  1214. _M_value *= __r;
  1215. return *this;
  1216. }
  1217. complex&
  1218. operator/=(long double __r)
  1219. {
  1220. _M_value /= __r;
  1221. return *this;
  1222. }
  1223. // The compiler knows how to do this efficiently
  1224. // complex& operator=(const complex&);
  1225. template<typename _Tp>
  1226. complex&
  1227. operator=(const complex<_Tp>& __z)
  1228. {
  1229. __real__ _M_value = __z.real();
  1230. __imag__ _M_value = __z.imag();
  1231. return *this;
  1232. }
  1233. template<typename _Tp>
  1234. complex&
  1235. operator+=(const complex<_Tp>& __z)
  1236. {
  1237. __real__ _M_value += __z.real();
  1238. __imag__ _M_value += __z.imag();
  1239. return *this;
  1240. }
  1241. template<typename _Tp>
  1242. complex&
  1243. operator-=(const complex<_Tp>& __z)
  1244. {
  1245. __real__ _M_value -= __z.real();
  1246. __imag__ _M_value -= __z.imag();
  1247. return *this;
  1248. }
  1249. template<typename _Tp>
  1250. complex&
  1251. operator*=(const complex<_Tp>& __z)
  1252. {
  1253. _ComplexT __t;
  1254. __real__ __t = __z.real();
  1255. __imag__ __t = __z.imag();
  1256. _M_value *= __t;
  1257. return *this;
  1258. }
  1259. template<typename _Tp>
  1260. complex&
  1261. operator/=(const complex<_Tp>& __z)
  1262. {
  1263. _ComplexT __t;
  1264. __real__ __t = __z.real();
  1265. __imag__ __t = __z.imag();
  1266. _M_value /= __t;
  1267. return *this;
  1268. }
  1269. _GLIBCXX_CONSTEXPR _ComplexT __rep() const { return _M_value; }
  1270. private:
  1271. _ComplexT _M_value;
  1272. };
  1273. // These bits have to be at the end of this file, so that the
  1274. // specializations have all been defined.
  1275. inline _GLIBCXX_CONSTEXPR
  1276. complex<float>::complex(const complex<double>& __z)
  1277. : _M_value(__z.__rep()) { }
  1278. inline _GLIBCXX_CONSTEXPR
  1279. complex<float>::complex(const complex<long double>& __z)
  1280. : _M_value(__z.__rep()) { }
  1281. inline _GLIBCXX_CONSTEXPR
  1282. complex<double>::complex(const complex<long double>& __z)
  1283. : _M_value(__z.__rep()) { }
  1284. // Inhibit implicit instantiations for required instantiations,
  1285. // which are defined via explicit instantiations elsewhere.
  1286. // NB: This syntax is a GNU extension.
  1287. #if _GLIBCXX_EXTERN_TEMPLATE
  1288. extern template istream& operator>>(istream&, complex<float>&);
  1289. extern template ostream& operator<<(ostream&, const complex<float>&);
  1290. extern template istream& operator>>(istream&, complex<double>&);
  1291. extern template ostream& operator<<(ostream&, const complex<double>&);
  1292. extern template istream& operator>>(istream&, complex<long double>&);
  1293. extern template ostream& operator<<(ostream&, const complex<long double>&);
  1294. #ifdef _GLIBCXX_USE_WCHAR_T
  1295. extern template wistream& operator>>(wistream&, complex<float>&);
  1296. extern template wostream& operator<<(wostream&, const complex<float>&);
  1297. extern template wistream& operator>>(wistream&, complex<double>&);
  1298. extern template wostream& operator<<(wostream&, const complex<double>&);
  1299. extern template wistream& operator>>(wistream&, complex<long double>&);
  1300. extern template wostream& operator<<(wostream&, const complex<long double>&);
  1301. #endif
  1302. #endif
  1303. // @} group complex_numbers
  1304. _GLIBCXX_END_NAMESPACE_VERSION
  1305. } // namespace
  1306. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  1307. {
  1308. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  1309. // See ext/type_traits.h for the primary template.
  1310. template<typename _Tp, typename _Up>
  1311. struct __promote_2<std::complex<_Tp>, _Up>
  1312. {
  1313. public:
  1314. typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
  1315. };
  1316. template<typename _Tp, typename _Up>
  1317. struct __promote_2<_Tp, std::complex<_Up> >
  1318. {
  1319. public:
  1320. typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
  1321. };
  1322. template<typename _Tp, typename _Up>
  1323. struct __promote_2<std::complex<_Tp>, std::complex<_Up> >
  1324. {
  1325. public:
  1326. typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
  1327. };
  1328. _GLIBCXX_END_NAMESPACE_VERSION
  1329. } // namespace
  1330. #if __cplusplus >= 201103L
  1331. namespace std _GLIBCXX_VISIBILITY(default)
  1332. {
  1333. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  1334. // Forward declarations.
  1335. template<typename _Tp> std::complex<_Tp> acos(const std::complex<_Tp>&);
  1336. template<typename _Tp> std::complex<_Tp> asin(const std::complex<_Tp>&);
  1337. template<typename _Tp> std::complex<_Tp> atan(const std::complex<_Tp>&);
  1338. template<typename _Tp> std::complex<_Tp> acosh(const std::complex<_Tp>&);
  1339. template<typename _Tp> std::complex<_Tp> asinh(const std::complex<_Tp>&);
  1340. template<typename _Tp> std::complex<_Tp> atanh(const std::complex<_Tp>&);
  1341. // DR 595.
  1342. template<typename _Tp> _Tp fabs(const std::complex<_Tp>&);
  1343. template<typename _Tp>
  1344. inline std::complex<_Tp>
  1345. __complex_acos(const std::complex<_Tp>& __z)
  1346. {
  1347. const std::complex<_Tp> __t = std::asin(__z);
  1348. const _Tp __pi_2 = 1.5707963267948966192313216916397514L;
  1349. return std::complex<_Tp>(__pi_2 - __t.real(), -__t.imag());
  1350. }
  1351. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1352. inline __complex__ float
  1353. __complex_acos(__complex__ float __z)
  1354. { return __builtin_cacosf(__z); }
  1355. inline __complex__ double
  1356. __complex_acos(__complex__ double __z)
  1357. { return __builtin_cacos(__z); }
  1358. inline __complex__ long double
  1359. __complex_acos(const __complex__ long double& __z)
  1360. { return __builtin_cacosl(__z); }
  1361. template<typename _Tp>
  1362. inline std::complex<_Tp>
  1363. acos(const std::complex<_Tp>& __z)
  1364. { return __complex_acos(__z.__rep()); }
  1365. #else
  1366. /// acos(__z) [8.1.2].
  1367. // Effects: Behaves the same as C99 function cacos, defined
  1368. // in subclause 7.3.5.1.
  1369. template<typename _Tp>
  1370. inline std::complex<_Tp>
  1371. acos(const std::complex<_Tp>& __z)
  1372. { return __complex_acos(__z); }
  1373. #endif
  1374. template<typename _Tp>
  1375. inline std::complex<_Tp>
  1376. __complex_asin(const std::complex<_Tp>& __z)
  1377. {
  1378. std::complex<_Tp> __t(-__z.imag(), __z.real());
  1379. __t = std::asinh(__t);
  1380. return std::complex<_Tp>(__t.imag(), -__t.real());
  1381. }
  1382. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1383. inline __complex__ float
  1384. __complex_asin(__complex__ float __z)
  1385. { return __builtin_casinf(__z); }
  1386. inline __complex__ double
  1387. __complex_asin(__complex__ double __z)
  1388. { return __builtin_casin(__z); }
  1389. inline __complex__ long double
  1390. __complex_asin(const __complex__ long double& __z)
  1391. { return __builtin_casinl(__z); }
  1392. template<typename _Tp>
  1393. inline std::complex<_Tp>
  1394. asin(const std::complex<_Tp>& __z)
  1395. { return __complex_asin(__z.__rep()); }
  1396. #else
  1397. /// asin(__z) [8.1.3].
  1398. // Effects: Behaves the same as C99 function casin, defined
  1399. // in subclause 7.3.5.2.
  1400. template<typename _Tp>
  1401. inline std::complex<_Tp>
  1402. asin(const std::complex<_Tp>& __z)
  1403. { return __complex_asin(__z); }
  1404. #endif
  1405. template<typename _Tp>
  1406. std::complex<_Tp>
  1407. __complex_atan(const std::complex<_Tp>& __z)
  1408. {
  1409. const _Tp __r2 = __z.real() * __z.real();
  1410. const _Tp __x = _Tp(1.0) - __r2 - __z.imag() * __z.imag();
  1411. _Tp __num = __z.imag() + _Tp(1.0);
  1412. _Tp __den = __z.imag() - _Tp(1.0);
  1413. __num = __r2 + __num * __num;
  1414. __den = __r2 + __den * __den;
  1415. return std::complex<_Tp>(_Tp(0.5) * atan2(_Tp(2.0) * __z.real(), __x),
  1416. _Tp(0.25) * log(__num / __den));
  1417. }
  1418. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1419. inline __complex__ float
  1420. __complex_atan(__complex__ float __z)
  1421. { return __builtin_catanf(__z); }
  1422. inline __complex__ double
  1423. __complex_atan(__complex__ double __z)
  1424. { return __builtin_catan(__z); }
  1425. inline __complex__ long double
  1426. __complex_atan(const __complex__ long double& __z)
  1427. { return __builtin_catanl(__z); }
  1428. template<typename _Tp>
  1429. inline std::complex<_Tp>
  1430. atan(const std::complex<_Tp>& __z)
  1431. { return __complex_atan(__z.__rep()); }
  1432. #else
  1433. /// atan(__z) [8.1.4].
  1434. // Effects: Behaves the same as C99 function catan, defined
  1435. // in subclause 7.3.5.3.
  1436. template<typename _Tp>
  1437. inline std::complex<_Tp>
  1438. atan(const std::complex<_Tp>& __z)
  1439. { return __complex_atan(__z); }
  1440. #endif
  1441. template<typename _Tp>
  1442. std::complex<_Tp>
  1443. __complex_acosh(const std::complex<_Tp>& __z)
  1444. {
  1445. // Kahan's formula.
  1446. return _Tp(2.0) * std::log(std::sqrt(_Tp(0.5) * (__z + _Tp(1.0)))
  1447. + std::sqrt(_Tp(0.5) * (__z - _Tp(1.0))));
  1448. }
  1449. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1450. inline __complex__ float
  1451. __complex_acosh(__complex__ float __z)
  1452. { return __builtin_cacoshf(__z); }
  1453. inline __complex__ double
  1454. __complex_acosh(__complex__ double __z)
  1455. { return __builtin_cacosh(__z); }
  1456. inline __complex__ long double
  1457. __complex_acosh(const __complex__ long double& __z)
  1458. { return __builtin_cacoshl(__z); }
  1459. template<typename _Tp>
  1460. inline std::complex<_Tp>
  1461. acosh(const std::complex<_Tp>& __z)
  1462. { return __complex_acosh(__z.__rep()); }
  1463. #else
  1464. /// acosh(__z) [8.1.5].
  1465. // Effects: Behaves the same as C99 function cacosh, defined
  1466. // in subclause 7.3.6.1.
  1467. template<typename _Tp>
  1468. inline std::complex<_Tp>
  1469. acosh(const std::complex<_Tp>& __z)
  1470. { return __complex_acosh(__z); }
  1471. #endif
  1472. template<typename _Tp>
  1473. std::complex<_Tp>
  1474. __complex_asinh(const std::complex<_Tp>& __z)
  1475. {
  1476. std::complex<_Tp> __t((__z.real() - __z.imag())
  1477. * (__z.real() + __z.imag()) + _Tp(1.0),
  1478. _Tp(2.0) * __z.real() * __z.imag());
  1479. __t = std::sqrt(__t);
  1480. return std::log(__t + __z);
  1481. }
  1482. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1483. inline __complex__ float
  1484. __complex_asinh(__complex__ float __z)
  1485. { return __builtin_casinhf(__z); }
  1486. inline __complex__ double
  1487. __complex_asinh(__complex__ double __z)
  1488. { return __builtin_casinh(__z); }
  1489. inline __complex__ long double
  1490. __complex_asinh(const __complex__ long double& __z)
  1491. { return __builtin_casinhl(__z); }
  1492. template<typename _Tp>
  1493. inline std::complex<_Tp>
  1494. asinh(const std::complex<_Tp>& __z)
  1495. { return __complex_asinh(__z.__rep()); }
  1496. #else
  1497. /// asinh(__z) [8.1.6].
  1498. // Effects: Behaves the same as C99 function casin, defined
  1499. // in subclause 7.3.6.2.
  1500. template<typename _Tp>
  1501. inline std::complex<_Tp>
  1502. asinh(const std::complex<_Tp>& __z)
  1503. { return __complex_asinh(__z); }
  1504. #endif
  1505. template<typename _Tp>
  1506. std::complex<_Tp>
  1507. __complex_atanh(const std::complex<_Tp>& __z)
  1508. {
  1509. const _Tp __i2 = __z.imag() * __z.imag();
  1510. const _Tp __x = _Tp(1.0) - __i2 - __z.real() * __z.real();
  1511. _Tp __num = _Tp(1.0) + __z.real();
  1512. _Tp __den = _Tp(1.0) - __z.real();
  1513. __num = __i2 + __num * __num;
  1514. __den = __i2 + __den * __den;
  1515. return std::complex<_Tp>(_Tp(0.25) * (log(__num) - log(__den)),
  1516. _Tp(0.5) * atan2(_Tp(2.0) * __z.imag(), __x));
  1517. }
  1518. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1519. inline __complex__ float
  1520. __complex_atanh(__complex__ float __z)
  1521. { return __builtin_catanhf(__z); }
  1522. inline __complex__ double
  1523. __complex_atanh(__complex__ double __z)
  1524. { return __builtin_catanh(__z); }
  1525. inline __complex__ long double
  1526. __complex_atanh(const __complex__ long double& __z)
  1527. { return __builtin_catanhl(__z); }
  1528. template<typename _Tp>
  1529. inline std::complex<_Tp>
  1530. atanh(const std::complex<_Tp>& __z)
  1531. { return __complex_atanh(__z.__rep()); }
  1532. #else
  1533. /// atanh(__z) [8.1.7].
  1534. // Effects: Behaves the same as C99 function catanh, defined
  1535. // in subclause 7.3.6.3.
  1536. template<typename _Tp>
  1537. inline std::complex<_Tp>
  1538. atanh(const std::complex<_Tp>& __z)
  1539. { return __complex_atanh(__z); }
  1540. #endif
  1541. template<typename _Tp>
  1542. inline _Tp
  1543. /// fabs(__z) [8.1.8].
  1544. // Effects: Behaves the same as C99 function cabs, defined
  1545. // in subclause 7.3.8.1.
  1546. fabs(const std::complex<_Tp>& __z)
  1547. { return std::abs(__z); }
  1548. /// Additional overloads [8.1.9].
  1549. template<typename _Tp>
  1550. inline typename __gnu_cxx::__promote<_Tp>::__type
  1551. arg(_Tp __x)
  1552. {
  1553. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  1554. #if (_GLIBCXX11_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC)
  1555. return std::signbit(__x) ? __type(3.1415926535897932384626433832795029L)
  1556. : __type();
  1557. #else
  1558. return std::arg(std::complex<__type>(__x));
  1559. #endif
  1560. }
  1561. template<typename _Tp>
  1562. inline typename __gnu_cxx::__promote<_Tp>::__type
  1563. imag(_Tp)
  1564. { return _Tp(); }
  1565. template<typename _Tp>
  1566. inline typename __gnu_cxx::__promote<_Tp>::__type
  1567. norm(_Tp __x)
  1568. {
  1569. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  1570. return __type(__x) * __type(__x);
  1571. }
  1572. template<typename _Tp>
  1573. inline typename __gnu_cxx::__promote<_Tp>::__type
  1574. real(_Tp __x)
  1575. { return __x; }
  1576. template<typename _Tp, typename _Up>
  1577. inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type>
  1578. pow(const std::complex<_Tp>& __x, const _Up& __y)
  1579. {
  1580. typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
  1581. return std::pow(std::complex<__type>(__x), __type(__y));
  1582. }
  1583. template<typename _Tp, typename _Up>
  1584. inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type>
  1585. pow(const _Tp& __x, const std::complex<_Up>& __y)
  1586. {
  1587. typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
  1588. return std::pow(__type(__x), std::complex<__type>(__y));
  1589. }
  1590. template<typename _Tp, typename _Up>
  1591. inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type>
  1592. pow(const std::complex<_Tp>& __x, const std::complex<_Up>& __y)
  1593. {
  1594. typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
  1595. return std::pow(std::complex<__type>(__x),
  1596. std::complex<__type>(__y));
  1597. }
  1598. // Forward declarations.
  1599. // DR 781.
  1600. template<typename _Tp> std::complex<_Tp> proj(const std::complex<_Tp>&);
  1601. template<typename _Tp>
  1602. std::complex<_Tp>
  1603. __complex_proj(const std::complex<_Tp>& __z)
  1604. {
  1605. const _Tp __den = (__z.real() * __z.real()
  1606. + __z.imag() * __z.imag() + _Tp(1.0));
  1607. return std::complex<_Tp>((_Tp(2.0) * __z.real()) / __den,
  1608. (_Tp(2.0) * __z.imag()) / __den);
  1609. }
  1610. #if _GLIBCXX_USE_C99_COMPLEX
  1611. inline __complex__ float
  1612. __complex_proj(__complex__ float __z)
  1613. { return __builtin_cprojf(__z); }
  1614. inline __complex__ double
  1615. __complex_proj(__complex__ double __z)
  1616. { return __builtin_cproj(__z); }
  1617. inline __complex__ long double
  1618. __complex_proj(const __complex__ long double& __z)
  1619. { return __builtin_cprojl(__z); }
  1620. template<typename _Tp>
  1621. inline std::complex<_Tp>
  1622. proj(const std::complex<_Tp>& __z)
  1623. { return __complex_proj(__z.__rep()); }
  1624. #else
  1625. template<typename _Tp>
  1626. inline std::complex<_Tp>
  1627. proj(const std::complex<_Tp>& __z)
  1628. { return __complex_proj(__z); }
  1629. #endif
  1630. // DR 1137.
  1631. template<typename _Tp>
  1632. inline typename __gnu_cxx::__promote<_Tp>::__type
  1633. proj(_Tp __x)
  1634. { return __x; }
  1635. template<typename _Tp>
  1636. inline typename __gnu_cxx::__promote<_Tp>::__type
  1637. conj(_Tp __x)
  1638. { return __x; }
  1639. _GLIBCXX_END_NAMESPACE_VERSION
  1640. #if __cplusplus > 201103L
  1641. inline namespace literals {
  1642. inline namespace complex_literals {
  1643. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  1644. #define __cpp_lib_complex_udls 201309
  1645. constexpr std::complex<float>
  1646. operator""if(long double __num)
  1647. { return std::complex<float>{0.0F, static_cast<float>(__num)}; }
  1648. constexpr std::complex<float>
  1649. operator""if(unsigned long long __num)
  1650. { return std::complex<float>{0.0F, static_cast<float>(__num)}; }
  1651. constexpr std::complex<double>
  1652. operator""i(long double __num)
  1653. { return std::complex<double>{0.0, static_cast<double>(__num)}; }
  1654. constexpr std::complex<double>
  1655. operator""i(unsigned long long __num)
  1656. { return std::complex<double>{0.0, static_cast<double>(__num)}; }
  1657. constexpr std::complex<long double>
  1658. operator""il(long double __num)
  1659. { return std::complex<long double>{0.0L, __num}; }
  1660. constexpr std::complex<long double>
  1661. operator""il(unsigned long long __num)
  1662. { return std::complex<long double>{0.0L, static_cast<long double>(__num)}; }
  1663. _GLIBCXX_END_NAMESPACE_VERSION
  1664. } // inline namespace complex_literals
  1665. } // inline namespace literals
  1666. #endif // C++14
  1667. } // namespace
  1668. #endif // C++11
  1669. #endif /* _GLIBCXX_COMPLEX */