complex 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973
  1. // The template and inlines for the -*- C++ -*- complex number classes.
  2. // Copyright (C) 1997-2015 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. { return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); }
  585. template<typename _Tp>
  586. inline complex<_Tp>
  587. conj(const complex<_Tp>& __z)
  588. { return complex<_Tp>(__z.real(), -__z.imag()); }
  589. // Transcendentals
  590. // 26.2.8/1 cos(__z): Returns the cosine of __z.
  591. template<typename _Tp>
  592. inline complex<_Tp>
  593. __complex_cos(const complex<_Tp>& __z)
  594. {
  595. const _Tp __x = __z.real();
  596. const _Tp __y = __z.imag();
  597. return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y));
  598. }
  599. #if _GLIBCXX_USE_C99_COMPLEX
  600. inline __complex__ float
  601. __complex_cos(__complex__ float __z) { return __builtin_ccosf(__z); }
  602. inline __complex__ double
  603. __complex_cos(__complex__ double __z) { return __builtin_ccos(__z); }
  604. inline __complex__ long double
  605. __complex_cos(const __complex__ long double& __z)
  606. { return __builtin_ccosl(__z); }
  607. template<typename _Tp>
  608. inline complex<_Tp>
  609. cos(const complex<_Tp>& __z) { return __complex_cos(__z.__rep()); }
  610. #else
  611. template<typename _Tp>
  612. inline complex<_Tp>
  613. cos(const complex<_Tp>& __z) { return __complex_cos(__z); }
  614. #endif
  615. // 26.2.8/2 cosh(__z): Returns the hyperbolic cosine of __z.
  616. template<typename _Tp>
  617. inline complex<_Tp>
  618. __complex_cosh(const complex<_Tp>& __z)
  619. {
  620. const _Tp __x = __z.real();
  621. const _Tp __y = __z.imag();
  622. return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y));
  623. }
  624. #if _GLIBCXX_USE_C99_COMPLEX
  625. inline __complex__ float
  626. __complex_cosh(__complex__ float __z) { return __builtin_ccoshf(__z); }
  627. inline __complex__ double
  628. __complex_cosh(__complex__ double __z) { return __builtin_ccosh(__z); }
  629. inline __complex__ long double
  630. __complex_cosh(const __complex__ long double& __z)
  631. { return __builtin_ccoshl(__z); }
  632. template<typename _Tp>
  633. inline complex<_Tp>
  634. cosh(const complex<_Tp>& __z) { return __complex_cosh(__z.__rep()); }
  635. #else
  636. template<typename _Tp>
  637. inline complex<_Tp>
  638. cosh(const complex<_Tp>& __z) { return __complex_cosh(__z); }
  639. #endif
  640. // 26.2.8/3 exp(__z): Returns the complex base e exponential of x
  641. template<typename _Tp>
  642. inline complex<_Tp>
  643. __complex_exp(const complex<_Tp>& __z)
  644. { return std::polar<_Tp>(exp(__z.real()), __z.imag()); }
  645. #if _GLIBCXX_USE_C99_COMPLEX
  646. inline __complex__ float
  647. __complex_exp(__complex__ float __z) { return __builtin_cexpf(__z); }
  648. inline __complex__ double
  649. __complex_exp(__complex__ double __z) { return __builtin_cexp(__z); }
  650. inline __complex__ long double
  651. __complex_exp(const __complex__ long double& __z)
  652. { return __builtin_cexpl(__z); }
  653. template<typename _Tp>
  654. inline complex<_Tp>
  655. exp(const complex<_Tp>& __z) { return __complex_exp(__z.__rep()); }
  656. #else
  657. template<typename _Tp>
  658. inline complex<_Tp>
  659. exp(const complex<_Tp>& __z) { return __complex_exp(__z); }
  660. #endif
  661. // 26.2.8/5 log(__z): Returns the natural complex logarithm of __z.
  662. // The branch cut is along the negative axis.
  663. template<typename _Tp>
  664. inline complex<_Tp>
  665. __complex_log(const complex<_Tp>& __z)
  666. { return complex<_Tp>(log(std::abs(__z)), std::arg(__z)); }
  667. #if _GLIBCXX_USE_C99_COMPLEX
  668. inline __complex__ float
  669. __complex_log(__complex__ float __z) { return __builtin_clogf(__z); }
  670. inline __complex__ double
  671. __complex_log(__complex__ double __z) { return __builtin_clog(__z); }
  672. inline __complex__ long double
  673. __complex_log(const __complex__ long double& __z)
  674. { return __builtin_clogl(__z); }
  675. template<typename _Tp>
  676. inline complex<_Tp>
  677. log(const complex<_Tp>& __z) { return __complex_log(__z.__rep()); }
  678. #else
  679. template<typename _Tp>
  680. inline complex<_Tp>
  681. log(const complex<_Tp>& __z) { return __complex_log(__z); }
  682. #endif
  683. template<typename _Tp>
  684. inline complex<_Tp>
  685. log10(const complex<_Tp>& __z)
  686. { return std::log(__z) / log(_Tp(10.0)); }
  687. // 26.2.8/10 sin(__z): Returns the sine of __z.
  688. template<typename _Tp>
  689. inline complex<_Tp>
  690. __complex_sin(const complex<_Tp>& __z)
  691. {
  692. const _Tp __x = __z.real();
  693. const _Tp __y = __z.imag();
  694. return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y));
  695. }
  696. #if _GLIBCXX_USE_C99_COMPLEX
  697. inline __complex__ float
  698. __complex_sin(__complex__ float __z) { return __builtin_csinf(__z); }
  699. inline __complex__ double
  700. __complex_sin(__complex__ double __z) { return __builtin_csin(__z); }
  701. inline __complex__ long double
  702. __complex_sin(const __complex__ long double& __z)
  703. { return __builtin_csinl(__z); }
  704. template<typename _Tp>
  705. inline complex<_Tp>
  706. sin(const complex<_Tp>& __z) { return __complex_sin(__z.__rep()); }
  707. #else
  708. template<typename _Tp>
  709. inline complex<_Tp>
  710. sin(const complex<_Tp>& __z) { return __complex_sin(__z); }
  711. #endif
  712. // 26.2.8/11 sinh(__z): Returns the hyperbolic sine of __z.
  713. template<typename _Tp>
  714. inline complex<_Tp>
  715. __complex_sinh(const complex<_Tp>& __z)
  716. {
  717. const _Tp __x = __z.real();
  718. const _Tp __y = __z.imag();
  719. return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y));
  720. }
  721. #if _GLIBCXX_USE_C99_COMPLEX
  722. inline __complex__ float
  723. __complex_sinh(__complex__ float __z) { return __builtin_csinhf(__z); }
  724. inline __complex__ double
  725. __complex_sinh(__complex__ double __z) { return __builtin_csinh(__z); }
  726. inline __complex__ long double
  727. __complex_sinh(const __complex__ long double& __z)
  728. { return __builtin_csinhl(__z); }
  729. template<typename _Tp>
  730. inline complex<_Tp>
  731. sinh(const complex<_Tp>& __z) { return __complex_sinh(__z.__rep()); }
  732. #else
  733. template<typename _Tp>
  734. inline complex<_Tp>
  735. sinh(const complex<_Tp>& __z) { return __complex_sinh(__z); }
  736. #endif
  737. // 26.2.8/13 sqrt(__z): Returns the complex square root of __z.
  738. // The branch cut is on the negative axis.
  739. template<typename _Tp>
  740. complex<_Tp>
  741. __complex_sqrt(const complex<_Tp>& __z)
  742. {
  743. _Tp __x = __z.real();
  744. _Tp __y = __z.imag();
  745. if (__x == _Tp())
  746. {
  747. _Tp __t = sqrt(abs(__y) / 2);
  748. return complex<_Tp>(__t, __y < _Tp() ? -__t : __t);
  749. }
  750. else
  751. {
  752. _Tp __t = sqrt(2 * (std::abs(__z) + abs(__x)));
  753. _Tp __u = __t / 2;
  754. return __x > _Tp()
  755. ? complex<_Tp>(__u, __y / __t)
  756. : complex<_Tp>(abs(__y) / __t, __y < _Tp() ? -__u : __u);
  757. }
  758. }
  759. #if _GLIBCXX_USE_C99_COMPLEX
  760. inline __complex__ float
  761. __complex_sqrt(__complex__ float __z) { return __builtin_csqrtf(__z); }
  762. inline __complex__ double
  763. __complex_sqrt(__complex__ double __z) { return __builtin_csqrt(__z); }
  764. inline __complex__ long double
  765. __complex_sqrt(const __complex__ long double& __z)
  766. { return __builtin_csqrtl(__z); }
  767. template<typename _Tp>
  768. inline complex<_Tp>
  769. sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z.__rep()); }
  770. #else
  771. template<typename _Tp>
  772. inline complex<_Tp>
  773. sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z); }
  774. #endif
  775. // 26.2.8/14 tan(__z): Return the complex tangent of __z.
  776. template<typename _Tp>
  777. inline complex<_Tp>
  778. __complex_tan(const complex<_Tp>& __z)
  779. { return std::sin(__z) / std::cos(__z); }
  780. #if _GLIBCXX_USE_C99_COMPLEX
  781. inline __complex__ float
  782. __complex_tan(__complex__ float __z) { return __builtin_ctanf(__z); }
  783. inline __complex__ double
  784. __complex_tan(__complex__ double __z) { return __builtin_ctan(__z); }
  785. inline __complex__ long double
  786. __complex_tan(const __complex__ long double& __z)
  787. { return __builtin_ctanl(__z); }
  788. template<typename _Tp>
  789. inline complex<_Tp>
  790. tan(const complex<_Tp>& __z) { return __complex_tan(__z.__rep()); }
  791. #else
  792. template<typename _Tp>
  793. inline complex<_Tp>
  794. tan(const complex<_Tp>& __z) { return __complex_tan(__z); }
  795. #endif
  796. // 26.2.8/15 tanh(__z): Returns the hyperbolic tangent of __z.
  797. template<typename _Tp>
  798. inline complex<_Tp>
  799. __complex_tanh(const complex<_Tp>& __z)
  800. { return std::sinh(__z) / std::cosh(__z); }
  801. #if _GLIBCXX_USE_C99_COMPLEX
  802. inline __complex__ float
  803. __complex_tanh(__complex__ float __z) { return __builtin_ctanhf(__z); }
  804. inline __complex__ double
  805. __complex_tanh(__complex__ double __z) { return __builtin_ctanh(__z); }
  806. inline __complex__ long double
  807. __complex_tanh(const __complex__ long double& __z)
  808. { return __builtin_ctanhl(__z); }
  809. template<typename _Tp>
  810. inline complex<_Tp>
  811. tanh(const complex<_Tp>& __z) { return __complex_tanh(__z.__rep()); }
  812. #else
  813. template<typename _Tp>
  814. inline complex<_Tp>
  815. tanh(const complex<_Tp>& __z) { return __complex_tanh(__z); }
  816. #endif
  817. // 26.2.8/9 pow(__x, __y): Returns the complex power base of __x
  818. // raised to the __y-th power. The branch
  819. // cut is on the negative axis.
  820. template<typename _Tp>
  821. complex<_Tp>
  822. __complex_pow_unsigned(complex<_Tp> __x, unsigned __n)
  823. {
  824. complex<_Tp> __y = __n % 2 ? __x : complex<_Tp>(1);
  825. while (__n >>= 1)
  826. {
  827. __x *= __x;
  828. if (__n % 2)
  829. __y *= __x;
  830. }
  831. return __y;
  832. }
  833. // In C++11 mode we used to implement the resolution of
  834. // DR 844. complex pow return type is ambiguous.
  835. // thus the following overload was disabled in that mode. However, doing
  836. // that causes all sorts of issues, see, for example:
  837. // http://gcc.gnu.org/ml/libstdc++/2013-01/msg00058.html
  838. // and also PR57974.
  839. template<typename _Tp>
  840. inline complex<_Tp>
  841. pow(const complex<_Tp>& __z, int __n)
  842. {
  843. return __n < 0
  844. ? complex<_Tp>(1) / std::__complex_pow_unsigned(__z, -(unsigned)__n)
  845. : std::__complex_pow_unsigned(__z, __n);
  846. }
  847. template<typename _Tp>
  848. complex<_Tp>
  849. pow(const complex<_Tp>& __x, const _Tp& __y)
  850. {
  851. #ifndef _GLIBCXX_USE_C99_COMPLEX
  852. if (__x == _Tp())
  853. return _Tp();
  854. #endif
  855. if (__x.imag() == _Tp() && __x.real() > _Tp())
  856. return pow(__x.real(), __y);
  857. complex<_Tp> __t = std::log(__x);
  858. return std::polar<_Tp>(exp(__y * __t.real()), __y * __t.imag());
  859. }
  860. template<typename _Tp>
  861. inline complex<_Tp>
  862. __complex_pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
  863. { return __x == _Tp() ? _Tp() : std::exp(__y * std::log(__x)); }
  864. #if _GLIBCXX_USE_C99_COMPLEX
  865. inline __complex__ float
  866. __complex_pow(__complex__ float __x, __complex__ float __y)
  867. { return __builtin_cpowf(__x, __y); }
  868. inline __complex__ double
  869. __complex_pow(__complex__ double __x, __complex__ double __y)
  870. { return __builtin_cpow(__x, __y); }
  871. inline __complex__ long double
  872. __complex_pow(const __complex__ long double& __x,
  873. const __complex__ long double& __y)
  874. { return __builtin_cpowl(__x, __y); }
  875. template<typename _Tp>
  876. inline complex<_Tp>
  877. pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
  878. { return __complex_pow(__x.__rep(), __y.__rep()); }
  879. #else
  880. template<typename _Tp>
  881. inline complex<_Tp>
  882. pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
  883. { return __complex_pow(__x, __y); }
  884. #endif
  885. template<typename _Tp>
  886. inline complex<_Tp>
  887. pow(const _Tp& __x, const complex<_Tp>& __y)
  888. {
  889. return __x > _Tp() ? std::polar<_Tp>(pow(__x, __y.real()),
  890. __y.imag() * log(__x))
  891. : std::pow(complex<_Tp>(__x), __y);
  892. }
  893. /// 26.2.3 complex specializations
  894. /// complex<float> specialization
  895. template<>
  896. struct complex<float>
  897. {
  898. typedef float value_type;
  899. typedef __complex__ float _ComplexT;
  900. _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
  901. _GLIBCXX_CONSTEXPR complex(float __r = 0.0f, float __i = 0.0f)
  902. #if __cplusplus >= 201103L
  903. : _M_value{ __r, __i } { }
  904. #else
  905. {
  906. __real__ _M_value = __r;
  907. __imag__ _M_value = __i;
  908. }
  909. #endif
  910. explicit _GLIBCXX_CONSTEXPR complex(const complex<double>&);
  911. explicit _GLIBCXX_CONSTEXPR complex(const complex<long double>&);
  912. #if __cplusplus >= 201103L
  913. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  914. // DR 387. std::complex over-encapsulated.
  915. __attribute ((__abi_tag__ ("cxx11")))
  916. constexpr float
  917. real() const { return __real__ _M_value; }
  918. __attribute ((__abi_tag__ ("cxx11")))
  919. constexpr float
  920. imag() const { return __imag__ _M_value; }
  921. #else
  922. float&
  923. real() { return __real__ _M_value; }
  924. const float&
  925. real() const { return __real__ _M_value; }
  926. float&
  927. imag() { return __imag__ _M_value; }
  928. const float&
  929. imag() const { return __imag__ _M_value; }
  930. #endif
  931. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  932. // DR 387. std::complex over-encapsulated.
  933. void
  934. real(float __val) { __real__ _M_value = __val; }
  935. void
  936. imag(float __val) { __imag__ _M_value = __val; }
  937. complex&
  938. operator=(float __f)
  939. {
  940. _M_value = __f;
  941. return *this;
  942. }
  943. complex&
  944. operator+=(float __f)
  945. {
  946. _M_value += __f;
  947. return *this;
  948. }
  949. complex&
  950. operator-=(float __f)
  951. {
  952. _M_value -= __f;
  953. return *this;
  954. }
  955. complex&
  956. operator*=(float __f)
  957. {
  958. _M_value *= __f;
  959. return *this;
  960. }
  961. complex&
  962. operator/=(float __f)
  963. {
  964. _M_value /= __f;
  965. return *this;
  966. }
  967. // Let the compiler synthesize the copy and assignment
  968. // operator. It always does a pretty good job.
  969. // complex& operator=(const complex&);
  970. template<typename _Tp>
  971. complex&
  972. operator=(const complex<_Tp>& __z)
  973. {
  974. __real__ _M_value = __z.real();
  975. __imag__ _M_value = __z.imag();
  976. return *this;
  977. }
  978. template<typename _Tp>
  979. complex&
  980. operator+=(const complex<_Tp>& __z)
  981. {
  982. __real__ _M_value += __z.real();
  983. __imag__ _M_value += __z.imag();
  984. return *this;
  985. }
  986. template<class _Tp>
  987. complex&
  988. operator-=(const complex<_Tp>& __z)
  989. {
  990. __real__ _M_value -= __z.real();
  991. __imag__ _M_value -= __z.imag();
  992. return *this;
  993. }
  994. template<class _Tp>
  995. complex&
  996. operator*=(const complex<_Tp>& __z)
  997. {
  998. _ComplexT __t;
  999. __real__ __t = __z.real();
  1000. __imag__ __t = __z.imag();
  1001. _M_value *= __t;
  1002. return *this;
  1003. }
  1004. template<class _Tp>
  1005. complex&
  1006. operator/=(const complex<_Tp>& __z)
  1007. {
  1008. _ComplexT __t;
  1009. __real__ __t = __z.real();
  1010. __imag__ __t = __z.imag();
  1011. _M_value /= __t;
  1012. return *this;
  1013. }
  1014. _GLIBCXX_CONSTEXPR _ComplexT __rep() const { return _M_value; }
  1015. private:
  1016. _ComplexT _M_value;
  1017. };
  1018. /// 26.2.3 complex specializations
  1019. /// complex<double> specialization
  1020. template<>
  1021. struct complex<double>
  1022. {
  1023. typedef double value_type;
  1024. typedef __complex__ double _ComplexT;
  1025. _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
  1026. _GLIBCXX_CONSTEXPR complex(double __r = 0.0, double __i = 0.0)
  1027. #if __cplusplus >= 201103L
  1028. : _M_value{ __r, __i } { }
  1029. #else
  1030. {
  1031. __real__ _M_value = __r;
  1032. __imag__ _M_value = __i;
  1033. }
  1034. #endif
  1035. _GLIBCXX_CONSTEXPR complex(const complex<float>& __z)
  1036. : _M_value(__z.__rep()) { }
  1037. explicit _GLIBCXX_CONSTEXPR complex(const complex<long double>&);
  1038. #if __cplusplus >= 201103L
  1039. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1040. // DR 387. std::complex over-encapsulated.
  1041. __attribute ((__abi_tag__ ("cxx11")))
  1042. constexpr double
  1043. real() const { return __real__ _M_value; }
  1044. __attribute ((__abi_tag__ ("cxx11")))
  1045. constexpr double
  1046. imag() const { return __imag__ _M_value; }
  1047. #else
  1048. double&
  1049. real() { return __real__ _M_value; }
  1050. const double&
  1051. real() const { return __real__ _M_value; }
  1052. double&
  1053. imag() { return __imag__ _M_value; }
  1054. const double&
  1055. imag() const { return __imag__ _M_value; }
  1056. #endif
  1057. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1058. // DR 387. std::complex over-encapsulated.
  1059. void
  1060. real(double __val) { __real__ _M_value = __val; }
  1061. void
  1062. imag(double __val) { __imag__ _M_value = __val; }
  1063. complex&
  1064. operator=(double __d)
  1065. {
  1066. _M_value = __d;
  1067. return *this;
  1068. }
  1069. complex&
  1070. operator+=(double __d)
  1071. {
  1072. _M_value += __d;
  1073. return *this;
  1074. }
  1075. complex&
  1076. operator-=(double __d)
  1077. {
  1078. _M_value -= __d;
  1079. return *this;
  1080. }
  1081. complex&
  1082. operator*=(double __d)
  1083. {
  1084. _M_value *= __d;
  1085. return *this;
  1086. }
  1087. complex&
  1088. operator/=(double __d)
  1089. {
  1090. _M_value /= __d;
  1091. return *this;
  1092. }
  1093. // The compiler will synthesize this, efficiently.
  1094. // complex& operator=(const complex&);
  1095. template<typename _Tp>
  1096. complex&
  1097. operator=(const complex<_Tp>& __z)
  1098. {
  1099. __real__ _M_value = __z.real();
  1100. __imag__ _M_value = __z.imag();
  1101. return *this;
  1102. }
  1103. template<typename _Tp>
  1104. complex&
  1105. operator+=(const complex<_Tp>& __z)
  1106. {
  1107. __real__ _M_value += __z.real();
  1108. __imag__ _M_value += __z.imag();
  1109. return *this;
  1110. }
  1111. template<typename _Tp>
  1112. complex&
  1113. operator-=(const complex<_Tp>& __z)
  1114. {
  1115. __real__ _M_value -= __z.real();
  1116. __imag__ _M_value -= __z.imag();
  1117. return *this;
  1118. }
  1119. template<typename _Tp>
  1120. complex&
  1121. operator*=(const complex<_Tp>& __z)
  1122. {
  1123. _ComplexT __t;
  1124. __real__ __t = __z.real();
  1125. __imag__ __t = __z.imag();
  1126. _M_value *= __t;
  1127. return *this;
  1128. }
  1129. template<typename _Tp>
  1130. complex&
  1131. operator/=(const complex<_Tp>& __z)
  1132. {
  1133. _ComplexT __t;
  1134. __real__ __t = __z.real();
  1135. __imag__ __t = __z.imag();
  1136. _M_value /= __t;
  1137. return *this;
  1138. }
  1139. _GLIBCXX_CONSTEXPR _ComplexT __rep() const { return _M_value; }
  1140. private:
  1141. _ComplexT _M_value;
  1142. };
  1143. /// 26.2.3 complex specializations
  1144. /// complex<long double> specialization
  1145. template<>
  1146. struct complex<long double>
  1147. {
  1148. typedef long double value_type;
  1149. typedef __complex__ long double _ComplexT;
  1150. _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
  1151. _GLIBCXX_CONSTEXPR complex(long double __r = 0.0L,
  1152. long double __i = 0.0L)
  1153. #if __cplusplus >= 201103L
  1154. : _M_value{ __r, __i } { }
  1155. #else
  1156. {
  1157. __real__ _M_value = __r;
  1158. __imag__ _M_value = __i;
  1159. }
  1160. #endif
  1161. _GLIBCXX_CONSTEXPR complex(const complex<float>& __z)
  1162. : _M_value(__z.__rep()) { }
  1163. _GLIBCXX_CONSTEXPR complex(const complex<double>& __z)
  1164. : _M_value(__z.__rep()) { }
  1165. #if __cplusplus >= 201103L
  1166. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1167. // DR 387. std::complex over-encapsulated.
  1168. __attribute ((__abi_tag__ ("cxx11")))
  1169. constexpr long double
  1170. real() const { return __real__ _M_value; }
  1171. __attribute ((__abi_tag__ ("cxx11")))
  1172. constexpr long double
  1173. imag() const { return __imag__ _M_value; }
  1174. #else
  1175. long double&
  1176. real() { return __real__ _M_value; }
  1177. const long double&
  1178. real() const { return __real__ _M_value; }
  1179. long double&
  1180. imag() { return __imag__ _M_value; }
  1181. const long double&
  1182. imag() const { return __imag__ _M_value; }
  1183. #endif
  1184. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1185. // DR 387. std::complex over-encapsulated.
  1186. void
  1187. real(long double __val) { __real__ _M_value = __val; }
  1188. void
  1189. imag(long double __val) { __imag__ _M_value = __val; }
  1190. complex&
  1191. operator=(long double __r)
  1192. {
  1193. _M_value = __r;
  1194. return *this;
  1195. }
  1196. complex&
  1197. operator+=(long double __r)
  1198. {
  1199. _M_value += __r;
  1200. return *this;
  1201. }
  1202. complex&
  1203. operator-=(long double __r)
  1204. {
  1205. _M_value -= __r;
  1206. return *this;
  1207. }
  1208. complex&
  1209. operator*=(long double __r)
  1210. {
  1211. _M_value *= __r;
  1212. return *this;
  1213. }
  1214. complex&
  1215. operator/=(long double __r)
  1216. {
  1217. _M_value /= __r;
  1218. return *this;
  1219. }
  1220. // The compiler knows how to do this efficiently
  1221. // complex& operator=(const complex&);
  1222. template<typename _Tp>
  1223. complex&
  1224. operator=(const complex<_Tp>& __z)
  1225. {
  1226. __real__ _M_value = __z.real();
  1227. __imag__ _M_value = __z.imag();
  1228. return *this;
  1229. }
  1230. template<typename _Tp>
  1231. complex&
  1232. operator+=(const complex<_Tp>& __z)
  1233. {
  1234. __real__ _M_value += __z.real();
  1235. __imag__ _M_value += __z.imag();
  1236. return *this;
  1237. }
  1238. template<typename _Tp>
  1239. complex&
  1240. operator-=(const complex<_Tp>& __z)
  1241. {
  1242. __real__ _M_value -= __z.real();
  1243. __imag__ _M_value -= __z.imag();
  1244. return *this;
  1245. }
  1246. template<typename _Tp>
  1247. complex&
  1248. operator*=(const complex<_Tp>& __z)
  1249. {
  1250. _ComplexT __t;
  1251. __real__ __t = __z.real();
  1252. __imag__ __t = __z.imag();
  1253. _M_value *= __t;
  1254. return *this;
  1255. }
  1256. template<typename _Tp>
  1257. complex&
  1258. operator/=(const complex<_Tp>& __z)
  1259. {
  1260. _ComplexT __t;
  1261. __real__ __t = __z.real();
  1262. __imag__ __t = __z.imag();
  1263. _M_value /= __t;
  1264. return *this;
  1265. }
  1266. _GLIBCXX_CONSTEXPR _ComplexT __rep() const { return _M_value; }
  1267. private:
  1268. _ComplexT _M_value;
  1269. };
  1270. // These bits have to be at the end of this file, so that the
  1271. // specializations have all been defined.
  1272. inline _GLIBCXX_CONSTEXPR
  1273. complex<float>::complex(const complex<double>& __z)
  1274. : _M_value(__z.__rep()) { }
  1275. inline _GLIBCXX_CONSTEXPR
  1276. complex<float>::complex(const complex<long double>& __z)
  1277. : _M_value(__z.__rep()) { }
  1278. inline _GLIBCXX_CONSTEXPR
  1279. complex<double>::complex(const complex<long double>& __z)
  1280. : _M_value(__z.__rep()) { }
  1281. // Inhibit implicit instantiations for required instantiations,
  1282. // which are defined via explicit instantiations elsewhere.
  1283. // NB: This syntax is a GNU extension.
  1284. #if _GLIBCXX_EXTERN_TEMPLATE
  1285. extern template istream& operator>>(istream&, complex<float>&);
  1286. extern template ostream& operator<<(ostream&, const complex<float>&);
  1287. extern template istream& operator>>(istream&, complex<double>&);
  1288. extern template ostream& operator<<(ostream&, const complex<double>&);
  1289. extern template istream& operator>>(istream&, complex<long double>&);
  1290. extern template ostream& operator<<(ostream&, const complex<long double>&);
  1291. #ifdef _GLIBCXX_USE_WCHAR_T
  1292. extern template wistream& operator>>(wistream&, complex<float>&);
  1293. extern template wostream& operator<<(wostream&, const complex<float>&);
  1294. extern template wistream& operator>>(wistream&, complex<double>&);
  1295. extern template wostream& operator<<(wostream&, const complex<double>&);
  1296. extern template wistream& operator>>(wistream&, complex<long double>&);
  1297. extern template wostream& operator<<(wostream&, const complex<long double>&);
  1298. #endif
  1299. #endif
  1300. // @} group complex_numbers
  1301. _GLIBCXX_END_NAMESPACE_VERSION
  1302. } // namespace
  1303. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  1304. {
  1305. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  1306. // See ext/type_traits.h for the primary template.
  1307. template<typename _Tp, typename _Up>
  1308. struct __promote_2<std::complex<_Tp>, _Up>
  1309. {
  1310. public:
  1311. typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
  1312. };
  1313. template<typename _Tp, typename _Up>
  1314. struct __promote_2<_Tp, std::complex<_Up> >
  1315. {
  1316. public:
  1317. typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
  1318. };
  1319. template<typename _Tp, typename _Up>
  1320. struct __promote_2<std::complex<_Tp>, std::complex<_Up> >
  1321. {
  1322. public:
  1323. typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
  1324. };
  1325. _GLIBCXX_END_NAMESPACE_VERSION
  1326. } // namespace
  1327. #if __cplusplus >= 201103L
  1328. namespace std _GLIBCXX_VISIBILITY(default)
  1329. {
  1330. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  1331. // Forward declarations.
  1332. template<typename _Tp> std::complex<_Tp> acos(const std::complex<_Tp>&);
  1333. template<typename _Tp> std::complex<_Tp> asin(const std::complex<_Tp>&);
  1334. template<typename _Tp> std::complex<_Tp> atan(const std::complex<_Tp>&);
  1335. template<typename _Tp> std::complex<_Tp> acosh(const std::complex<_Tp>&);
  1336. template<typename _Tp> std::complex<_Tp> asinh(const std::complex<_Tp>&);
  1337. template<typename _Tp> std::complex<_Tp> atanh(const std::complex<_Tp>&);
  1338. // DR 595.
  1339. template<typename _Tp> _Tp fabs(const std::complex<_Tp>&);
  1340. template<typename _Tp>
  1341. inline std::complex<_Tp>
  1342. __complex_acos(const std::complex<_Tp>& __z)
  1343. {
  1344. const std::complex<_Tp> __t = std::asin(__z);
  1345. const _Tp __pi_2 = 1.5707963267948966192313216916397514L;
  1346. return std::complex<_Tp>(__pi_2 - __t.real(), -__t.imag());
  1347. }
  1348. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1349. inline __complex__ float
  1350. __complex_acos(__complex__ float __z)
  1351. { return __builtin_cacosf(__z); }
  1352. inline __complex__ double
  1353. __complex_acos(__complex__ double __z)
  1354. { return __builtin_cacos(__z); }
  1355. inline __complex__ long double
  1356. __complex_acos(const __complex__ long double& __z)
  1357. { return __builtin_cacosl(__z); }
  1358. template<typename _Tp>
  1359. inline std::complex<_Tp>
  1360. acos(const std::complex<_Tp>& __z)
  1361. { return __complex_acos(__z.__rep()); }
  1362. #else
  1363. /// acos(__z) [8.1.2].
  1364. // Effects: Behaves the same as C99 function cacos, defined
  1365. // in subclause 7.3.5.1.
  1366. template<typename _Tp>
  1367. inline std::complex<_Tp>
  1368. acos(const std::complex<_Tp>& __z)
  1369. { return __complex_acos(__z); }
  1370. #endif
  1371. template<typename _Tp>
  1372. inline std::complex<_Tp>
  1373. __complex_asin(const std::complex<_Tp>& __z)
  1374. {
  1375. std::complex<_Tp> __t(-__z.imag(), __z.real());
  1376. __t = std::asinh(__t);
  1377. return std::complex<_Tp>(__t.imag(), -__t.real());
  1378. }
  1379. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1380. inline __complex__ float
  1381. __complex_asin(__complex__ float __z)
  1382. { return __builtin_casinf(__z); }
  1383. inline __complex__ double
  1384. __complex_asin(__complex__ double __z)
  1385. { return __builtin_casin(__z); }
  1386. inline __complex__ long double
  1387. __complex_asin(const __complex__ long double& __z)
  1388. { return __builtin_casinl(__z); }
  1389. template<typename _Tp>
  1390. inline std::complex<_Tp>
  1391. asin(const std::complex<_Tp>& __z)
  1392. { return __complex_asin(__z.__rep()); }
  1393. #else
  1394. /// asin(__z) [8.1.3].
  1395. // Effects: Behaves the same as C99 function casin, defined
  1396. // in subclause 7.3.5.2.
  1397. template<typename _Tp>
  1398. inline std::complex<_Tp>
  1399. asin(const std::complex<_Tp>& __z)
  1400. { return __complex_asin(__z); }
  1401. #endif
  1402. template<typename _Tp>
  1403. std::complex<_Tp>
  1404. __complex_atan(const std::complex<_Tp>& __z)
  1405. {
  1406. const _Tp __r2 = __z.real() * __z.real();
  1407. const _Tp __x = _Tp(1.0) - __r2 - __z.imag() * __z.imag();
  1408. _Tp __num = __z.imag() + _Tp(1.0);
  1409. _Tp __den = __z.imag() - _Tp(1.0);
  1410. __num = __r2 + __num * __num;
  1411. __den = __r2 + __den * __den;
  1412. return std::complex<_Tp>(_Tp(0.5) * atan2(_Tp(2.0) * __z.real(), __x),
  1413. _Tp(0.25) * log(__num / __den));
  1414. }
  1415. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1416. inline __complex__ float
  1417. __complex_atan(__complex__ float __z)
  1418. { return __builtin_catanf(__z); }
  1419. inline __complex__ double
  1420. __complex_atan(__complex__ double __z)
  1421. { return __builtin_catan(__z); }
  1422. inline __complex__ long double
  1423. __complex_atan(const __complex__ long double& __z)
  1424. { return __builtin_catanl(__z); }
  1425. template<typename _Tp>
  1426. inline std::complex<_Tp>
  1427. atan(const std::complex<_Tp>& __z)
  1428. { return __complex_atan(__z.__rep()); }
  1429. #else
  1430. /// atan(__z) [8.1.4].
  1431. // Effects: Behaves the same as C99 function catan, defined
  1432. // in subclause 7.3.5.3.
  1433. template<typename _Tp>
  1434. inline std::complex<_Tp>
  1435. atan(const std::complex<_Tp>& __z)
  1436. { return __complex_atan(__z); }
  1437. #endif
  1438. template<typename _Tp>
  1439. std::complex<_Tp>
  1440. __complex_acosh(const std::complex<_Tp>& __z)
  1441. {
  1442. // Kahan's formula.
  1443. return _Tp(2.0) * std::log(std::sqrt(_Tp(0.5) * (__z + _Tp(1.0)))
  1444. + std::sqrt(_Tp(0.5) * (__z - _Tp(1.0))));
  1445. }
  1446. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1447. inline __complex__ float
  1448. __complex_acosh(__complex__ float __z)
  1449. { return __builtin_cacoshf(__z); }
  1450. inline __complex__ double
  1451. __complex_acosh(__complex__ double __z)
  1452. { return __builtin_cacosh(__z); }
  1453. inline __complex__ long double
  1454. __complex_acosh(const __complex__ long double& __z)
  1455. { return __builtin_cacoshl(__z); }
  1456. template<typename _Tp>
  1457. inline std::complex<_Tp>
  1458. acosh(const std::complex<_Tp>& __z)
  1459. { return __complex_acosh(__z.__rep()); }
  1460. #else
  1461. /// acosh(__z) [8.1.5].
  1462. // Effects: Behaves the same as C99 function cacosh, defined
  1463. // in subclause 7.3.6.1.
  1464. template<typename _Tp>
  1465. inline std::complex<_Tp>
  1466. acosh(const std::complex<_Tp>& __z)
  1467. { return __complex_acosh(__z); }
  1468. #endif
  1469. template<typename _Tp>
  1470. std::complex<_Tp>
  1471. __complex_asinh(const std::complex<_Tp>& __z)
  1472. {
  1473. std::complex<_Tp> __t((__z.real() - __z.imag())
  1474. * (__z.real() + __z.imag()) + _Tp(1.0),
  1475. _Tp(2.0) * __z.real() * __z.imag());
  1476. __t = std::sqrt(__t);
  1477. return std::log(__t + __z);
  1478. }
  1479. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1480. inline __complex__ float
  1481. __complex_asinh(__complex__ float __z)
  1482. { return __builtin_casinhf(__z); }
  1483. inline __complex__ double
  1484. __complex_asinh(__complex__ double __z)
  1485. { return __builtin_casinh(__z); }
  1486. inline __complex__ long double
  1487. __complex_asinh(const __complex__ long double& __z)
  1488. { return __builtin_casinhl(__z); }
  1489. template<typename _Tp>
  1490. inline std::complex<_Tp>
  1491. asinh(const std::complex<_Tp>& __z)
  1492. { return __complex_asinh(__z.__rep()); }
  1493. #else
  1494. /// asinh(__z) [8.1.6].
  1495. // Effects: Behaves the same as C99 function casin, defined
  1496. // in subclause 7.3.6.2.
  1497. template<typename _Tp>
  1498. inline std::complex<_Tp>
  1499. asinh(const std::complex<_Tp>& __z)
  1500. { return __complex_asinh(__z); }
  1501. #endif
  1502. template<typename _Tp>
  1503. std::complex<_Tp>
  1504. __complex_atanh(const std::complex<_Tp>& __z)
  1505. {
  1506. const _Tp __i2 = __z.imag() * __z.imag();
  1507. const _Tp __x = _Tp(1.0) - __i2 - __z.real() * __z.real();
  1508. _Tp __num = _Tp(1.0) + __z.real();
  1509. _Tp __den = _Tp(1.0) - __z.real();
  1510. __num = __i2 + __num * __num;
  1511. __den = __i2 + __den * __den;
  1512. return std::complex<_Tp>(_Tp(0.25) * (log(__num) - log(__den)),
  1513. _Tp(0.5) * atan2(_Tp(2.0) * __z.imag(), __x));
  1514. }
  1515. #if _GLIBCXX_USE_C99_COMPLEX_TR1
  1516. inline __complex__ float
  1517. __complex_atanh(__complex__ float __z)
  1518. { return __builtin_catanhf(__z); }
  1519. inline __complex__ double
  1520. __complex_atanh(__complex__ double __z)
  1521. { return __builtin_catanh(__z); }
  1522. inline __complex__ long double
  1523. __complex_atanh(const __complex__ long double& __z)
  1524. { return __builtin_catanhl(__z); }
  1525. template<typename _Tp>
  1526. inline std::complex<_Tp>
  1527. atanh(const std::complex<_Tp>& __z)
  1528. { return __complex_atanh(__z.__rep()); }
  1529. #else
  1530. /// atanh(__z) [8.1.7].
  1531. // Effects: Behaves the same as C99 function catanh, defined
  1532. // in subclause 7.3.6.3.
  1533. template<typename _Tp>
  1534. inline std::complex<_Tp>
  1535. atanh(const std::complex<_Tp>& __z)
  1536. { return __complex_atanh(__z); }
  1537. #endif
  1538. template<typename _Tp>
  1539. inline _Tp
  1540. /// fabs(__z) [8.1.8].
  1541. // Effects: Behaves the same as C99 function cabs, defined
  1542. // in subclause 7.3.8.1.
  1543. fabs(const std::complex<_Tp>& __z)
  1544. { return std::abs(__z); }
  1545. /// Additional overloads [8.1.9].
  1546. template<typename _Tp>
  1547. inline typename __gnu_cxx::__promote<_Tp>::__type
  1548. arg(_Tp __x)
  1549. {
  1550. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  1551. #if (_GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC)
  1552. return std::signbit(__x) ? __type(3.1415926535897932384626433832795029L)
  1553. : __type();
  1554. #else
  1555. return std::arg(std::complex<__type>(__x));
  1556. #endif
  1557. }
  1558. template<typename _Tp>
  1559. inline typename __gnu_cxx::__promote<_Tp>::__type
  1560. imag(_Tp)
  1561. { return _Tp(); }
  1562. template<typename _Tp>
  1563. inline typename __gnu_cxx::__promote<_Tp>::__type
  1564. norm(_Tp __x)
  1565. {
  1566. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  1567. return __type(__x) * __type(__x);
  1568. }
  1569. template<typename _Tp>
  1570. inline typename __gnu_cxx::__promote<_Tp>::__type
  1571. real(_Tp __x)
  1572. { return __x; }
  1573. template<typename _Tp, typename _Up>
  1574. inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type>
  1575. pow(const std::complex<_Tp>& __x, const _Up& __y)
  1576. {
  1577. typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
  1578. return std::pow(std::complex<__type>(__x), __type(__y));
  1579. }
  1580. template<typename _Tp, typename _Up>
  1581. inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type>
  1582. pow(const _Tp& __x, const std::complex<_Up>& __y)
  1583. {
  1584. typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
  1585. return std::pow(__type(__x), std::complex<__type>(__y));
  1586. }
  1587. template<typename _Tp, typename _Up>
  1588. inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type>
  1589. pow(const std::complex<_Tp>& __x, const std::complex<_Up>& __y)
  1590. {
  1591. typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
  1592. return std::pow(std::complex<__type>(__x),
  1593. std::complex<__type>(__y));
  1594. }
  1595. // Forward declarations.
  1596. // DR 781.
  1597. template<typename _Tp> std::complex<_Tp> proj(const std::complex<_Tp>&);
  1598. template<typename _Tp>
  1599. std::complex<_Tp>
  1600. __complex_proj(const std::complex<_Tp>& __z)
  1601. {
  1602. const _Tp __den = (__z.real() * __z.real()
  1603. + __z.imag() * __z.imag() + _Tp(1.0));
  1604. return std::complex<_Tp>((_Tp(2.0) * __z.real()) / __den,
  1605. (_Tp(2.0) * __z.imag()) / __den);
  1606. }
  1607. #if _GLIBCXX_USE_C99_COMPLEX
  1608. inline __complex__ float
  1609. __complex_proj(__complex__ float __z)
  1610. { return __builtin_cprojf(__z); }
  1611. inline __complex__ double
  1612. __complex_proj(__complex__ double __z)
  1613. { return __builtin_cproj(__z); }
  1614. inline __complex__ long double
  1615. __complex_proj(const __complex__ long double& __z)
  1616. { return __builtin_cprojl(__z); }
  1617. template<typename _Tp>
  1618. inline std::complex<_Tp>
  1619. proj(const std::complex<_Tp>& __z)
  1620. { return __complex_proj(__z.__rep()); }
  1621. #else
  1622. template<typename _Tp>
  1623. inline std::complex<_Tp>
  1624. proj(const std::complex<_Tp>& __z)
  1625. { return __complex_proj(__z); }
  1626. #endif
  1627. // DR 1137.
  1628. template<typename _Tp>
  1629. inline typename __gnu_cxx::__promote<_Tp>::__type
  1630. proj(_Tp __x)
  1631. { return __x; }
  1632. template<typename _Tp>
  1633. inline typename __gnu_cxx::__promote<_Tp>::__type
  1634. conj(_Tp __x)
  1635. { return __x; }
  1636. #if __cplusplus > 201103L
  1637. inline namespace literals {
  1638. inline namespace complex_literals {
  1639. #define __cpp_lib_complex_udls 201309
  1640. constexpr std::complex<float>
  1641. operator""if(long double __num)
  1642. { return std::complex<float>{0.0F, static_cast<float>(__num)}; }
  1643. constexpr std::complex<float>
  1644. operator""if(unsigned long long __num)
  1645. { return std::complex<float>{0.0F, static_cast<float>(__num)}; }
  1646. constexpr std::complex<double>
  1647. operator""i(long double __num)
  1648. { return std::complex<double>{0.0, static_cast<double>(__num)}; }
  1649. constexpr std::complex<double>
  1650. operator""i(unsigned long long __num)
  1651. { return std::complex<double>{0.0, static_cast<double>(__num)}; }
  1652. constexpr std::complex<long double>
  1653. operator""il(long double __num)
  1654. { return std::complex<long double>{0.0L, __num}; }
  1655. constexpr std::complex<long double>
  1656. operator""il(unsigned long long __num)
  1657. { return std::complex<long double>{0.0L, static_cast<long double>(__num)}; }
  1658. } // inline namespace complex_literals
  1659. } // inline namespace literals
  1660. #endif // C++14
  1661. _GLIBCXX_END_NAMESPACE_VERSION
  1662. } // namespace
  1663. #endif // C++11
  1664. #endif /* _GLIBCXX_COMPLEX */