You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2021 lines
55KB

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