xref: /freebsd/contrib/llvm-project/libcxx/include/complex (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_COMPLEX
110b57cec5SDimitry Andric#define _LIBCPP_COMPLEX
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    complex synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
190b57cec5SDimitry Andrictemplate<class T>
200b57cec5SDimitry Andricclass complex
210b57cec5SDimitry Andric{
220b57cec5SDimitry Andricpublic:
230b57cec5SDimitry Andric    typedef T value_type;
240b57cec5SDimitry Andric
250b57cec5SDimitry Andric    complex(const T& re = T(), const T& im = T()); // constexpr in C++14
260b57cec5SDimitry Andric    complex(const complex&);  // constexpr in C++14
270b57cec5SDimitry Andric    template<class X> complex(const complex<X>&);  // constexpr in C++14
280b57cec5SDimitry Andric
290b57cec5SDimitry Andric    T real() const; // constexpr in C++14
300b57cec5SDimitry Andric    T imag() const; // constexpr in C++14
310b57cec5SDimitry Andric
32bdd1243dSDimitry Andric    void real(T); // constexpr in C++20
33bdd1243dSDimitry Andric    void imag(T); // constexpr in C++20
340b57cec5SDimitry Andric
35bdd1243dSDimitry Andric    complex<T>& operator= (const T&); // constexpr in C++20
36bdd1243dSDimitry Andric    complex<T>& operator+=(const T&); // constexpr in C++20
37bdd1243dSDimitry Andric    complex<T>& operator-=(const T&); // constexpr in C++20
38bdd1243dSDimitry Andric    complex<T>& operator*=(const T&); // constexpr in C++20
39bdd1243dSDimitry Andric    complex<T>& operator/=(const T&); // constexpr in C++20
400b57cec5SDimitry Andric
41bdd1243dSDimitry Andric    complex& operator=(const complex&); // constexpr in C++20
42bdd1243dSDimitry Andric    template<class X> complex<T>& operator= (const complex<X>&); // constexpr in C++20
43bdd1243dSDimitry Andric    template<class X> complex<T>& operator+=(const complex<X>&); // constexpr in C++20
44bdd1243dSDimitry Andric    template<class X> complex<T>& operator-=(const complex<X>&); // constexpr in C++20
45bdd1243dSDimitry Andric    template<class X> complex<T>& operator*=(const complex<X>&); // constexpr in C++20
46bdd1243dSDimitry Andric    template<class X> complex<T>& operator/=(const complex<X>&); // constexpr in C++20
470b57cec5SDimitry Andric};
480b57cec5SDimitry Andric
490b57cec5SDimitry Andrictemplate<>
500b57cec5SDimitry Andricclass complex<float>
510b57cec5SDimitry Andric{
520b57cec5SDimitry Andricpublic:
530b57cec5SDimitry Andric    typedef float value_type;
540b57cec5SDimitry Andric
550b57cec5SDimitry Andric    constexpr complex(float re = 0.0f, float im = 0.0f);
560b57cec5SDimitry Andric    explicit constexpr complex(const complex<double>&);
570b57cec5SDimitry Andric    explicit constexpr complex(const complex<long double>&);
580b57cec5SDimitry Andric
590b57cec5SDimitry Andric    constexpr float real() const;
60bdd1243dSDimitry Andric    void real(float); // constexpr in C++20
610b57cec5SDimitry Andric    constexpr float imag() const;
62bdd1243dSDimitry Andric    void imag(float); // constexpr in C++20
630b57cec5SDimitry Andric
64bdd1243dSDimitry Andric    complex<float>& operator= (float); // constexpr in C++20
65bdd1243dSDimitry Andric    complex<float>& operator+=(float); // constexpr in C++20
66bdd1243dSDimitry Andric    complex<float>& operator-=(float); // constexpr in C++20
67bdd1243dSDimitry Andric    complex<float>& operator*=(float); // constexpr in C++20
68bdd1243dSDimitry Andric    complex<float>& operator/=(float); // constexpr in C++20
690b57cec5SDimitry Andric
70bdd1243dSDimitry Andric    complex<float>& operator=(const complex<float>&); // constexpr in C++20
71bdd1243dSDimitry Andric    template<class X> complex<float>& operator= (const complex<X>&); // constexpr in C++20
72bdd1243dSDimitry Andric    template<class X> complex<float>& operator+=(const complex<X>&); // constexpr in C++20
73bdd1243dSDimitry Andric    template<class X> complex<float>& operator-=(const complex<X>&); // constexpr in C++20
74bdd1243dSDimitry Andric    template<class X> complex<float>& operator*=(const complex<X>&); // constexpr in C++20
75bdd1243dSDimitry Andric    template<class X> complex<float>& operator/=(const complex<X>&); // constexpr in C++20
760b57cec5SDimitry Andric};
770b57cec5SDimitry Andric
780b57cec5SDimitry Andrictemplate<>
790b57cec5SDimitry Andricclass complex<double>
800b57cec5SDimitry Andric{
810b57cec5SDimitry Andricpublic:
820b57cec5SDimitry Andric    typedef double value_type;
830b57cec5SDimitry Andric
840b57cec5SDimitry Andric    constexpr complex(double re = 0.0, double im = 0.0);
850b57cec5SDimitry Andric    constexpr complex(const complex<float>&);
860b57cec5SDimitry Andric    explicit constexpr complex(const complex<long double>&);
870b57cec5SDimitry Andric
880b57cec5SDimitry Andric    constexpr double real() const;
89bdd1243dSDimitry Andric    void real(double); // constexpr in C++20
900b57cec5SDimitry Andric    constexpr double imag() const;
91bdd1243dSDimitry Andric    void imag(double); // constexpr in C++20
920b57cec5SDimitry Andric
93bdd1243dSDimitry Andric    complex<double>& operator= (double); // constexpr in C++20
94bdd1243dSDimitry Andric    complex<double>& operator+=(double); // constexpr in C++20
95bdd1243dSDimitry Andric    complex<double>& operator-=(double); // constexpr in C++20
96bdd1243dSDimitry Andric    complex<double>& operator*=(double); // constexpr in C++20
97bdd1243dSDimitry Andric    complex<double>& operator/=(double); // constexpr in C++20
98bdd1243dSDimitry Andric    complex<double>& operator=(const complex<double>&); // constexpr in C++20
990b57cec5SDimitry Andric
100bdd1243dSDimitry Andric    template<class X> complex<double>& operator= (const complex<X>&); // constexpr in C++20
101bdd1243dSDimitry Andric    template<class X> complex<double>& operator+=(const complex<X>&); // constexpr in C++20
102bdd1243dSDimitry Andric    template<class X> complex<double>& operator-=(const complex<X>&); // constexpr in C++20
103bdd1243dSDimitry Andric    template<class X> complex<double>& operator*=(const complex<X>&); // constexpr in C++20
104bdd1243dSDimitry Andric    template<class X> complex<double>& operator/=(const complex<X>&); // constexpr in C++20
1050b57cec5SDimitry Andric};
1060b57cec5SDimitry Andric
1070b57cec5SDimitry Andrictemplate<>
1080b57cec5SDimitry Andricclass complex<long double>
1090b57cec5SDimitry Andric{
1100b57cec5SDimitry Andricpublic:
1110b57cec5SDimitry Andric    typedef long double value_type;
1120b57cec5SDimitry Andric
1130b57cec5SDimitry Andric    constexpr complex(long double re = 0.0L, long double im = 0.0L);
1140b57cec5SDimitry Andric    constexpr complex(const complex<float>&);
1150b57cec5SDimitry Andric    constexpr complex(const complex<double>&);
1160b57cec5SDimitry Andric
1170b57cec5SDimitry Andric    constexpr long double real() const;
118bdd1243dSDimitry Andric    void real(long double); // constexpr in C++20
1190b57cec5SDimitry Andric    constexpr long double imag() const;
120bdd1243dSDimitry Andric    void imag(long double); // constexpr in C++20
1210b57cec5SDimitry Andric
122bdd1243dSDimitry Andric    complex<long double>& operator=(const complex<long double>&); // constexpr in C++20
123bdd1243dSDimitry Andric    complex<long double>& operator= (long double); // constexpr in C++20
124bdd1243dSDimitry Andric    complex<long double>& operator+=(long double); // constexpr in C++20
125bdd1243dSDimitry Andric    complex<long double>& operator-=(long double); // constexpr in C++20
126bdd1243dSDimitry Andric    complex<long double>& operator*=(long double); // constexpr in C++20
127bdd1243dSDimitry Andric    complex<long double>& operator/=(long double); // constexpr in C++20
1280b57cec5SDimitry Andric
129bdd1243dSDimitry Andric    template<class X> complex<long double>& operator= (const complex<X>&); // constexpr in C++20
130bdd1243dSDimitry Andric    template<class X> complex<long double>& operator+=(const complex<X>&); // constexpr in C++20
131bdd1243dSDimitry Andric    template<class X> complex<long double>& operator-=(const complex<X>&); // constexpr in C++20
132bdd1243dSDimitry Andric    template<class X> complex<long double>& operator*=(const complex<X>&); // constexpr in C++20
133bdd1243dSDimitry Andric    template<class X> complex<long double>& operator/=(const complex<X>&); // constexpr in C++20
1340b57cec5SDimitry Andric};
1350b57cec5SDimitry Andric
1360b57cec5SDimitry Andric// 26.3.6 operators:
137bdd1243dSDimitry Andrictemplate<class T> complex<T> operator+(const complex<T>&, const complex<T>&); // constexpr in C++20
138bdd1243dSDimitry Andrictemplate<class T> complex<T> operator+(const complex<T>&, const T&);          // constexpr in C++20
139bdd1243dSDimitry Andrictemplate<class T> complex<T> operator+(const T&, const complex<T>&);          // constexpr in C++20
140bdd1243dSDimitry Andrictemplate<class T> complex<T> operator-(const complex<T>&, const complex<T>&); // constexpr in C++20
141bdd1243dSDimitry Andrictemplate<class T> complex<T> operator-(const complex<T>&, const T&);          // constexpr in C++20
142bdd1243dSDimitry Andrictemplate<class T> complex<T> operator-(const T&, const complex<T>&);          // constexpr in C++20
143bdd1243dSDimitry Andrictemplate<class T> complex<T> operator*(const complex<T>&, const complex<T>&); // constexpr in C++20
144bdd1243dSDimitry Andrictemplate<class T> complex<T> operator*(const complex<T>&, const T&);          // constexpr in C++20
145bdd1243dSDimitry Andrictemplate<class T> complex<T> operator*(const T&, const complex<T>&);          // constexpr in C++20
146bdd1243dSDimitry Andrictemplate<class T> complex<T> operator/(const complex<T>&, const complex<T>&); // constexpr in C++20
147bdd1243dSDimitry Andrictemplate<class T> complex<T> operator/(const complex<T>&, const T&);          // constexpr in C++20
148bdd1243dSDimitry Andrictemplate<class T> complex<T> operator/(const T&, const complex<T>&);          // constexpr in C++20
149bdd1243dSDimitry Andrictemplate<class T> complex<T> operator+(const complex<T>&);                    // constexpr in C++20
150bdd1243dSDimitry Andrictemplate<class T> complex<T> operator-(const complex<T>&);                    // constexpr in C++20
1510b57cec5SDimitry Andrictemplate<class T> bool operator==(const complex<T>&, const complex<T>&);      // constexpr in C++14
1520b57cec5SDimitry Andrictemplate<class T> bool operator==(const complex<T>&, const T&);               // constexpr in C++14
153*06c3fb27SDimitry Andrictemplate<class T> bool operator==(const T&, const complex<T>&);               // constexpr in C++14, removed in C++20
154*06c3fb27SDimitry Andrictemplate<class T> bool operator!=(const complex<T>&, const complex<T>&);      // constexpr in C++14, removed in C++20
155*06c3fb27SDimitry Andrictemplate<class T> bool operator!=(const complex<T>&, const T&);               // constexpr in C++14, removed in C++20
156*06c3fb27SDimitry Andrictemplate<class T> bool operator!=(const T&, const complex<T>&);               // constexpr in C++14, removed in C++20
1570b57cec5SDimitry Andric
1580b57cec5SDimitry Andrictemplate<class T, class charT, class traits>
1590b57cec5SDimitry Andric  basic_istream<charT, traits>&
1600b57cec5SDimitry Andric  operator>>(basic_istream<charT, traits>&, complex<T>&);
1610b57cec5SDimitry Andrictemplate<class T, class charT, class traits>
1620b57cec5SDimitry Andric  basic_ostream<charT, traits>&
1630b57cec5SDimitry Andric  operator<<(basic_ostream<charT, traits>&, const complex<T>&);
1640b57cec5SDimitry Andric
1650b57cec5SDimitry Andric// 26.3.7 values:
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andrictemplate<class T>              T real(const complex<T>&); // constexpr in C++14
1680b57cec5SDimitry Andric                     long double real(long double);       // constexpr in C++14
1690b57cec5SDimitry Andric                          double real(double);            // constexpr in C++14
1700b57cec5SDimitry Andrictemplate<Integral T>      double real(T);                 // constexpr in C++14
1710b57cec5SDimitry Andric                          float  real(float);             // constexpr in C++14
1720b57cec5SDimitry Andric
1730b57cec5SDimitry Andrictemplate<class T>              T imag(const complex<T>&); // constexpr in C++14
1740b57cec5SDimitry Andric                     long double imag(long double);       // constexpr in C++14
1750b57cec5SDimitry Andric                          double imag(double);            // constexpr in C++14
1760b57cec5SDimitry Andrictemplate<Integral T>      double imag(T);                 // constexpr in C++14
1770b57cec5SDimitry Andric                          float  imag(float);             // constexpr in C++14
1780b57cec5SDimitry Andric
1790b57cec5SDimitry Andrictemplate<class T> T abs(const complex<T>&);
1800b57cec5SDimitry Andric
1810b57cec5SDimitry Andrictemplate<class T>              T arg(const complex<T>&);
1820b57cec5SDimitry Andric                     long double arg(long double);
1830b57cec5SDimitry Andric                          double arg(double);
1840b57cec5SDimitry Andrictemplate<Integral T>      double arg(T);
1850b57cec5SDimitry Andric                          float  arg(float);
1860b57cec5SDimitry Andric
187bdd1243dSDimitry Andrictemplate<class T>              T norm(const complex<T>&); // constexpr in C++20
188bdd1243dSDimitry Andric                     long double norm(long double);       // constexpr in C++20
189bdd1243dSDimitry Andric                          double norm(double);            // constexpr in C++20
190bdd1243dSDimitry Andrictemplate<Integral T>      double norm(T);                 // constexpr in C++20
191bdd1243dSDimitry Andric                          float  norm(float);             // constexpr in C++20
1920b57cec5SDimitry Andric
193bdd1243dSDimitry Andrictemplate<class T>      complex<T>           conj(const complex<T>&); // constexpr in C++20
194bdd1243dSDimitry Andric                       complex<long double> conj(long double);       // constexpr in C++20
195bdd1243dSDimitry Andric                       complex<double>      conj(double);            // constexpr in C++20
196bdd1243dSDimitry Andrictemplate<Integral T>   complex<double>      conj(T);                 // constexpr in C++20
197bdd1243dSDimitry Andric                       complex<float>       conj(float);             // constexpr in C++20
1980b57cec5SDimitry Andric
1990b57cec5SDimitry Andrictemplate<class T>    complex<T>           proj(const complex<T>&);
2000b57cec5SDimitry Andric                     complex<long double> proj(long double);
2010b57cec5SDimitry Andric                     complex<double>      proj(double);
2020b57cec5SDimitry Andrictemplate<Integral T> complex<double>      proj(T);
2030b57cec5SDimitry Andric                     complex<float>       proj(float);
2040b57cec5SDimitry Andric
2050b57cec5SDimitry Andrictemplate<class T> complex<T> polar(const T&, const T& = T());
2060b57cec5SDimitry Andric
2070b57cec5SDimitry Andric// 26.3.8 transcendentals:
2080b57cec5SDimitry Andrictemplate<class T> complex<T> acos(const complex<T>&);
2090b57cec5SDimitry Andrictemplate<class T> complex<T> asin(const complex<T>&);
2100b57cec5SDimitry Andrictemplate<class T> complex<T> atan(const complex<T>&);
2110b57cec5SDimitry Andrictemplate<class T> complex<T> acosh(const complex<T>&);
2120b57cec5SDimitry Andrictemplate<class T> complex<T> asinh(const complex<T>&);
2130b57cec5SDimitry Andrictemplate<class T> complex<T> atanh(const complex<T>&);
2140b57cec5SDimitry Andrictemplate<class T> complex<T> cos (const complex<T>&);
2150b57cec5SDimitry Andrictemplate<class T> complex<T> cosh (const complex<T>&);
2160b57cec5SDimitry Andrictemplate<class T> complex<T> exp (const complex<T>&);
2170b57cec5SDimitry Andrictemplate<class T> complex<T> log (const complex<T>&);
2180b57cec5SDimitry Andrictemplate<class T> complex<T> log10(const complex<T>&);
2190b57cec5SDimitry Andric
2200b57cec5SDimitry Andrictemplate<class T> complex<T> pow(const complex<T>&, const T&);
2210b57cec5SDimitry Andrictemplate<class T> complex<T> pow(const complex<T>&, const complex<T>&);
2220b57cec5SDimitry Andrictemplate<class T> complex<T> pow(const T&, const complex<T>&);
2230b57cec5SDimitry Andric
2240b57cec5SDimitry Andrictemplate<class T> complex<T> sin (const complex<T>&);
2250b57cec5SDimitry Andrictemplate<class T> complex<T> sinh (const complex<T>&);
2260b57cec5SDimitry Andrictemplate<class T> complex<T> sqrt (const complex<T>&);
2270b57cec5SDimitry Andrictemplate<class T> complex<T> tan (const complex<T>&);
2280b57cec5SDimitry Andrictemplate<class T> complex<T> tanh (const complex<T>&);
2290b57cec5SDimitry Andric
2300b57cec5SDimitry Andric}  // std
2310b57cec5SDimitry Andric
2320b57cec5SDimitry Andric*/
2330b57cec5SDimitry Andric
23481ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
2350b57cec5SDimitry Andric#include <__config>
2360b57cec5SDimitry Andric#include <cmath>
2375ffd83dbSDimitry Andric#include <iosfwd>
238fe6060f1SDimitry Andric#include <stdexcept>
2390b57cec5SDimitry Andric#include <version>
2400b57cec5SDimitry Andric
241e8d8bef9SDimitry Andric#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
242e8d8bef9SDimitry Andric#   include <sstream> // for std::basic_ostringstream
243e8d8bef9SDimitry Andric#endif
244e8d8bef9SDimitry Andric
2450b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2460b57cec5SDimitry Andric#  pragma GCC system_header
2470b57cec5SDimitry Andric#endif
2480b57cec5SDimitry Andric
2490b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2500b57cec5SDimitry Andric
2510b57cec5SDimitry Andrictemplate<class _Tp> class _LIBCPP_TEMPLATE_VIS complex;
2520b57cec5SDimitry Andric
253bdd1243dSDimitry Andrictemplate<class _Tp> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 complex<_Tp> operator*(const complex<_Tp>& __z, const complex<_Tp>& __w);
254bdd1243dSDimitry Andrictemplate<class _Tp> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 complex<_Tp> operator/(const complex<_Tp>& __x, const complex<_Tp>& __y);
2550b57cec5SDimitry Andric
2560b57cec5SDimitry Andrictemplate<class _Tp>
2570b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS complex
2580b57cec5SDimitry Andric{
2590b57cec5SDimitry Andricpublic:
2600b57cec5SDimitry Andric    typedef _Tp value_type;
2610b57cec5SDimitry Andricprivate:
2620b57cec5SDimitry Andric    value_type __re_;
2630b57cec5SDimitry Andric    value_type __im_;
2640b57cec5SDimitry Andricpublic:
265bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
2660b57cec5SDimitry Andric    complex(const value_type& __re = value_type(), const value_type& __im = value_type())
2670b57cec5SDimitry Andric        : __re_(__re), __im_(__im) {}
268bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
2690b57cec5SDimitry Andric    complex(const complex<_Xp>& __c)
2700b57cec5SDimitry Andric        : __re_(__c.real()), __im_(__c.imag()) {}
2710b57cec5SDimitry Andric
272bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 value_type real() const {return __re_;}
273bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 value_type imag() const {return __im_;}
2740b57cec5SDimitry Andric
275bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void real(value_type __re) {__re_ = __re;}
276bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void imag(value_type __im) {__im_ = __im;}
2770b57cec5SDimitry Andric
278bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator= (const value_type& __re)
2790b57cec5SDimitry Andric        {__re_ = __re; __im_ = value_type(); return *this;}
280bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator+=(const value_type& __re) {__re_ += __re; return *this;}
281bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator-=(const value_type& __re) {__re_ -= __re; return *this;}
282bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator*=(const value_type& __re) {__re_ *= __re; __im_ *= __re; return *this;}
283bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator/=(const value_type& __re) {__re_ /= __re; __im_ /= __re; return *this;}
2840b57cec5SDimitry Andric
285bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator= (const complex<_Xp>& __c)
2860b57cec5SDimitry Andric        {
2870b57cec5SDimitry Andric            __re_ = __c.real();
2880b57cec5SDimitry Andric            __im_ = __c.imag();
2890b57cec5SDimitry Andric            return *this;
2900b57cec5SDimitry Andric        }
291bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator+=(const complex<_Xp>& __c)
2920b57cec5SDimitry Andric        {
2930b57cec5SDimitry Andric            __re_ += __c.real();
2940b57cec5SDimitry Andric            __im_ += __c.imag();
2950b57cec5SDimitry Andric            return *this;
2960b57cec5SDimitry Andric        }
297bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator-=(const complex<_Xp>& __c)
2980b57cec5SDimitry Andric        {
2990b57cec5SDimitry Andric            __re_ -= __c.real();
3000b57cec5SDimitry Andric            __im_ -= __c.imag();
3010b57cec5SDimitry Andric            return *this;
3020b57cec5SDimitry Andric        }
303bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator*=(const complex<_Xp>& __c)
3040b57cec5SDimitry Andric        {
3050b57cec5SDimitry Andric            *this = *this * complex(__c.real(), __c.imag());
3060b57cec5SDimitry Andric            return *this;
3070b57cec5SDimitry Andric        }
308bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator/=(const complex<_Xp>& __c)
3090b57cec5SDimitry Andric        {
3100b57cec5SDimitry Andric            *this = *this / complex(__c.real(), __c.imag());
3110b57cec5SDimitry Andric            return *this;
3120b57cec5SDimitry Andric        }
3130b57cec5SDimitry Andric};
3140b57cec5SDimitry Andric
3150b57cec5SDimitry Andrictemplate<> class _LIBCPP_TEMPLATE_VIS complex<double>;
3160b57cec5SDimitry Andrictemplate<> class _LIBCPP_TEMPLATE_VIS complex<long double>;
3170b57cec5SDimitry Andric
3180b57cec5SDimitry Andrictemplate<>
3190b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS complex<float>
3200b57cec5SDimitry Andric{
3210b57cec5SDimitry Andric    float __re_;
3220b57cec5SDimitry Andric    float __im_;
3230b57cec5SDimitry Andricpublic:
3240b57cec5SDimitry Andric    typedef float value_type;
3250b57cec5SDimitry Andric
3260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(float __re = 0.0f, float __im = 0.0f)
3270b57cec5SDimitry Andric        : __re_(__re), __im_(__im) {}
3280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3290b57cec5SDimitry Andric    explicit _LIBCPP_CONSTEXPR complex(const complex<double>& __c);
3300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3310b57cec5SDimitry Andric    explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c);
3320b57cec5SDimitry Andric
3330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float real() const {return __re_;}
3340b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float imag() const {return __im_;}
3350b57cec5SDimitry Andric
336bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void real(value_type __re) {__re_ = __re;}
337bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void imag(value_type __im) {__im_ = __im;}
3380b57cec5SDimitry Andric
339bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator= (float __re)
3400b57cec5SDimitry Andric        {__re_ = __re; __im_ = value_type(); return *this;}
341bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator+=(float __re) {__re_ += __re; return *this;}
342bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator-=(float __re) {__re_ -= __re; return *this;}
343bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator*=(float __re) {__re_ *= __re; __im_ *= __re; return *this;}
344bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator/=(float __re) {__re_ /= __re; __im_ /= __re; return *this;}
3450b57cec5SDimitry Andric
346bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator= (const complex<_Xp>& __c)
3470b57cec5SDimitry Andric        {
3480b57cec5SDimitry Andric            __re_ = __c.real();
3490b57cec5SDimitry Andric            __im_ = __c.imag();
3500b57cec5SDimitry Andric            return *this;
3510b57cec5SDimitry Andric        }
352bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator+=(const complex<_Xp>& __c)
3530b57cec5SDimitry Andric        {
3540b57cec5SDimitry Andric            __re_ += __c.real();
3550b57cec5SDimitry Andric            __im_ += __c.imag();
3560b57cec5SDimitry Andric            return *this;
3570b57cec5SDimitry Andric        }
358bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator-=(const complex<_Xp>& __c)
3590b57cec5SDimitry Andric        {
3600b57cec5SDimitry Andric            __re_ -= __c.real();
3610b57cec5SDimitry Andric            __im_ -= __c.imag();
3620b57cec5SDimitry Andric            return *this;
3630b57cec5SDimitry Andric        }
364bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator*=(const complex<_Xp>& __c)
3650b57cec5SDimitry Andric        {
3660b57cec5SDimitry Andric            *this = *this * complex(__c.real(), __c.imag());
3670b57cec5SDimitry Andric            return *this;
3680b57cec5SDimitry Andric        }
369bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator/=(const complex<_Xp>& __c)
3700b57cec5SDimitry Andric        {
3710b57cec5SDimitry Andric            *this = *this / complex(__c.real(), __c.imag());
3720b57cec5SDimitry Andric            return *this;
3730b57cec5SDimitry Andric        }
3740b57cec5SDimitry Andric};
3750b57cec5SDimitry Andric
3760b57cec5SDimitry Andrictemplate<>
3770b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS complex<double>
3780b57cec5SDimitry Andric{
3790b57cec5SDimitry Andric    double __re_;
3800b57cec5SDimitry Andric    double __im_;
3810b57cec5SDimitry Andricpublic:
3820b57cec5SDimitry Andric    typedef double value_type;
3830b57cec5SDimitry Andric
3840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(double __re = 0.0, double __im = 0.0)
3850b57cec5SDimitry Andric        : __re_(__re), __im_(__im) {}
3860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3870b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR complex(const complex<float>& __c);
3880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3890b57cec5SDimitry Andric    explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c);
3900b57cec5SDimitry Andric
3910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double real() const {return __re_;}
3920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double imag() const {return __im_;}
3930b57cec5SDimitry Andric
394bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void real(value_type __re) {__re_ = __re;}
395bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void imag(value_type __im) {__im_ = __im;}
3960b57cec5SDimitry Andric
397bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator= (double __re)
3980b57cec5SDimitry Andric        {__re_ = __re; __im_ = value_type(); return *this;}
399bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator+=(double __re) {__re_ += __re; return *this;}
400bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator-=(double __re) {__re_ -= __re; return *this;}
401bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator*=(double __re) {__re_ *= __re; __im_ *= __re; return *this;}
402bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator/=(double __re) {__re_ /= __re; __im_ /= __re; return *this;}
4030b57cec5SDimitry Andric
404bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator= (const complex<_Xp>& __c)
4050b57cec5SDimitry Andric        {
4060b57cec5SDimitry Andric            __re_ = __c.real();
4070b57cec5SDimitry Andric            __im_ = __c.imag();
4080b57cec5SDimitry Andric            return *this;
4090b57cec5SDimitry Andric        }
410bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator+=(const complex<_Xp>& __c)
4110b57cec5SDimitry Andric        {
4120b57cec5SDimitry Andric            __re_ += __c.real();
4130b57cec5SDimitry Andric            __im_ += __c.imag();
4140b57cec5SDimitry Andric            return *this;
4150b57cec5SDimitry Andric        }
416bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator-=(const complex<_Xp>& __c)
4170b57cec5SDimitry Andric        {
4180b57cec5SDimitry Andric            __re_ -= __c.real();
4190b57cec5SDimitry Andric            __im_ -= __c.imag();
4200b57cec5SDimitry Andric            return *this;
4210b57cec5SDimitry Andric        }
422bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator*=(const complex<_Xp>& __c)
4230b57cec5SDimitry Andric        {
4240b57cec5SDimitry Andric            *this = *this * complex(__c.real(), __c.imag());
4250b57cec5SDimitry Andric            return *this;
4260b57cec5SDimitry Andric        }
427bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator/=(const complex<_Xp>& __c)
4280b57cec5SDimitry Andric        {
4290b57cec5SDimitry Andric            *this = *this / complex(__c.real(), __c.imag());
4300b57cec5SDimitry Andric            return *this;
4310b57cec5SDimitry Andric        }
4320b57cec5SDimitry Andric};
4330b57cec5SDimitry Andric
4340b57cec5SDimitry Andrictemplate<>
4350b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS complex<long double>
4360b57cec5SDimitry Andric{
4370b57cec5SDimitry Andric    long double __re_;
4380b57cec5SDimitry Andric    long double __im_;
4390b57cec5SDimitry Andricpublic:
4400b57cec5SDimitry Andric    typedef long double value_type;
4410b57cec5SDimitry Andric
4420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(long double __re = 0.0L, long double __im = 0.0L)
4430b57cec5SDimitry Andric        : __re_(__re), __im_(__im) {}
4440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4450b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR complex(const complex<float>& __c);
4460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4470b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR complex(const complex<double>& __c);
4480b57cec5SDimitry Andric
4490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double real() const {return __re_;}
4500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double imag() const {return __im_;}
4510b57cec5SDimitry Andric
452bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void real(value_type __re) {__re_ = __re;}
453bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void imag(value_type __im) {__im_ = __im;}
4540b57cec5SDimitry Andric
455bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator= (long double __re)
4560b57cec5SDimitry Andric        {__re_ = __re; __im_ = value_type(); return *this;}
457bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator+=(long double __re) {__re_ += __re; return *this;}
458bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator-=(long double __re) {__re_ -= __re; return *this;}
459bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator*=(long double __re) {__re_ *= __re; __im_ *= __re; return *this;}
460bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator/=(long double __re) {__re_ /= __re; __im_ /= __re; return *this;}
4610b57cec5SDimitry Andric
462bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator= (const complex<_Xp>& __c)
4630b57cec5SDimitry Andric        {
4640b57cec5SDimitry Andric            __re_ = __c.real();
4650b57cec5SDimitry Andric            __im_ = __c.imag();
4660b57cec5SDimitry Andric            return *this;
4670b57cec5SDimitry Andric        }
468bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator+=(const complex<_Xp>& __c)
4690b57cec5SDimitry Andric        {
4700b57cec5SDimitry Andric            __re_ += __c.real();
4710b57cec5SDimitry Andric            __im_ += __c.imag();
4720b57cec5SDimitry Andric            return *this;
4730b57cec5SDimitry Andric        }
474bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator-=(const complex<_Xp>& __c)
4750b57cec5SDimitry Andric        {
4760b57cec5SDimitry Andric            __re_ -= __c.real();
4770b57cec5SDimitry Andric            __im_ -= __c.imag();
4780b57cec5SDimitry Andric            return *this;
4790b57cec5SDimitry Andric        }
480bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator*=(const complex<_Xp>& __c)
4810b57cec5SDimitry Andric        {
4820b57cec5SDimitry Andric            *this = *this * complex(__c.real(), __c.imag());
4830b57cec5SDimitry Andric            return *this;
4840b57cec5SDimitry Andric        }
485bdd1243dSDimitry Andric    template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 complex& operator/=(const complex<_Xp>& __c)
4860b57cec5SDimitry Andric        {
4870b57cec5SDimitry Andric            *this = *this / complex(__c.real(), __c.imag());
4880b57cec5SDimitry Andric            return *this;
4890b57cec5SDimitry Andric        }
4900b57cec5SDimitry Andric};
4910b57cec5SDimitry Andric
4920b57cec5SDimitry Andricinline
4930b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
4940b57cec5SDimitry Andriccomplex<float>::complex(const complex<double>& __c)
4950b57cec5SDimitry Andric    : __re_(__c.real()), __im_(__c.imag()) {}
4960b57cec5SDimitry Andric
4970b57cec5SDimitry Andricinline
4980b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
4990b57cec5SDimitry Andriccomplex<float>::complex(const complex<long double>& __c)
5000b57cec5SDimitry Andric    : __re_(__c.real()), __im_(__c.imag()) {}
5010b57cec5SDimitry Andric
5020b57cec5SDimitry Andricinline
5030b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
5040b57cec5SDimitry Andriccomplex<double>::complex(const complex<float>& __c)
5050b57cec5SDimitry Andric    : __re_(__c.real()), __im_(__c.imag()) {}
5060b57cec5SDimitry Andric
5070b57cec5SDimitry Andricinline
5080b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
5090b57cec5SDimitry Andriccomplex<double>::complex(const complex<long double>& __c)
5100b57cec5SDimitry Andric    : __re_(__c.real()), __im_(__c.imag()) {}
5110b57cec5SDimitry Andric
5120b57cec5SDimitry Andricinline
5130b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
5140b57cec5SDimitry Andriccomplex<long double>::complex(const complex<float>& __c)
5150b57cec5SDimitry Andric    : __re_(__c.real()), __im_(__c.imag()) {}
5160b57cec5SDimitry Andric
5170b57cec5SDimitry Andricinline
5180b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
5190b57cec5SDimitry Andriccomplex<long double>::complex(const complex<double>& __c)
5200b57cec5SDimitry Andric    : __re_(__c.real()), __im_(__c.imag()) {}
5210b57cec5SDimitry Andric
5220b57cec5SDimitry Andric// 26.3.6 operators:
5230b57cec5SDimitry Andric
5240b57cec5SDimitry Andrictemplate<class _Tp>
525bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
5260b57cec5SDimitry Andriccomplex<_Tp>
5270b57cec5SDimitry Andricoperator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
5280b57cec5SDimitry Andric{
5290b57cec5SDimitry Andric    complex<_Tp> __t(__x);
5300b57cec5SDimitry Andric    __t += __y;
5310b57cec5SDimitry Andric    return __t;
5320b57cec5SDimitry Andric}
5330b57cec5SDimitry Andric
5340b57cec5SDimitry Andrictemplate<class _Tp>
535bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
5360b57cec5SDimitry Andriccomplex<_Tp>
5370b57cec5SDimitry Andricoperator+(const complex<_Tp>& __x, const _Tp& __y)
5380b57cec5SDimitry Andric{
5390b57cec5SDimitry Andric    complex<_Tp> __t(__x);
5400b57cec5SDimitry Andric    __t += __y;
5410b57cec5SDimitry Andric    return __t;
5420b57cec5SDimitry Andric}
5430b57cec5SDimitry Andric
5440b57cec5SDimitry Andrictemplate<class _Tp>
545bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
5460b57cec5SDimitry Andriccomplex<_Tp>
5470b57cec5SDimitry Andricoperator+(const _Tp& __x, const complex<_Tp>& __y)
5480b57cec5SDimitry Andric{
5490b57cec5SDimitry Andric    complex<_Tp> __t(__y);
5500b57cec5SDimitry Andric    __t += __x;
5510b57cec5SDimitry Andric    return __t;
5520b57cec5SDimitry Andric}
5530b57cec5SDimitry Andric
5540b57cec5SDimitry Andrictemplate<class _Tp>
555bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
5560b57cec5SDimitry Andriccomplex<_Tp>
5570b57cec5SDimitry Andricoperator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
5580b57cec5SDimitry Andric{
5590b57cec5SDimitry Andric    complex<_Tp> __t(__x);
5600b57cec5SDimitry Andric    __t -= __y;
5610b57cec5SDimitry Andric    return __t;
5620b57cec5SDimitry Andric}
5630b57cec5SDimitry Andric
5640b57cec5SDimitry Andrictemplate<class _Tp>
565bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
5660b57cec5SDimitry Andriccomplex<_Tp>
5670b57cec5SDimitry Andricoperator-(const complex<_Tp>& __x, const _Tp& __y)
5680b57cec5SDimitry Andric{
5690b57cec5SDimitry Andric    complex<_Tp> __t(__x);
5700b57cec5SDimitry Andric    __t -= __y;
5710b57cec5SDimitry Andric    return __t;
5720b57cec5SDimitry Andric}
5730b57cec5SDimitry Andric
5740b57cec5SDimitry Andrictemplate<class _Tp>
575bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
5760b57cec5SDimitry Andriccomplex<_Tp>
5770b57cec5SDimitry Andricoperator-(const _Tp& __x, const complex<_Tp>& __y)
5780b57cec5SDimitry Andric{
5790b57cec5SDimitry Andric    complex<_Tp> __t(-__y);
5800b57cec5SDimitry Andric    __t += __x;
5810b57cec5SDimitry Andric    return __t;
5820b57cec5SDimitry Andric}
5830b57cec5SDimitry Andric
5840b57cec5SDimitry Andrictemplate<class _Tp>
585bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 complex<_Tp>
5860b57cec5SDimitry Andricoperator*(const complex<_Tp>& __z, const complex<_Tp>& __w)
5870b57cec5SDimitry Andric{
5880b57cec5SDimitry Andric    _Tp __a = __z.real();
5890b57cec5SDimitry Andric    _Tp __b = __z.imag();
5900b57cec5SDimitry Andric    _Tp __c = __w.real();
5910b57cec5SDimitry Andric    _Tp __d = __w.imag();
592bdd1243dSDimitry Andric
593bdd1243dSDimitry Andric    // Avoid floating point operations that are invalid during constant evaluation
594bdd1243dSDimitry Andric    if (__libcpp_is_constant_evaluated()) {
595bdd1243dSDimitry Andric        bool __z_zero = __a == _Tp(0) && __b == _Tp(0);
596bdd1243dSDimitry Andric        bool __w_zero = __c == _Tp(0) && __d == _Tp(0);
597bdd1243dSDimitry Andric        bool __z_inf = std::__constexpr_isinf(__a) || std::__constexpr_isinf(__b);
598bdd1243dSDimitry Andric        bool __w_inf = std::__constexpr_isinf(__c) || std::__constexpr_isinf(__d);
599bdd1243dSDimitry Andric        bool __z_nan = !__z_inf && (
600bdd1243dSDimitry Andric            (std::__constexpr_isnan(__a) && std::__constexpr_isnan(__b))
601bdd1243dSDimitry Andric            || (std::__constexpr_isnan(__a) && __b == _Tp(0))
602bdd1243dSDimitry Andric            || (__a == _Tp(0) && std::__constexpr_isnan(__b))
603bdd1243dSDimitry Andric        );
604bdd1243dSDimitry Andric        bool __w_nan = !__w_inf && (
605bdd1243dSDimitry Andric            (std::__constexpr_isnan(__c) && std::__constexpr_isnan(__d))
606bdd1243dSDimitry Andric            || (std::__constexpr_isnan(__c) && __d == _Tp(0))
607bdd1243dSDimitry Andric            || (__c == _Tp(0) && std::__constexpr_isnan(__d))
608bdd1243dSDimitry Andric        );
609bdd1243dSDimitry Andric        if (__z_nan || __w_nan) {
610bdd1243dSDimitry Andric            return complex<_Tp>(_Tp(numeric_limits<_Tp>::quiet_NaN()), _Tp(0));
611bdd1243dSDimitry Andric        }
612bdd1243dSDimitry Andric        if (__z_inf || __w_inf) {
613bdd1243dSDimitry Andric            if (__z_zero || __w_zero) {
614bdd1243dSDimitry Andric                return complex<_Tp>(_Tp(numeric_limits<_Tp>::quiet_NaN()), _Tp(0));
615bdd1243dSDimitry Andric            }
616bdd1243dSDimitry Andric            return complex<_Tp>(_Tp(numeric_limits<_Tp>::infinity()), _Tp(numeric_limits<_Tp>::infinity()));
617bdd1243dSDimitry Andric        }
618bdd1243dSDimitry Andric        bool __z_nonzero_nan = !__z_inf && !__z_nan && (std::__constexpr_isnan(__a) || std::__constexpr_isnan(__b));
619bdd1243dSDimitry Andric        bool __w_nonzero_nan = !__w_inf && !__w_nan && (std::__constexpr_isnan(__c) || std::__constexpr_isnan(__d));
620bdd1243dSDimitry Andric        if (__z_nonzero_nan || __w_nonzero_nan) {
621bdd1243dSDimitry Andric            return complex<_Tp>(_Tp(numeric_limits<_Tp>::quiet_NaN()), _Tp(0));
622bdd1243dSDimitry Andric        }
623bdd1243dSDimitry Andric    }
624bdd1243dSDimitry Andric
6250b57cec5SDimitry Andric    _Tp __ac = __a * __c;
6260b57cec5SDimitry Andric    _Tp __bd = __b * __d;
6270b57cec5SDimitry Andric    _Tp __ad = __a * __d;
6280b57cec5SDimitry Andric    _Tp __bc = __b * __c;
6290b57cec5SDimitry Andric    _Tp __x = __ac - __bd;
6300b57cec5SDimitry Andric    _Tp __y = __ad + __bc;
631bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__x) && std::__constexpr_isnan(__y))
6320b57cec5SDimitry Andric    {
6330b57cec5SDimitry Andric        bool __recalc = false;
634bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__a) || std::__constexpr_isinf(__b))
6350b57cec5SDimitry Andric        {
636bdd1243dSDimitry Andric            __a = std::__constexpr_copysign(std::__constexpr_isinf(__a) ? _Tp(1) : _Tp(0), __a);
637bdd1243dSDimitry Andric            __b = std::__constexpr_copysign(std::__constexpr_isinf(__b) ? _Tp(1) : _Tp(0), __b);
638bdd1243dSDimitry Andric            if (std::__constexpr_isnan(__c))
639bdd1243dSDimitry Andric                __c = std::__constexpr_copysign(_Tp(0), __c);
640bdd1243dSDimitry Andric            if (std::__constexpr_isnan(__d))
641bdd1243dSDimitry Andric                __d = std::__constexpr_copysign(_Tp(0), __d);
6420b57cec5SDimitry Andric            __recalc = true;
6430b57cec5SDimitry Andric        }
644bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__c) || std::__constexpr_isinf(__d))
6450b57cec5SDimitry Andric        {
646bdd1243dSDimitry Andric            __c = std::__constexpr_copysign(std::__constexpr_isinf(__c) ? _Tp(1) : _Tp(0), __c);
647bdd1243dSDimitry Andric            __d = std::__constexpr_copysign(std::__constexpr_isinf(__d) ? _Tp(1) : _Tp(0), __d);
648bdd1243dSDimitry Andric            if (std::__constexpr_isnan(__a))
649bdd1243dSDimitry Andric                __a = std::__constexpr_copysign(_Tp(0), __a);
650bdd1243dSDimitry Andric            if (std::__constexpr_isnan(__b))
651bdd1243dSDimitry Andric                __b = std::__constexpr_copysign(_Tp(0), __b);
6520b57cec5SDimitry Andric            __recalc = true;
6530b57cec5SDimitry Andric        }
654bdd1243dSDimitry Andric        if (!__recalc && (std::__constexpr_isinf(__ac) || std::__constexpr_isinf(__bd) ||
655bdd1243dSDimitry Andric                          std::__constexpr_isinf(__ad) || std::__constexpr_isinf(__bc)))
6560b57cec5SDimitry Andric        {
657bdd1243dSDimitry Andric            if (std::__constexpr_isnan(__a))
658bdd1243dSDimitry Andric                __a = std::__constexpr_copysign(_Tp(0), __a);
659bdd1243dSDimitry Andric            if (std::__constexpr_isnan(__b))
660bdd1243dSDimitry Andric                __b = std::__constexpr_copysign(_Tp(0), __b);
661bdd1243dSDimitry Andric            if (std::__constexpr_isnan(__c))
662bdd1243dSDimitry Andric                __c = std::__constexpr_copysign(_Tp(0), __c);
663bdd1243dSDimitry Andric            if (std::__constexpr_isnan(__d))
664bdd1243dSDimitry Andric                __d = std::__constexpr_copysign(_Tp(0), __d);
6650b57cec5SDimitry Andric            __recalc = true;
6660b57cec5SDimitry Andric        }
6670b57cec5SDimitry Andric        if (__recalc)
6680b57cec5SDimitry Andric        {
6690b57cec5SDimitry Andric            __x = _Tp(INFINITY) * (__a * __c - __b * __d);
6700b57cec5SDimitry Andric            __y = _Tp(INFINITY) * (__a * __d + __b * __c);
6710b57cec5SDimitry Andric        }
6720b57cec5SDimitry Andric    }
6730b57cec5SDimitry Andric    return complex<_Tp>(__x, __y);
6740b57cec5SDimitry Andric}
6750b57cec5SDimitry Andric
6760b57cec5SDimitry Andrictemplate<class _Tp>
677bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
6780b57cec5SDimitry Andriccomplex<_Tp>
6790b57cec5SDimitry Andricoperator*(const complex<_Tp>& __x, const _Tp& __y)
6800b57cec5SDimitry Andric{
6810b57cec5SDimitry Andric    complex<_Tp> __t(__x);
6820b57cec5SDimitry Andric    __t *= __y;
6830b57cec5SDimitry Andric    return __t;
6840b57cec5SDimitry Andric}
6850b57cec5SDimitry Andric
6860b57cec5SDimitry Andrictemplate<class _Tp>
687bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
6880b57cec5SDimitry Andriccomplex<_Tp>
6890b57cec5SDimitry Andricoperator*(const _Tp& __x, const complex<_Tp>& __y)
6900b57cec5SDimitry Andric{
6910b57cec5SDimitry Andric    complex<_Tp> __t(__y);
6920b57cec5SDimitry Andric    __t *= __x;
6930b57cec5SDimitry Andric    return __t;
6940b57cec5SDimitry Andric}
6950b57cec5SDimitry Andric
6960b57cec5SDimitry Andrictemplate<class _Tp>
697bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 complex<_Tp>
6980b57cec5SDimitry Andricoperator/(const complex<_Tp>& __z, const complex<_Tp>& __w)
6990b57cec5SDimitry Andric{
7000b57cec5SDimitry Andric    int __ilogbw = 0;
7010b57cec5SDimitry Andric    _Tp __a = __z.real();
7020b57cec5SDimitry Andric    _Tp __b = __z.imag();
7030b57cec5SDimitry Andric    _Tp __c = __w.real();
7040b57cec5SDimitry Andric    _Tp __d = __w.imag();
705bdd1243dSDimitry Andric    _Tp __logbw = std::__constexpr_logb(std::__constexpr_fmax(std::__constexpr_fabs(__c), std::__constexpr_fabs(__d)));
706bdd1243dSDimitry Andric    if (std::__constexpr_isfinite(__logbw))
7070b57cec5SDimitry Andric    {
7080b57cec5SDimitry Andric        __ilogbw = static_cast<int>(__logbw);
709bdd1243dSDimitry Andric        __c = std::__constexpr_scalbn(__c, -__ilogbw);
710bdd1243dSDimitry Andric        __d = std::__constexpr_scalbn(__d, -__ilogbw);
7110b57cec5SDimitry Andric    }
712bdd1243dSDimitry Andric
713bdd1243dSDimitry Andric    // Avoid floating point operations that are invalid during constant evaluation
714bdd1243dSDimitry Andric    if (__libcpp_is_constant_evaluated()) {
715bdd1243dSDimitry Andric        bool __z_zero = __a == _Tp(0) && __b == _Tp(0);
716bdd1243dSDimitry Andric        bool __w_zero = __c == _Tp(0) && __d == _Tp(0);
717bdd1243dSDimitry Andric        bool __z_inf = std::__constexpr_isinf(__a) || std::__constexpr_isinf(__b);
718bdd1243dSDimitry Andric        bool __w_inf = std::__constexpr_isinf(__c) || std::__constexpr_isinf(__d);
719bdd1243dSDimitry Andric        bool __z_nan = !__z_inf && (
720bdd1243dSDimitry Andric            (std::__constexpr_isnan(__a) && std::__constexpr_isnan(__b))
721bdd1243dSDimitry Andric            || (std::__constexpr_isnan(__a) && __b == _Tp(0))
722bdd1243dSDimitry Andric            || (__a == _Tp(0) && std::__constexpr_isnan(__b))
723bdd1243dSDimitry Andric        );
724bdd1243dSDimitry Andric        bool __w_nan = !__w_inf && (
725bdd1243dSDimitry Andric            (std::__constexpr_isnan(__c) && std::__constexpr_isnan(__d))
726bdd1243dSDimitry Andric            || (std::__constexpr_isnan(__c) && __d == _Tp(0))
727bdd1243dSDimitry Andric            || (__c == _Tp(0) && std::__constexpr_isnan(__d))
728bdd1243dSDimitry Andric        );
729bdd1243dSDimitry Andric        if ((__z_nan || __w_nan) || (__z_inf && __w_inf)) {
730bdd1243dSDimitry Andric            return complex<_Tp>(_Tp(numeric_limits<_Tp>::quiet_NaN()), _Tp(0));
731bdd1243dSDimitry Andric        }
732bdd1243dSDimitry Andric        bool __z_nonzero_nan = !__z_inf && !__z_nan && (std::__constexpr_isnan(__a) || std::__constexpr_isnan(__b));
733bdd1243dSDimitry Andric        bool __w_nonzero_nan = !__w_inf && !__w_nan && (std::__constexpr_isnan(__c) || std::__constexpr_isnan(__d));
734bdd1243dSDimitry Andric        if (__z_nonzero_nan || __w_nonzero_nan) {
735bdd1243dSDimitry Andric            if (__w_zero) {
736bdd1243dSDimitry Andric                return complex<_Tp>(_Tp(numeric_limits<_Tp>::infinity()), _Tp(numeric_limits<_Tp>::infinity()));
737bdd1243dSDimitry Andric            }
738bdd1243dSDimitry Andric            return complex<_Tp>(_Tp(numeric_limits<_Tp>::quiet_NaN()), _Tp(0));
739bdd1243dSDimitry Andric        }
740bdd1243dSDimitry Andric        if (__w_inf) {
741bdd1243dSDimitry Andric            return complex<_Tp>(_Tp(0), _Tp(0));
742bdd1243dSDimitry Andric        }
743bdd1243dSDimitry Andric        if (__z_inf) {
744bdd1243dSDimitry Andric            return complex<_Tp>(_Tp(numeric_limits<_Tp>::infinity()), _Tp(numeric_limits<_Tp>::infinity()));
745bdd1243dSDimitry Andric        }
746bdd1243dSDimitry Andric        if (__w_zero) {
747bdd1243dSDimitry Andric            if (__z_zero) {
748bdd1243dSDimitry Andric                return complex<_Tp>(_Tp(numeric_limits<_Tp>::quiet_NaN()), _Tp(0));
749bdd1243dSDimitry Andric            }
750bdd1243dSDimitry Andric            return complex<_Tp>(_Tp(numeric_limits<_Tp>::infinity()), _Tp(numeric_limits<_Tp>::infinity()));
751bdd1243dSDimitry Andric        }
752bdd1243dSDimitry Andric    }
753bdd1243dSDimitry Andric
7540b57cec5SDimitry Andric    _Tp __denom = __c * __c + __d * __d;
755bdd1243dSDimitry Andric    _Tp __x = std::__constexpr_scalbn((__a * __c + __b * __d) / __denom, -__ilogbw);
756bdd1243dSDimitry Andric    _Tp __y = std::__constexpr_scalbn((__b * __c - __a * __d) / __denom, -__ilogbw);
757bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__x) && std::__constexpr_isnan(__y))
7580b57cec5SDimitry Andric    {
759bdd1243dSDimitry Andric        if ((__denom == _Tp(0)) && (!std::__constexpr_isnan(__a) || !std::__constexpr_isnan(__b)))
7600b57cec5SDimitry Andric        {
761bdd1243dSDimitry Andric            __x = std::__constexpr_copysign(_Tp(INFINITY), __c) * __a;
762bdd1243dSDimitry Andric            __y = std::__constexpr_copysign(_Tp(INFINITY), __c) * __b;
763bdd1243dSDimitry Andric        } else if ((std::__constexpr_isinf(__a) || std::__constexpr_isinf(__b)) && std::__constexpr_isfinite(__c) &&
764bdd1243dSDimitry Andric                   std::__constexpr_isfinite(__d)) {
765bdd1243dSDimitry Andric            __a = std::__constexpr_copysign(std::__constexpr_isinf(__a) ? _Tp(1) : _Tp(0), __a);
766bdd1243dSDimitry Andric            __b = std::__constexpr_copysign(std::__constexpr_isinf(__b) ? _Tp(1) : _Tp(0), __b);
7670b57cec5SDimitry Andric            __x = _Tp(INFINITY) * (__a * __c + __b * __d);
7680b57cec5SDimitry Andric            __y = _Tp(INFINITY) * (__b * __c - __a * __d);
769bdd1243dSDimitry Andric        } else if (std::__constexpr_isinf(__logbw) && __logbw > _Tp(0) && std::__constexpr_isfinite(__a) &&
770bdd1243dSDimitry Andric                   std::__constexpr_isfinite(__b)) {
771bdd1243dSDimitry Andric            __c = std::__constexpr_copysign(std::__constexpr_isinf(__c) ? _Tp(1) : _Tp(0), __c);
772bdd1243dSDimitry Andric            __d = std::__constexpr_copysign(std::__constexpr_isinf(__d) ? _Tp(1) : _Tp(0), __d);
7730b57cec5SDimitry Andric            __x = _Tp(0) * (__a * __c + __b * __d);
7740b57cec5SDimitry Andric            __y = _Tp(0) * (__b * __c - __a * __d);
7750b57cec5SDimitry Andric        }
7760b57cec5SDimitry Andric    }
7770b57cec5SDimitry Andric    return complex<_Tp>(__x, __y);
7780b57cec5SDimitry Andric}
7790b57cec5SDimitry Andric
7800b57cec5SDimitry Andrictemplate<class _Tp>
781bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
7820b57cec5SDimitry Andriccomplex<_Tp>
7830b57cec5SDimitry Andricoperator/(const complex<_Tp>& __x, const _Tp& __y)
7840b57cec5SDimitry Andric{
7850b57cec5SDimitry Andric    return complex<_Tp>(__x.real() / __y, __x.imag() / __y);
7860b57cec5SDimitry Andric}
7870b57cec5SDimitry Andric
7880b57cec5SDimitry Andrictemplate<class _Tp>
789bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
7900b57cec5SDimitry Andriccomplex<_Tp>
7910b57cec5SDimitry Andricoperator/(const _Tp& __x, const complex<_Tp>& __y)
7920b57cec5SDimitry Andric{
7930b57cec5SDimitry Andric    complex<_Tp> __t(__x);
7940b57cec5SDimitry Andric    __t /= __y;
7950b57cec5SDimitry Andric    return __t;
7960b57cec5SDimitry Andric}
7970b57cec5SDimitry Andric
7980b57cec5SDimitry Andrictemplate<class _Tp>
799bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
8000b57cec5SDimitry Andriccomplex<_Tp>
8010b57cec5SDimitry Andricoperator+(const complex<_Tp>& __x)
8020b57cec5SDimitry Andric{
8030b57cec5SDimitry Andric    return __x;
8040b57cec5SDimitry Andric}
8050b57cec5SDimitry Andric
8060b57cec5SDimitry Andrictemplate<class _Tp>
807bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
8080b57cec5SDimitry Andriccomplex<_Tp>
8090b57cec5SDimitry Andricoperator-(const complex<_Tp>& __x)
8100b57cec5SDimitry Andric{
8110b57cec5SDimitry Andric    return complex<_Tp>(-__x.real(), -__x.imag());
8120b57cec5SDimitry Andric}
8130b57cec5SDimitry Andric
8140b57cec5SDimitry Andrictemplate<class _Tp>
815bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
8160b57cec5SDimitry Andricbool
8170b57cec5SDimitry Andricoperator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
8180b57cec5SDimitry Andric{
8190b57cec5SDimitry Andric    return __x.real() == __y.real() && __x.imag() == __y.imag();
8200b57cec5SDimitry Andric}
8210b57cec5SDimitry Andric
8220b57cec5SDimitry Andrictemplate<class _Tp>
823bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
8240b57cec5SDimitry Andricbool
8250b57cec5SDimitry Andricoperator==(const complex<_Tp>& __x, const _Tp& __y)
8260b57cec5SDimitry Andric{
8270b57cec5SDimitry Andric    return __x.real() == __y && __x.imag() == 0;
8280b57cec5SDimitry Andric}
8290b57cec5SDimitry Andric
830*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17
831*06c3fb27SDimitry Andric
8320b57cec5SDimitry Andrictemplate<class _Tp>
833bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
8340b57cec5SDimitry Andricbool
8350b57cec5SDimitry Andricoperator==(const _Tp& __x, const complex<_Tp>& __y)
8360b57cec5SDimitry Andric{
8370b57cec5SDimitry Andric    return __x == __y.real() && 0 == __y.imag();
8380b57cec5SDimitry Andric}
8390b57cec5SDimitry Andric
8400b57cec5SDimitry Andrictemplate<class _Tp>
841bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
8420b57cec5SDimitry Andricbool
8430b57cec5SDimitry Andricoperator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
8440b57cec5SDimitry Andric{
8450b57cec5SDimitry Andric    return !(__x == __y);
8460b57cec5SDimitry Andric}
8470b57cec5SDimitry Andric
8480b57cec5SDimitry Andrictemplate<class _Tp>
849bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
8500b57cec5SDimitry Andricbool
8510b57cec5SDimitry Andricoperator!=(const complex<_Tp>& __x, const _Tp& __y)
8520b57cec5SDimitry Andric{
8530b57cec5SDimitry Andric    return !(__x == __y);
8540b57cec5SDimitry Andric}
8550b57cec5SDimitry Andric
8560b57cec5SDimitry Andrictemplate<class _Tp>
857bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
8580b57cec5SDimitry Andricbool
8590b57cec5SDimitry Andricoperator!=(const _Tp& __x, const complex<_Tp>& __y)
8600b57cec5SDimitry Andric{
8610b57cec5SDimitry Andric    return !(__x == __y);
8620b57cec5SDimitry Andric}
8630b57cec5SDimitry Andric
864*06c3fb27SDimitry Andric#endif
865*06c3fb27SDimitry Andric
8660b57cec5SDimitry Andric// 26.3.7 values:
8670b57cec5SDimitry Andric
8680b57cec5SDimitry Andrictemplate <class _Tp, bool = is_integral<_Tp>::value,
8690b57cec5SDimitry Andric                     bool = is_floating_point<_Tp>::value
8700b57cec5SDimitry Andric                     >
8710b57cec5SDimitry Andricstruct __libcpp_complex_overload_traits {};
8720b57cec5SDimitry Andric
8730b57cec5SDimitry Andric// Integral Types
8740b57cec5SDimitry Andrictemplate <class _Tp>
8750b57cec5SDimitry Andricstruct __libcpp_complex_overload_traits<_Tp, true, false>
8760b57cec5SDimitry Andric{
8770b57cec5SDimitry Andric    typedef double _ValueType;
8780b57cec5SDimitry Andric    typedef complex<double> _ComplexType;
8790b57cec5SDimitry Andric};
8800b57cec5SDimitry Andric
8810b57cec5SDimitry Andric// Floating point types
8820b57cec5SDimitry Andrictemplate <class _Tp>
8830b57cec5SDimitry Andricstruct __libcpp_complex_overload_traits<_Tp, false, true>
8840b57cec5SDimitry Andric{
8850b57cec5SDimitry Andric    typedef _Tp _ValueType;
8860b57cec5SDimitry Andric    typedef complex<_Tp> _ComplexType;
8870b57cec5SDimitry Andric};
8880b57cec5SDimitry Andric
8890b57cec5SDimitry Andric// real
8900b57cec5SDimitry Andric
8910b57cec5SDimitry Andrictemplate<class _Tp>
892bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
8930b57cec5SDimitry Andric_Tp
8940b57cec5SDimitry Andricreal(const complex<_Tp>& __c)
8950b57cec5SDimitry Andric{
8960b57cec5SDimitry Andric    return __c.real();
8970b57cec5SDimitry Andric}
8980b57cec5SDimitry Andric
8990b57cec5SDimitry Andrictemplate <class _Tp>
900bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
9010b57cec5SDimitry Andrictypename __libcpp_complex_overload_traits<_Tp>::_ValueType
9020b57cec5SDimitry Andricreal(_Tp __re)
9030b57cec5SDimitry Andric{
9040b57cec5SDimitry Andric    return __re;
9050b57cec5SDimitry Andric}
9060b57cec5SDimitry Andric
9070b57cec5SDimitry Andric// imag
9080b57cec5SDimitry Andric
9090b57cec5SDimitry Andrictemplate<class _Tp>
910bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
9110b57cec5SDimitry Andric_Tp
9120b57cec5SDimitry Andricimag(const complex<_Tp>& __c)
9130b57cec5SDimitry Andric{
9140b57cec5SDimitry Andric    return __c.imag();
9150b57cec5SDimitry Andric}
9160b57cec5SDimitry Andric
9170b57cec5SDimitry Andrictemplate <class _Tp>
918bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
9190b57cec5SDimitry Andrictypename __libcpp_complex_overload_traits<_Tp>::_ValueType
9200b57cec5SDimitry Andricimag(_Tp)
9210b57cec5SDimitry Andric{
9220b57cec5SDimitry Andric    return 0;
9230b57cec5SDimitry Andric}
9240b57cec5SDimitry Andric
9250b57cec5SDimitry Andric// abs
9260b57cec5SDimitry Andric
9270b57cec5SDimitry Andrictemplate<class _Tp>
9280b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9290b57cec5SDimitry Andric_Tp
9300b57cec5SDimitry Andricabs(const complex<_Tp>& __c)
9310b57cec5SDimitry Andric{
932bdd1243dSDimitry Andric    return std::hypot(__c.real(), __c.imag());
9330b57cec5SDimitry Andric}
9340b57cec5SDimitry Andric
9350b57cec5SDimitry Andric// arg
9360b57cec5SDimitry Andric
9370b57cec5SDimitry Andrictemplate<class _Tp>
9380b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9390b57cec5SDimitry Andric_Tp
9400b57cec5SDimitry Andricarg(const complex<_Tp>& __c)
9410b57cec5SDimitry Andric{
942bdd1243dSDimitry Andric    return std::atan2(__c.imag(), __c.real());
9430b57cec5SDimitry Andric}
9440b57cec5SDimitry Andric
9450b57cec5SDimitry Andrictemplate <class _Tp>
9460b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9470b57cec5SDimitry Andrictypename enable_if<
9480b57cec5SDimitry Andric    is_same<_Tp, long double>::value,
9490b57cec5SDimitry Andric    long double
9500b57cec5SDimitry Andric>::type
9510b57cec5SDimitry Andricarg(_Tp __re)
9520b57cec5SDimitry Andric{
953bdd1243dSDimitry Andric    return std::atan2l(0.L, __re);
9540b57cec5SDimitry Andric}
9550b57cec5SDimitry Andric
9560b57cec5SDimitry Andrictemplate<class _Tp>
9570b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9580b57cec5SDimitry Andrictypename enable_if
9590b57cec5SDimitry Andric<
9600b57cec5SDimitry Andric    is_integral<_Tp>::value || is_same<_Tp, double>::value,
9610b57cec5SDimitry Andric    double
9620b57cec5SDimitry Andric>::type
9630b57cec5SDimitry Andricarg(_Tp __re)
9640b57cec5SDimitry Andric{
965bdd1243dSDimitry Andric    return std::atan2(0., __re);
9660b57cec5SDimitry Andric}
9670b57cec5SDimitry Andric
9680b57cec5SDimitry Andrictemplate <class _Tp>
9690b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9700b57cec5SDimitry Andrictypename enable_if<
9710b57cec5SDimitry Andric    is_same<_Tp, float>::value,
9720b57cec5SDimitry Andric    float
9730b57cec5SDimitry Andric>::type
9740b57cec5SDimitry Andricarg(_Tp __re)
9750b57cec5SDimitry Andric{
976bdd1243dSDimitry Andric    return std::atan2f(0.F, __re);
9770b57cec5SDimitry Andric}
9780b57cec5SDimitry Andric
9790b57cec5SDimitry Andric// norm
9800b57cec5SDimitry Andric
9810b57cec5SDimitry Andrictemplate<class _Tp>
982bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
9830b57cec5SDimitry Andric_Tp
9840b57cec5SDimitry Andricnorm(const complex<_Tp>& __c)
9850b57cec5SDimitry Andric{
986bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__c.real()))
987bdd1243dSDimitry Andric        return std::abs(__c.real());
988bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__c.imag()))
989bdd1243dSDimitry Andric        return std::abs(__c.imag());
9900b57cec5SDimitry Andric    return __c.real() * __c.real() + __c.imag() * __c.imag();
9910b57cec5SDimitry Andric}
9920b57cec5SDimitry Andric
9930b57cec5SDimitry Andrictemplate <class _Tp>
994bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
9950b57cec5SDimitry Andrictypename __libcpp_complex_overload_traits<_Tp>::_ValueType
9960b57cec5SDimitry Andricnorm(_Tp __re)
9970b57cec5SDimitry Andric{
9980b57cec5SDimitry Andric    typedef typename __libcpp_complex_overload_traits<_Tp>::_ValueType _ValueType;
9990b57cec5SDimitry Andric    return static_cast<_ValueType>(__re) * __re;
10000b57cec5SDimitry Andric}
10010b57cec5SDimitry Andric
10020b57cec5SDimitry Andric// conj
10030b57cec5SDimitry Andric
10040b57cec5SDimitry Andrictemplate<class _Tp>
1005bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
10060b57cec5SDimitry Andriccomplex<_Tp>
10070b57cec5SDimitry Andricconj(const complex<_Tp>& __c)
10080b57cec5SDimitry Andric{
10090b57cec5SDimitry Andric    return complex<_Tp>(__c.real(), -__c.imag());
10100b57cec5SDimitry Andric}
10110b57cec5SDimitry Andric
10120b57cec5SDimitry Andrictemplate <class _Tp>
1013bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
10140b57cec5SDimitry Andrictypename __libcpp_complex_overload_traits<_Tp>::_ComplexType
10150b57cec5SDimitry Andricconj(_Tp __re)
10160b57cec5SDimitry Andric{
10170b57cec5SDimitry Andric    typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType;
10180b57cec5SDimitry Andric    return _ComplexType(__re);
10190b57cec5SDimitry Andric}
10200b57cec5SDimitry Andric
10210b57cec5SDimitry Andric
10220b57cec5SDimitry Andric
10230b57cec5SDimitry Andric// proj
10240b57cec5SDimitry Andric
10250b57cec5SDimitry Andrictemplate<class _Tp>
10260b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
10270b57cec5SDimitry Andriccomplex<_Tp>
10280b57cec5SDimitry Andricproj(const complex<_Tp>& __c)
10290b57cec5SDimitry Andric{
1030e8d8bef9SDimitry Andric    complex<_Tp> __r = __c;
1031bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__c.real()) || std::__constexpr_isinf(__c.imag()))
1032bdd1243dSDimitry Andric        __r = complex<_Tp>(INFINITY, std::copysign(_Tp(0), __c.imag()));
10330b57cec5SDimitry Andric    return __r;
10340b57cec5SDimitry Andric}
10350b57cec5SDimitry Andric
10360b57cec5SDimitry Andrictemplate <class _Tp>
10370b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
10380b57cec5SDimitry Andrictypename enable_if
10390b57cec5SDimitry Andric<
10400b57cec5SDimitry Andric    is_floating_point<_Tp>::value,
10410b57cec5SDimitry Andric    typename __libcpp_complex_overload_traits<_Tp>::_ComplexType
10420b57cec5SDimitry Andric>::type
10430b57cec5SDimitry Andricproj(_Tp __re)
10440b57cec5SDimitry Andric{
1045bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__re))
1046bdd1243dSDimitry Andric        __re = std::abs(__re);
10470b57cec5SDimitry Andric    return complex<_Tp>(__re);
10480b57cec5SDimitry Andric}
10490b57cec5SDimitry Andric
10500b57cec5SDimitry Andrictemplate <class _Tp>
10510b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
10520b57cec5SDimitry Andrictypename enable_if
10530b57cec5SDimitry Andric<
10540b57cec5SDimitry Andric    is_integral<_Tp>::value,
10550b57cec5SDimitry Andric    typename __libcpp_complex_overload_traits<_Tp>::_ComplexType
10560b57cec5SDimitry Andric>::type
10570b57cec5SDimitry Andricproj(_Tp __re)
10580b57cec5SDimitry Andric{
10590b57cec5SDimitry Andric    typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType;
10600b57cec5SDimitry Andric    return _ComplexType(__re);
10610b57cec5SDimitry Andric}
10620b57cec5SDimitry Andric
10630b57cec5SDimitry Andric// polar
10640b57cec5SDimitry Andric
10650b57cec5SDimitry Andrictemplate<class _Tp>
1066bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
10670b57cec5SDimitry Andricpolar(const _Tp& __rho, const _Tp& __theta = _Tp())
10680b57cec5SDimitry Andric{
1069bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__rho) || std::signbit(__rho))
10700b57cec5SDimitry Andric        return complex<_Tp>(_Tp(NAN), _Tp(NAN));
1071bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__theta))
10720b57cec5SDimitry Andric    {
1073bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__rho))
10740b57cec5SDimitry Andric            return complex<_Tp>(__rho, __theta);
10750b57cec5SDimitry Andric        return complex<_Tp>(__theta, __theta);
10760b57cec5SDimitry Andric    }
1077bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__theta))
10780b57cec5SDimitry Andric    {
1079bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__rho))
10800b57cec5SDimitry Andric            return complex<_Tp>(__rho, _Tp(NAN));
10810b57cec5SDimitry Andric        return complex<_Tp>(_Tp(NAN), _Tp(NAN));
10820b57cec5SDimitry Andric    }
1083bdd1243dSDimitry Andric    _Tp __x = __rho * std::cos(__theta);
1084bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__x))
10850b57cec5SDimitry Andric        __x = 0;
1086bdd1243dSDimitry Andric    _Tp __y = __rho * std::sin(__theta);
1087bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__y))
10880b57cec5SDimitry Andric        __y = 0;
10890b57cec5SDimitry Andric    return complex<_Tp>(__x, __y);
10900b57cec5SDimitry Andric}
10910b57cec5SDimitry Andric
10920b57cec5SDimitry Andric// log
10930b57cec5SDimitry Andric
10940b57cec5SDimitry Andrictemplate<class _Tp>
10950b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
10960b57cec5SDimitry Andriccomplex<_Tp>
10970b57cec5SDimitry Andriclog(const complex<_Tp>& __x)
10980b57cec5SDimitry Andric{
1099bdd1243dSDimitry Andric    return complex<_Tp>(std::log(std::abs(__x)), std::arg(__x));
11000b57cec5SDimitry Andric}
11010b57cec5SDimitry Andric
11020b57cec5SDimitry Andric// log10
11030b57cec5SDimitry Andric
11040b57cec5SDimitry Andrictemplate<class _Tp>
11050b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
11060b57cec5SDimitry Andriccomplex<_Tp>
11070b57cec5SDimitry Andriclog10(const complex<_Tp>& __x)
11080b57cec5SDimitry Andric{
1109bdd1243dSDimitry Andric    return std::log(__x) / std::log(_Tp(10));
11100b57cec5SDimitry Andric}
11110b57cec5SDimitry Andric
11120b57cec5SDimitry Andric// sqrt
11130b57cec5SDimitry Andric
11140b57cec5SDimitry Andrictemplate<class _Tp>
1115bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
11160b57cec5SDimitry Andricsqrt(const complex<_Tp>& __x)
11170b57cec5SDimitry Andric{
1118bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.imag()))
11190b57cec5SDimitry Andric        return complex<_Tp>(_Tp(INFINITY), __x.imag());
1120bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.real()))
11210b57cec5SDimitry Andric    {
11220b57cec5SDimitry Andric        if (__x.real() > _Tp(0))
1123bdd1243dSDimitry Andric            return complex<_Tp>(__x.real(), std::__constexpr_isnan(__x.imag()) ? __x.imag() : std::copysign(_Tp(0), __x.imag()));
1124bdd1243dSDimitry Andric        return complex<_Tp>(std::__constexpr_isnan(__x.imag()) ? __x.imag() : _Tp(0), std::copysign(__x.real(), __x.imag()));
11250b57cec5SDimitry Andric    }
1126bdd1243dSDimitry Andric    return std::polar(std::sqrt(std::abs(__x)), std::arg(__x) / _Tp(2));
11270b57cec5SDimitry Andric}
11280b57cec5SDimitry Andric
11290b57cec5SDimitry Andric// exp
11300b57cec5SDimitry Andric
11310b57cec5SDimitry Andrictemplate<class _Tp>
1132bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
11330b57cec5SDimitry Andricexp(const complex<_Tp>& __x)
11340b57cec5SDimitry Andric{
11350b57cec5SDimitry Andric    _Tp __i = __x.imag();
1136349cc55cSDimitry Andric    if (__i == 0) {
1137bdd1243dSDimitry Andric        return complex<_Tp>(std::exp(__x.real()), std::copysign(_Tp(0), __x.imag()));
1138349cc55cSDimitry Andric    }
1139bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.real()))
11400b57cec5SDimitry Andric    {
11410b57cec5SDimitry Andric        if (__x.real() < _Tp(0))
11420b57cec5SDimitry Andric        {
1143bdd1243dSDimitry Andric            if (!std::__constexpr_isfinite(__i))
11440b57cec5SDimitry Andric                __i = _Tp(1);
11450b57cec5SDimitry Andric        }
1146bdd1243dSDimitry Andric        else if (__i == 0 || !std::__constexpr_isfinite(__i))
11470b57cec5SDimitry Andric        {
1148bdd1243dSDimitry Andric            if (std::__constexpr_isinf(__i))
11490b57cec5SDimitry Andric                __i = _Tp(NAN);
11500b57cec5SDimitry Andric            return complex<_Tp>(__x.real(), __i);
11510b57cec5SDimitry Andric        }
11520b57cec5SDimitry Andric    }
1153bdd1243dSDimitry Andric    _Tp __e = std::exp(__x.real());
1154bdd1243dSDimitry Andric    return complex<_Tp>(__e * std::cos(__i), __e * std::sin(__i));
11550b57cec5SDimitry Andric}
11560b57cec5SDimitry Andric
11570b57cec5SDimitry Andric// pow
11580b57cec5SDimitry Andric
11590b57cec5SDimitry Andrictemplate<class _Tp>
11600b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
11610b57cec5SDimitry Andriccomplex<_Tp>
11620b57cec5SDimitry Andricpow(const complex<_Tp>& __x, const complex<_Tp>& __y)
11630b57cec5SDimitry Andric{
1164bdd1243dSDimitry Andric    return std::exp(__y * std::log(__x));
11650b57cec5SDimitry Andric}
11660b57cec5SDimitry Andric
11670b57cec5SDimitry Andrictemplate<class _Tp, class _Up>
11680b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
11690b57cec5SDimitry Andriccomplex<typename __promote<_Tp, _Up>::type>
11700b57cec5SDimitry Andricpow(const complex<_Tp>& __x, const complex<_Up>& __y)
11710b57cec5SDimitry Andric{
11720b57cec5SDimitry Andric    typedef complex<typename __promote<_Tp, _Up>::type> result_type;
11730b57cec5SDimitry Andric    return _VSTD::pow(result_type(__x), result_type(__y));
11740b57cec5SDimitry Andric}
11750b57cec5SDimitry Andric
11760b57cec5SDimitry Andrictemplate<class _Tp, class _Up>
11770b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
11780b57cec5SDimitry Andrictypename enable_if
11790b57cec5SDimitry Andric<
11800b57cec5SDimitry Andric    is_arithmetic<_Up>::value,
11810b57cec5SDimitry Andric    complex<typename __promote<_Tp, _Up>::type>
11820b57cec5SDimitry Andric>::type
11830b57cec5SDimitry Andricpow(const complex<_Tp>& __x, const _Up& __y)
11840b57cec5SDimitry Andric{
11850b57cec5SDimitry Andric    typedef complex<typename __promote<_Tp, _Up>::type> result_type;
11860b57cec5SDimitry Andric    return _VSTD::pow(result_type(__x), result_type(__y));
11870b57cec5SDimitry Andric}
11880b57cec5SDimitry Andric
11890b57cec5SDimitry Andrictemplate<class _Tp, class _Up>
11900b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
11910b57cec5SDimitry Andrictypename enable_if
11920b57cec5SDimitry Andric<
11930b57cec5SDimitry Andric    is_arithmetic<_Tp>::value,
11940b57cec5SDimitry Andric    complex<typename __promote<_Tp, _Up>::type>
11950b57cec5SDimitry Andric>::type
11960b57cec5SDimitry Andricpow(const _Tp& __x, const complex<_Up>& __y)
11970b57cec5SDimitry Andric{
11980b57cec5SDimitry Andric    typedef complex<typename __promote<_Tp, _Up>::type> result_type;
11990b57cec5SDimitry Andric    return _VSTD::pow(result_type(__x), result_type(__y));
12000b57cec5SDimitry Andric}
12010b57cec5SDimitry Andric
12020b57cec5SDimitry Andric// __sqr, computes pow(x, 2)
12030b57cec5SDimitry Andric
12040b57cec5SDimitry Andrictemplate<class _Tp>
12050b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
12060b57cec5SDimitry Andriccomplex<_Tp>
12070b57cec5SDimitry Andric__sqr(const complex<_Tp>& __x)
12080b57cec5SDimitry Andric{
12090b57cec5SDimitry Andric    return complex<_Tp>((__x.real() - __x.imag()) * (__x.real() + __x.imag()),
12100b57cec5SDimitry Andric                        _Tp(2) * __x.real() * __x.imag());
12110b57cec5SDimitry Andric}
12120b57cec5SDimitry Andric
12130b57cec5SDimitry Andric// asinh
12140b57cec5SDimitry Andric
12150b57cec5SDimitry Andrictemplate<class _Tp>
1216bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
12170b57cec5SDimitry Andricasinh(const complex<_Tp>& __x)
12180b57cec5SDimitry Andric{
12190b57cec5SDimitry Andric    const _Tp __pi(atan2(+0., -0.));
1220bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.real()))
12210b57cec5SDimitry Andric    {
1222bdd1243dSDimitry Andric        if (std::__constexpr_isnan(__x.imag()))
12230b57cec5SDimitry Andric            return __x;
1224bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__x.imag()))
1225bdd1243dSDimitry Andric            return complex<_Tp>(__x.real(), std::copysign(__pi * _Tp(0.25), __x.imag()));
1226bdd1243dSDimitry Andric        return complex<_Tp>(__x.real(), std::copysign(_Tp(0), __x.imag()));
12270b57cec5SDimitry Andric    }
1228bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__x.real()))
12290b57cec5SDimitry Andric    {
1230bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__x.imag()))
12310b57cec5SDimitry Andric            return complex<_Tp>(__x.imag(), __x.real());
12320b57cec5SDimitry Andric        if (__x.imag() == 0)
12330b57cec5SDimitry Andric            return __x;
12340b57cec5SDimitry Andric        return complex<_Tp>(__x.real(), __x.real());
12350b57cec5SDimitry Andric    }
1236bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.imag()))
1237bdd1243dSDimitry Andric        return complex<_Tp>(std::copysign(__x.imag(), __x.real()), std::copysign(__pi/_Tp(2), __x.imag()));
1238bdd1243dSDimitry Andric    complex<_Tp> __z = std::log(__x + std::sqrt(std::__sqr(__x) + _Tp(1)));
1239bdd1243dSDimitry Andric    return complex<_Tp>(std::copysign(__z.real(), __x.real()), std::copysign(__z.imag(), __x.imag()));
12400b57cec5SDimitry Andric}
12410b57cec5SDimitry Andric
12420b57cec5SDimitry Andric// acosh
12430b57cec5SDimitry Andric
12440b57cec5SDimitry Andrictemplate<class _Tp>
1245bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
12460b57cec5SDimitry Andricacosh(const complex<_Tp>& __x)
12470b57cec5SDimitry Andric{
12480b57cec5SDimitry Andric    const _Tp __pi(atan2(+0., -0.));
1249bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.real()))
12500b57cec5SDimitry Andric    {
1251bdd1243dSDimitry Andric        if (std::__constexpr_isnan(__x.imag()))
1252bdd1243dSDimitry Andric            return complex<_Tp>(std::abs(__x.real()), __x.imag());
1253bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__x.imag()))
12540b57cec5SDimitry Andric        {
12550b57cec5SDimitry Andric            if (__x.real() > 0)
1256bdd1243dSDimitry Andric                return complex<_Tp>(__x.real(), std::copysign(__pi * _Tp(0.25), __x.imag()));
12570b57cec5SDimitry Andric            else
1258bdd1243dSDimitry Andric                return complex<_Tp>(-__x.real(), std::copysign(__pi * _Tp(0.75), __x.imag()));
12590b57cec5SDimitry Andric        }
12600b57cec5SDimitry Andric        if (__x.real() < 0)
1261bdd1243dSDimitry Andric            return complex<_Tp>(-__x.real(), std::copysign(__pi, __x.imag()));
1262bdd1243dSDimitry Andric        return complex<_Tp>(__x.real(), std::copysign(_Tp(0), __x.imag()));
12630b57cec5SDimitry Andric    }
1264bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__x.real()))
12650b57cec5SDimitry Andric    {
1266bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__x.imag()))
1267bdd1243dSDimitry Andric            return complex<_Tp>(std::abs(__x.imag()), __x.real());
12680b57cec5SDimitry Andric        return complex<_Tp>(__x.real(), __x.real());
12690b57cec5SDimitry Andric    }
1270bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.imag()))
1271bdd1243dSDimitry Andric        return complex<_Tp>(std::abs(__x.imag()), std::copysign(__pi/_Tp(2), __x.imag()));
1272bdd1243dSDimitry Andric    complex<_Tp> __z = std::log(__x + std::sqrt(std::__sqr(__x) - _Tp(1)));
1273bdd1243dSDimitry Andric    return complex<_Tp>(std::copysign(__z.real(), _Tp(0)), std::copysign(__z.imag(), __x.imag()));
12740b57cec5SDimitry Andric}
12750b57cec5SDimitry Andric
12760b57cec5SDimitry Andric// atanh
12770b57cec5SDimitry Andric
12780b57cec5SDimitry Andrictemplate<class _Tp>
1279bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
12800b57cec5SDimitry Andricatanh(const complex<_Tp>& __x)
12810b57cec5SDimitry Andric{
12820b57cec5SDimitry Andric    const _Tp __pi(atan2(+0., -0.));
1283bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.imag()))
12840b57cec5SDimitry Andric    {
1285bdd1243dSDimitry Andric        return complex<_Tp>(std::copysign(_Tp(0), __x.real()), std::copysign(__pi/_Tp(2), __x.imag()));
12860b57cec5SDimitry Andric    }
1287bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__x.imag()))
12880b57cec5SDimitry Andric    {
1289bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__x.real()) || __x.real() == 0)
1290bdd1243dSDimitry Andric            return complex<_Tp>(std::copysign(_Tp(0), __x.real()), __x.imag());
12910b57cec5SDimitry Andric        return complex<_Tp>(__x.imag(), __x.imag());
12920b57cec5SDimitry Andric    }
1293bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__x.real()))
12940b57cec5SDimitry Andric    {
12950b57cec5SDimitry Andric        return complex<_Tp>(__x.real(), __x.real());
12960b57cec5SDimitry Andric    }
1297bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.real()))
12980b57cec5SDimitry Andric    {
1299bdd1243dSDimitry Andric        return complex<_Tp>(std::copysign(_Tp(0), __x.real()), std::copysign(__pi/_Tp(2), __x.imag()));
13000b57cec5SDimitry Andric    }
1301bdd1243dSDimitry Andric    if (std::abs(__x.real()) == _Tp(1) && __x.imag() == _Tp(0))
13020b57cec5SDimitry Andric    {
1303bdd1243dSDimitry Andric        return complex<_Tp>(std::copysign(_Tp(INFINITY), __x.real()), std::copysign(_Tp(0), __x.imag()));
13040b57cec5SDimitry Andric    }
1305bdd1243dSDimitry Andric    complex<_Tp> __z = std::log((_Tp(1) + __x) / (_Tp(1) - __x)) / _Tp(2);
1306bdd1243dSDimitry Andric    return complex<_Tp>(std::copysign(__z.real(), __x.real()), std::copysign(__z.imag(), __x.imag()));
13070b57cec5SDimitry Andric}
13080b57cec5SDimitry Andric
13090b57cec5SDimitry Andric// sinh
13100b57cec5SDimitry Andric
13110b57cec5SDimitry Andrictemplate<class _Tp>
1312bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
13130b57cec5SDimitry Andricsinh(const complex<_Tp>& __x)
13140b57cec5SDimitry Andric{
1315bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.real()) && !std::__constexpr_isfinite(__x.imag()))
13160b57cec5SDimitry Andric        return complex<_Tp>(__x.real(), _Tp(NAN));
1317bdd1243dSDimitry Andric    if (__x.real() == 0 && !std::__constexpr_isfinite(__x.imag()))
13180b57cec5SDimitry Andric        return complex<_Tp>(__x.real(), _Tp(NAN));
1319bdd1243dSDimitry Andric    if (__x.imag() == 0 && !std::__constexpr_isfinite(__x.real()))
13200b57cec5SDimitry Andric        return __x;
1321bdd1243dSDimitry Andric    return complex<_Tp>(std::sinh(__x.real()) * std::cos(__x.imag()), std::cosh(__x.real()) * std::sin(__x.imag()));
13220b57cec5SDimitry Andric}
13230b57cec5SDimitry Andric
13240b57cec5SDimitry Andric// cosh
13250b57cec5SDimitry Andric
13260b57cec5SDimitry Andrictemplate<class _Tp>
1327bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
13280b57cec5SDimitry Andriccosh(const complex<_Tp>& __x)
13290b57cec5SDimitry Andric{
1330bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.real()) && !std::__constexpr_isfinite(__x.imag()))
1331bdd1243dSDimitry Andric        return complex<_Tp>(std::abs(__x.real()), _Tp(NAN));
1332bdd1243dSDimitry Andric    if (__x.real() == 0 && !std::__constexpr_isfinite(__x.imag()))
13330b57cec5SDimitry Andric        return complex<_Tp>(_Tp(NAN), __x.real());
13340b57cec5SDimitry Andric    if (__x.real() == 0 && __x.imag() == 0)
13350b57cec5SDimitry Andric        return complex<_Tp>(_Tp(1), __x.imag());
1336bdd1243dSDimitry Andric    if (__x.imag() == 0 && !std::__constexpr_isfinite(__x.real()))
1337bdd1243dSDimitry Andric        return complex<_Tp>(std::abs(__x.real()), __x.imag());
1338bdd1243dSDimitry Andric    return complex<_Tp>(std::cosh(__x.real()) * std::cos(__x.imag()), std::sinh(__x.real()) * std::sin(__x.imag()));
13390b57cec5SDimitry Andric}
13400b57cec5SDimitry Andric
13410b57cec5SDimitry Andric// tanh
13420b57cec5SDimitry Andric
13430b57cec5SDimitry Andrictemplate<class _Tp>
1344bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
13450b57cec5SDimitry Andrictanh(const complex<_Tp>& __x)
13460b57cec5SDimitry Andric{
1347bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.real()))
13480b57cec5SDimitry Andric    {
1349bdd1243dSDimitry Andric        if (!std::__constexpr_isfinite(__x.imag()))
1350bdd1243dSDimitry Andric            return complex<_Tp>(std::copysign(_Tp(1), __x.real()), _Tp(0));
1351bdd1243dSDimitry Andric        return complex<_Tp>(std::copysign(_Tp(1), __x.real()), std::copysign(_Tp(0), std::sin(_Tp(2) * __x.imag())));
13520b57cec5SDimitry Andric    }
1353bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__x.real()) && __x.imag() == 0)
13540b57cec5SDimitry Andric        return __x;
13550b57cec5SDimitry Andric    _Tp __2r(_Tp(2) * __x.real());
13560b57cec5SDimitry Andric    _Tp __2i(_Tp(2) * __x.imag());
1357bdd1243dSDimitry Andric    _Tp __d(std::cosh(__2r) + std::cos(__2i));
1358bdd1243dSDimitry Andric    _Tp __2rsh(std::sinh(__2r));
1359bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__2rsh) && std::__constexpr_isinf(__d))
13600b57cec5SDimitry Andric        return complex<_Tp>(__2rsh > _Tp(0) ? _Tp(1) : _Tp(-1),
13610b57cec5SDimitry Andric                            __2i > _Tp(0) ? _Tp(0) : _Tp(-0.));
1362bdd1243dSDimitry Andric    return  complex<_Tp>(__2rsh/__d, std::sin(__2i)/__d);
13630b57cec5SDimitry Andric}
13640b57cec5SDimitry Andric
13650b57cec5SDimitry Andric// asin
13660b57cec5SDimitry Andric
13670b57cec5SDimitry Andrictemplate<class _Tp>
1368bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
13690b57cec5SDimitry Andricasin(const complex<_Tp>& __x)
13700b57cec5SDimitry Andric{
1371bdd1243dSDimitry Andric    complex<_Tp> __z = std::asinh(complex<_Tp>(-__x.imag(), __x.real()));
13720b57cec5SDimitry Andric    return complex<_Tp>(__z.imag(), -__z.real());
13730b57cec5SDimitry Andric}
13740b57cec5SDimitry Andric
13750b57cec5SDimitry Andric// acos
13760b57cec5SDimitry Andric
13770b57cec5SDimitry Andrictemplate<class _Tp>
1378bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
13790b57cec5SDimitry Andricacos(const complex<_Tp>& __x)
13800b57cec5SDimitry Andric{
13810b57cec5SDimitry Andric    const _Tp __pi(atan2(+0., -0.));
1382bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.real()))
13830b57cec5SDimitry Andric    {
1384bdd1243dSDimitry Andric        if (std::__constexpr_isnan(__x.imag()))
13850b57cec5SDimitry Andric            return complex<_Tp>(__x.imag(), __x.real());
1386bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__x.imag()))
13870b57cec5SDimitry Andric        {
13880b57cec5SDimitry Andric            if (__x.real() < _Tp(0))
13890b57cec5SDimitry Andric                return complex<_Tp>(_Tp(0.75) * __pi, -__x.imag());
13900b57cec5SDimitry Andric            return complex<_Tp>(_Tp(0.25) * __pi, -__x.imag());
13910b57cec5SDimitry Andric        }
13920b57cec5SDimitry Andric        if (__x.real() < _Tp(0))
1393bdd1243dSDimitry Andric            return complex<_Tp>(__pi, std::signbit(__x.imag()) ? -__x.real() : __x.real());
1394bdd1243dSDimitry Andric        return complex<_Tp>(_Tp(0), std::signbit(__x.imag()) ? __x.real() : -__x.real());
13950b57cec5SDimitry Andric    }
1396bdd1243dSDimitry Andric    if (std::__constexpr_isnan(__x.real()))
13970b57cec5SDimitry Andric    {
1398bdd1243dSDimitry Andric        if (std::__constexpr_isinf(__x.imag()))
13990b57cec5SDimitry Andric            return complex<_Tp>(__x.real(), -__x.imag());
14000b57cec5SDimitry Andric        return complex<_Tp>(__x.real(), __x.real());
14010b57cec5SDimitry Andric    }
1402bdd1243dSDimitry Andric    if (std::__constexpr_isinf(__x.imag()))
14030b57cec5SDimitry Andric        return complex<_Tp>(__pi/_Tp(2), -__x.imag());
1404bdd1243dSDimitry Andric    if (__x.real() == 0 && (__x.imag() == 0 || std::isnan(__x.imag())))
14050b57cec5SDimitry Andric        return complex<_Tp>(__pi/_Tp(2), -__x.imag());
1406bdd1243dSDimitry Andric    complex<_Tp> __z = std::log(__x + std::sqrt(std::__sqr(__x) - _Tp(1)));
1407bdd1243dSDimitry Andric    if (std::signbit(__x.imag()))
1408bdd1243dSDimitry Andric        return complex<_Tp>(std::abs(__z.imag()), std::abs(__z.real()));
1409bdd1243dSDimitry Andric    return complex<_Tp>(std::abs(__z.imag()), -std::abs(__z.real()));
14100b57cec5SDimitry Andric}
14110b57cec5SDimitry Andric
14120b57cec5SDimitry Andric// atan
14130b57cec5SDimitry Andric
14140b57cec5SDimitry Andrictemplate<class _Tp>
1415bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
14160b57cec5SDimitry Andricatan(const complex<_Tp>& __x)
14170b57cec5SDimitry Andric{
1418bdd1243dSDimitry Andric    complex<_Tp> __z = std::atanh(complex<_Tp>(-__x.imag(), __x.real()));
14190b57cec5SDimitry Andric    return complex<_Tp>(__z.imag(), -__z.real());
14200b57cec5SDimitry Andric}
14210b57cec5SDimitry Andric
14220b57cec5SDimitry Andric// sin
14230b57cec5SDimitry Andric
14240b57cec5SDimitry Andrictemplate<class _Tp>
1425bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
14260b57cec5SDimitry Andricsin(const complex<_Tp>& __x)
14270b57cec5SDimitry Andric{
1428bdd1243dSDimitry Andric    complex<_Tp> __z = std::sinh(complex<_Tp>(-__x.imag(), __x.real()));
14290b57cec5SDimitry Andric    return complex<_Tp>(__z.imag(), -__z.real());
14300b57cec5SDimitry Andric}
14310b57cec5SDimitry Andric
14320b57cec5SDimitry Andric// cos
14330b57cec5SDimitry Andric
14340b57cec5SDimitry Andrictemplate<class _Tp>
14350b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14360b57cec5SDimitry Andriccomplex<_Tp>
14370b57cec5SDimitry Andriccos(const complex<_Tp>& __x)
14380b57cec5SDimitry Andric{
1439bdd1243dSDimitry Andric    return std::cosh(complex<_Tp>(-__x.imag(), __x.real()));
14400b57cec5SDimitry Andric}
14410b57cec5SDimitry Andric
14420b57cec5SDimitry Andric// tan
14430b57cec5SDimitry Andric
14440b57cec5SDimitry Andrictemplate<class _Tp>
1445bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI complex<_Tp>
14460b57cec5SDimitry Andrictan(const complex<_Tp>& __x)
14470b57cec5SDimitry Andric{
1448bdd1243dSDimitry Andric    complex<_Tp> __z = std::tanh(complex<_Tp>(-__x.imag(), __x.real()));
14490b57cec5SDimitry Andric    return complex<_Tp>(__z.imag(), -__z.real());
14500b57cec5SDimitry Andric}
14510b57cec5SDimitry Andric
1452bdd1243dSDimitry Andric#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
14530b57cec5SDimitry Andrictemplate<class _Tp, class _CharT, class _Traits>
1454bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
14550b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
14560b57cec5SDimitry Andric{
14570b57cec5SDimitry Andric    if (__is.good())
14580b57cec5SDimitry Andric    {
1459bdd1243dSDimitry Andric        std::ws(__is);
14600b57cec5SDimitry Andric        if (__is.peek() == _CharT('('))
14610b57cec5SDimitry Andric        {
14620b57cec5SDimitry Andric            __is.get();
14630b57cec5SDimitry Andric            _Tp __r;
14640b57cec5SDimitry Andric            __is >> __r;
14650b57cec5SDimitry Andric            if (!__is.fail())
14660b57cec5SDimitry Andric            {
1467bdd1243dSDimitry Andric                std::ws(__is);
14680b57cec5SDimitry Andric                _CharT __c = __is.peek();
14690b57cec5SDimitry Andric                if (__c == _CharT(','))
14700b57cec5SDimitry Andric                {
14710b57cec5SDimitry Andric                    __is.get();
14720b57cec5SDimitry Andric                    _Tp __i;
14730b57cec5SDimitry Andric                    __is >> __i;
14740b57cec5SDimitry Andric                    if (!__is.fail())
14750b57cec5SDimitry Andric                    {
1476bdd1243dSDimitry Andric                        std::ws(__is);
14770b57cec5SDimitry Andric                        __c = __is.peek();
14780b57cec5SDimitry Andric                        if (__c == _CharT(')'))
14790b57cec5SDimitry Andric                        {
14800b57cec5SDimitry Andric                            __is.get();
14810b57cec5SDimitry Andric                            __x = complex<_Tp>(__r, __i);
14820b57cec5SDimitry Andric                        }
14830b57cec5SDimitry Andric                        else
14845ffd83dbSDimitry Andric                            __is.setstate(__is.failbit);
14850b57cec5SDimitry Andric                    }
14860b57cec5SDimitry Andric                    else
14875ffd83dbSDimitry Andric                        __is.setstate(__is.failbit);
14880b57cec5SDimitry Andric                }
14890b57cec5SDimitry Andric                else if (__c == _CharT(')'))
14900b57cec5SDimitry Andric                {
14910b57cec5SDimitry Andric                    __is.get();
14920b57cec5SDimitry Andric                    __x = complex<_Tp>(__r, _Tp(0));
14930b57cec5SDimitry Andric                }
14940b57cec5SDimitry Andric                else
14955ffd83dbSDimitry Andric                    __is.setstate(__is.failbit);
14960b57cec5SDimitry Andric            }
14970b57cec5SDimitry Andric            else
14985ffd83dbSDimitry Andric                __is.setstate(__is.failbit);
14990b57cec5SDimitry Andric        }
15000b57cec5SDimitry Andric        else
15010b57cec5SDimitry Andric        {
15020b57cec5SDimitry Andric            _Tp __r;
15030b57cec5SDimitry Andric            __is >> __r;
15040b57cec5SDimitry Andric            if (!__is.fail())
15050b57cec5SDimitry Andric                __x = complex<_Tp>(__r, _Tp(0));
15060b57cec5SDimitry Andric            else
15075ffd83dbSDimitry Andric                __is.setstate(__is.failbit);
15080b57cec5SDimitry Andric        }
15090b57cec5SDimitry Andric    }
15100b57cec5SDimitry Andric    else
15115ffd83dbSDimitry Andric        __is.setstate(__is.failbit);
15120b57cec5SDimitry Andric    return __is;
15130b57cec5SDimitry Andric}
15140b57cec5SDimitry Andric
15150b57cec5SDimitry Andrictemplate<class _Tp, class _CharT, class _Traits>
1516bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
15170b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
15180b57cec5SDimitry Andric{
15190b57cec5SDimitry Andric    basic_ostringstream<_CharT, _Traits> __s;
15200b57cec5SDimitry Andric    __s.flags(__os.flags());
15210b57cec5SDimitry Andric    __s.imbue(__os.getloc());
15220b57cec5SDimitry Andric    __s.precision(__os.precision());
15230b57cec5SDimitry Andric    __s << '(' << __x.real() << ',' << __x.imag() << ')';
15240b57cec5SDimitry Andric    return __os << __s.str();
15250b57cec5SDimitry Andric}
1526e8d8bef9SDimitry Andric#endif // !_LIBCPP_HAS_NO_LOCALIZATION
15270b57cec5SDimitry Andric
1528*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
15290b57cec5SDimitry Andric// Literal suffix for complex number literals [complex.literals]
15300b57cec5SDimitry Andricinline namespace literals
15310b57cec5SDimitry Andric{
15320b57cec5SDimitry Andric  inline namespace complex_literals
15330b57cec5SDimitry Andric  {
1534bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI constexpr complex<long double> operator""il(long double __im)
15350b57cec5SDimitry Andric    {
15360b57cec5SDimitry Andric        return { 0.0l, __im };
15370b57cec5SDimitry Andric    }
15380b57cec5SDimitry Andric
1539bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI constexpr complex<long double> operator""il(unsigned long long __im)
15400b57cec5SDimitry Andric    {
15410b57cec5SDimitry Andric        return { 0.0l, static_cast<long double>(__im) };
15420b57cec5SDimitry Andric    }
15430b57cec5SDimitry Andric
15440b57cec5SDimitry Andric
1545bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI constexpr complex<double> operator""i(long double __im)
15460b57cec5SDimitry Andric    {
15470b57cec5SDimitry Andric        return { 0.0, static_cast<double>(__im) };
15480b57cec5SDimitry Andric    }
15490b57cec5SDimitry Andric
1550bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI constexpr complex<double> operator""i(unsigned long long __im)
15510b57cec5SDimitry Andric    {
15520b57cec5SDimitry Andric        return { 0.0, static_cast<double>(__im) };
15530b57cec5SDimitry Andric    }
15540b57cec5SDimitry Andric
15550b57cec5SDimitry Andric
1556bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI constexpr complex<float> operator""if(long double __im)
15570b57cec5SDimitry Andric    {
15580b57cec5SDimitry Andric        return { 0.0f, static_cast<float>(__im) };
15590b57cec5SDimitry Andric    }
15600b57cec5SDimitry Andric
1561bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI constexpr complex<float> operator""if(unsigned long long __im)
15620b57cec5SDimitry Andric    {
15630b57cec5SDimitry Andric        return { 0.0f, static_cast<float>(__im) };
15640b57cec5SDimitry Andric    }
15650eae32dcSDimitry Andric  } // namespace complex_literals
15660eae32dcSDimitry Andric} // namespace literals
15670b57cec5SDimitry Andric#endif
15680b57cec5SDimitry Andric
15690b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
15700b57cec5SDimitry Andric
1571*06c3fb27SDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1572*06c3fb27SDimitry Andric#  include <type_traits>
1573*06c3fb27SDimitry Andric#endif
1574*06c3fb27SDimitry Andric
15750b57cec5SDimitry Andric#endif // _LIBCPP_COMPLEX
1576