diff --git a/libaxx/include/complex b/libaxx/include/complex new file mode 100644 index 000000000..1eca648de --- /dev/null +++ b/libaxx/include/complex @@ -0,0 +1,7 @@ +#ifndef LIBAXX_COMPLEX +#define LIBAXX_COMPLEX + +#define THINNER_HEADER +#include "external/libcxx/complex" + +#endif diff --git a/libaxx/include/external/libcxx/complex b/libaxx/include/external/libcxx/complex new file mode 100644 index 000000000..c3ab4a2fa --- /dev/null +++ b/libaxx/include/external/libcxx/complex @@ -0,0 +1,1548 @@ +// -*- C++ -*- +//===--------------------------- complex ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_COMPLEX +#define _LIBCPP_COMPLEX + +/* + complex synopsis + +namespace std +{ + +template +class complex +{ +public: + typedef T value_type; + + complex(const T& re = T(), const T& im = T()); // constexpr in C++14 + complex(const complex&); // constexpr in C++14 + template complex(const complex&); // constexpr in C++14 + + T real() const; // constexpr in C++14 + T imag() const; // constexpr in C++14 + + void real(T); + void imag(T); + + complex& operator= (const T&); + complex& operator+=(const T&); + complex& operator-=(const T&); + complex& operator*=(const T&); + complex& operator/=(const T&); + + complex& operator=(const complex&); + template complex& operator= (const complex&); + template complex& operator+=(const complex&); + template complex& operator-=(const complex&); + template complex& operator*=(const complex&); + template complex& operator/=(const complex&); +}; + +template<> +class complex +{ +public: + typedef float value_type; + + constexpr complex(float re = 0.0f, float im = 0.0f); + explicit constexpr complex(const complex&); +#ifndef THINNER_HEADER + explicit constexpr complex(const complex&); +#endif + + constexpr float real() const; + void real(float); + constexpr float imag() const; + void imag(float); + + complex& operator= (float); + complex& operator+=(float); + complex& operator-=(float); + complex& operator*=(float); + complex& operator/=(float); + + complex& operator=(const complex&); + template complex& operator= (const complex&); + template complex& operator+=(const complex&); + template complex& operator-=(const complex&); + template complex& operator*=(const complex&); + template complex& operator/=(const complex&); +}; + +template<> +class complex +{ +public: + typedef double value_type; + + constexpr complex(double re = 0.0, double im = 0.0); + constexpr complex(const complex&); +#ifndef THINNER_HEADER + explicit constexpr complex(const complex&); +#endif + + constexpr double real() const; + void real(double); + constexpr double imag() const; + void imag(double); + + complex& operator= (double); + complex& operator+=(double); + complex& operator-=(double); + complex& operator*=(double); + complex& operator/=(double); + complex& operator=(const complex&); + + template complex& operator= (const complex&); + template complex& operator+=(const complex&); + template complex& operator-=(const complex&); + template complex& operator*=(const complex&); + template complex& operator/=(const complex&); +}; + +#ifndef THINNER_HEADER + +template<> +class complex +{ +public: + typedef long double value_type; + + constexpr complex(long double re = 0.0L, long double im = 0.0L); + constexpr complex(const complex&); + constexpr complex(const complex&); + + constexpr long double real() const; + void real(long double); + constexpr long double imag() const; + void imag(long double); + + complex& operator=(const complex&); + complex& operator= (long double); + complex& operator+=(long double); + complex& operator-=(long double); + complex& operator*=(long double); + complex& operator/=(long double); + + template complex& operator= (const complex&); + template complex& operator+=(const complex&); + template complex& operator-=(const complex&); + template complex& operator*=(const complex&); + template complex& operator/=(const complex&); +}; + +#endif + +// 26.3.6 operators: +template complex operator+(const complex&, const complex&); +template complex operator+(const complex&, const T&); +template complex operator+(const T&, const complex&); +template complex operator-(const complex&, const complex&); +template complex operator-(const complex&, const T&); +template complex operator-(const T&, const complex&); +template complex operator*(const complex&, const complex&); +template complex operator*(const complex&, const T&); +template complex operator*(const T&, const complex&); +template complex operator/(const complex&, const complex&); +template complex operator/(const complex&, const T&); +template complex operator/(const T&, const complex&); +template complex operator+(const complex&); +template complex operator-(const complex&); +template bool operator==(const complex&, const complex&); // constexpr in C++14 +template bool operator==(const complex&, const T&); // constexpr in C++14 +template bool operator==(const T&, const complex&); // constexpr in C++14 +template bool operator!=(const complex&, const complex&); // constexpr in C++14 +template bool operator!=(const complex&, const T&); // constexpr in C++14 +template bool operator!=(const T&, const complex&); // constexpr in C++14 + +#ifndef THINNER_HEADER + +template + basic_istream& + operator>>(basic_istream&, complex&); +template + basic_ostream& + operator<<(basic_ostream&, const complex&); + +#endif + +// 26.3.7 values: + +template T real(const complex&); // constexpr in C++14 +#ifndef THINNER_HEADER + long double real(long double); // constexpr in C++14 +#endif + double real(double); // constexpr in C++14 +template double real(T); // constexpr in C++14 + float real(float); // constexpr in C++14 + +template T imag(const complex&); // constexpr in C++14 +#ifndef THINNER_HEADER + long double imag(long double); // constexpr in C++14 +#endif + double imag(double); // constexpr in C++14 +template double imag(T); // constexpr in C++14 + float imag(float); // constexpr in C++14 + +template T abs(const complex&); + +template T arg(const complex&); +#ifndef THINNER_HEADER + long double arg(long double); +#endif + double arg(double); +template double arg(T); + float arg(float); + +template T norm(const complex&); +#ifndef THINNER_HEADER + long double norm(long double); +#endif + double norm(double); +template double norm(T); + float norm(float); + +template complex conj(const complex&); +#ifndef THINNER_HEADER + complex conj(long double); +#endif + complex conj(double); +template complex conj(T); + complex conj(float); + +template complex proj(const complex&); +#ifndef THINNER_HEADER + complex proj(long double); +#endif + complex proj(double); +template complex proj(T); + complex proj(float); + +template complex polar(const T&, const T& = T()); + +// 26.3.8 transcendentals: +template complex acos(const complex&); +template complex asin(const complex&); +template complex atan(const complex&); +template complex acosh(const complex&); +template complex asinh(const complex&); +template complex atanh(const complex&); +template complex cos (const complex&); +template complex cosh (const complex&); +template complex exp (const complex&); +template complex log (const complex&); +template complex log10(const complex&); + +template complex pow(const complex&, const T&); +template complex pow(const complex&, const complex&); +template complex pow(const T&, const complex&); + +template complex sin (const complex&); +template complex sinh (const complex&); +template complex sqrt (const complex&); +template complex tan (const complex&); +template complex tanh (const complex&); + + +#ifndef THINNER_HEADER + +template + basic_istream& + operator>>(basic_istream& is, complex& x); + +template + basic_ostream& + operator<<(basic_ostream& o, const complex& x); + +#endif + +} // std + +*/ + +#ifdef THINNER_HEADER +#include "include/__config" +#include "include/cmath" +#include "include/type_traits" +#else +#include <__config> +#include +#include +#include +#include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template class _LIBCPP_TEMPLATE_VIS complex; + +template complex<_Tp> operator*(const complex<_Tp>& __z, const complex<_Tp>& __w); +template complex<_Tp> operator/(const complex<_Tp>& __x, const complex<_Tp>& __y); + +template +class _LIBCPP_TEMPLATE_VIS complex +{ +public: + typedef _Tp value_type; +private: + value_type __re_; + value_type __im_; +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + complex(const value_type& __re = value_type(), const value_type& __im = value_type()) + : __re_(__re), __im_(__im) {} + template _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + complex(const complex<_Xp>& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (const value_type& __re) + {__re_ = __re; __im_ = value_type(); return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(const value_type& __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(const value_type& __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(const value_type& __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(const value_type& __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * complex(__c.real(), __c.imag()); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / complex(__c.real(), __c.imag()); + return *this; + } +}; + +template<> class _LIBCPP_TEMPLATE_VIS complex; +#ifndef THINNER_HEADER +template<> class _LIBCPP_TEMPLATE_VIS complex; +#endif + +template<> +class _LIBCPP_TEMPLATE_VIS complex +{ + float __re_; + float __im_; +public: + typedef float value_type; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(float __re = 0.0f, float __im = 0.0f) + : __re_(__re), __im_(__im) {} + _LIBCPP_INLINE_VISIBILITY + explicit _LIBCPP_CONSTEXPR complex(const complex& __c); +#ifndef THINNER_HEADER + _LIBCPP_INLINE_VISIBILITY + explicit _LIBCPP_CONSTEXPR complex(const complex& __c); +#endif + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (float __re) + {__re_ = __re; __im_ = value_type(); return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(float __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(float __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(float __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(float __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * complex(__c.real(), __c.imag()); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / complex(__c.real(), __c.imag()); + return *this; + } +}; + +template<> +class _LIBCPP_TEMPLATE_VIS complex +{ + double __re_; + double __im_; +public: + typedef double value_type; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(double __re = 0.0, double __im = 0.0) + : __re_(__re), __im_(__im) {} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR complex(const complex& __c); +#ifndef THINNER_HEADER + _LIBCPP_INLINE_VISIBILITY + explicit _LIBCPP_CONSTEXPR complex(const complex& __c); +#endif + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (double __re) + {__re_ = __re; __im_ = value_type(); return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(double __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(double __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(double __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(double __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * complex(__c.real(), __c.imag()); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / complex(__c.real(), __c.imag()); + return *this; + } +}; + +#ifndef THINNER_HEADER +template<> +class _LIBCPP_TEMPLATE_VIS complex +{ + long double __re_; + long double __im_; +public: + typedef long double value_type; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(long double __re = 0.0L, long double __im = 0.0L) + : __re_(__re), __im_(__im) {} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR complex(const complex& __c); + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR complex(const complex& __c); + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (long double __re) + {__re_ = __re; __im_ = value_type(); return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(long double __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(long double __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(long double __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(long double __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * complex(__c.real(), __c.imag()); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / complex(__c.real(), __c.imag()); + return *this; + } +}; +#endif + +inline +_LIBCPP_CONSTEXPR +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +#ifndef THINNER_HEADER +inline +_LIBCPP_CONSTEXPR +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} +#endif + +inline +_LIBCPP_CONSTEXPR +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +#ifndef THINNER_HEADER +inline +_LIBCPP_CONSTEXPR +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +inline +_LIBCPP_CONSTEXPR +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +inline +_LIBCPP_CONSTEXPR +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} +#endif + + +// 26.3.6 operators: + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__x); + __t += __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const complex<_Tp>& __x, const _Tp& __y) +{ + complex<_Tp> __t(__x); + __t += __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__y); + __t += __x; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__x); + __t -= __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const complex<_Tp>& __x, const _Tp& __y) +{ + complex<_Tp> __t(__x); + __t -= __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(-__y); + __t += __x; + return __t; +} + +template +complex<_Tp> +operator*(const complex<_Tp>& __z, const complex<_Tp>& __w) +{ + _Tp __a = __z.real(); + _Tp __b = __z.imag(); + _Tp __c = __w.real(); + _Tp __d = __w.imag(); + _Tp __ac = __a * __c; + _Tp __bd = __b * __d; + _Tp __ad = __a * __d; + _Tp __bc = __b * __c; + _Tp __x = __ac - __bd; + _Tp __y = __ad + __bc; + if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y)) + { + bool __recalc = false; + if (__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b)) + { + __a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b); + if (__libcpp_isnan_or_builtin(__c)) + __c = copysign(_Tp(0), __c); + if (__libcpp_isnan_or_builtin(__d)) + __d = copysign(_Tp(0), __d); + __recalc = true; + } + if (__libcpp_isinf_or_builtin(__c) || __libcpp_isinf_or_builtin(__d)) + { + __c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d); + if (__libcpp_isnan_or_builtin(__a)) + __a = copysign(_Tp(0), __a); + if (__libcpp_isnan_or_builtin(__b)) + __b = copysign(_Tp(0), __b); + __recalc = true; + } + if (!__recalc && (__libcpp_isinf_or_builtin(__ac) || __libcpp_isinf_or_builtin(__bd) || + __libcpp_isinf_or_builtin(__ad) || __libcpp_isinf_or_builtin(__bc))) + { + if (__libcpp_isnan_or_builtin(__a)) + __a = copysign(_Tp(0), __a); + if (__libcpp_isnan_or_builtin(__b)) + __b = copysign(_Tp(0), __b); + if (__libcpp_isnan_or_builtin(__c)) + __c = copysign(_Tp(0), __c); + if (__libcpp_isnan_or_builtin(__d)) + __d = copysign(_Tp(0), __d); + __recalc = true; + } + if (__recalc) + { + __x = _Tp(INFINITY) * (__a * __c - __b * __d); + __y = _Tp(INFINITY) * (__a * __d + __b * __c); + } + } + return complex<_Tp>(__x, __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator*(const complex<_Tp>& __x, const _Tp& __y) +{ + complex<_Tp> __t(__x); + __t *= __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator*(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__y); + __t *= __x; + return __t; +} + +template +complex<_Tp> +operator/(const complex<_Tp>& __z, const complex<_Tp>& __w) +{ + int __ilogbw = 0; + _Tp __a = __z.real(); + _Tp __b = __z.imag(); + _Tp __c = __w.real(); + _Tp __d = __w.imag(); + _Tp __logbw = logb(fmax(fabs(__c), fabs(__d))); + if (__libcpp_isfinite_or_builtin(__logbw)) + { + __ilogbw = static_cast(__logbw); + __c = scalbn(__c, -__ilogbw); + __d = scalbn(__d, -__ilogbw); + } + _Tp __denom = __c * __c + __d * __d; + _Tp __x = scalbn((__a * __c + __b * __d) / __denom, -__ilogbw); + _Tp __y = scalbn((__b * __c - __a * __d) / __denom, -__ilogbw); + if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y)) + { + if ((__denom == _Tp(0)) && (!__libcpp_isnan_or_builtin(__a) || !__libcpp_isnan_or_builtin(__b))) + { + __x = copysign(_Tp(INFINITY), __c) * __a; + __y = copysign(_Tp(INFINITY), __c) * __b; + } + else if ((__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b)) && __libcpp_isfinite_or_builtin(__c) && __libcpp_isfinite_or_builtin(__d)) + { + __a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b); + __x = _Tp(INFINITY) * (__a * __c + __b * __d); + __y = _Tp(INFINITY) * (__b * __c - __a * __d); + } + else if (__libcpp_isinf_or_builtin(__logbw) && __logbw > _Tp(0) && __libcpp_isfinite_or_builtin(__a) && __libcpp_isfinite_or_builtin(__b)) + { + __c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d); + __x = _Tp(0) * (__a * __c + __b * __d); + __y = _Tp(0) * (__b * __c - __a * __d); + } + } + return complex<_Tp>(__x, __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator/(const complex<_Tp>& __x, const _Tp& __y) +{ + return complex<_Tp>(__x.real() / __y, __x.imag() / __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator/(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__x); + __t /= __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const complex<_Tp>& __x) +{ + return __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const complex<_Tp>& __x) +{ + return complex<_Tp>(-__x.real(), -__x.imag()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator==(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + return __x.real() == __y.real() && __x.imag() == __y.imag(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator==(const complex<_Tp>& __x, const _Tp& __y) +{ + return __x.real() == __y && __x.imag() == 0; +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator==(const _Tp& __x, const complex<_Tp>& __y) +{ + return __x == __y.real() && 0 == __y.imag(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + return !(__x == __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator!=(const complex<_Tp>& __x, const _Tp& __y) +{ + return !(__x == __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator!=(const _Tp& __x, const complex<_Tp>& __y) +{ + return !(__x == __y); +} + +// 26.3.7 values: + +template ::value, + bool = is_floating_point<_Tp>::value + > +struct __libcpp_complex_overload_traits {}; + +// Integral Types +template +struct __libcpp_complex_overload_traits<_Tp, true, false> +{ + typedef double _ValueType; + typedef complex _ComplexType; +}; + +// Floating point types +template +struct __libcpp_complex_overload_traits<_Tp, false, true> +{ + typedef _Tp _ValueType; + typedef complex<_Tp> _ComplexType; +}; + +// real + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp +real(const complex<_Tp>& __c) +{ + return __c.real(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename __libcpp_complex_overload_traits<_Tp>::_ValueType +real(_Tp __re) +{ + return __re; +} + +// imag + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp +imag(const complex<_Tp>& __c) +{ + return __c.imag(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename __libcpp_complex_overload_traits<_Tp>::_ValueType +imag(_Tp) +{ + return 0; +} + +// abs + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +abs(const complex<_Tp>& __c) +{ + return hypot(__c.real(), __c.imag()); +} + +// arg + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +arg(const complex<_Tp>& __c) +{ + return atan2(__c.imag(), __c.real()); +} + +#ifndef THINNER_HEADER +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + is_same<_Tp, long double>::value, + long double +>::type +arg(_Tp __re) +{ + return atan2l(0.L, __re); +} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value || is_same<_Tp, double>::value, + double +>::type +arg(_Tp __re) +{ + return atan2(0., __re); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + is_same<_Tp, float>::value, + float +>::type +arg(_Tp __re) +{ + return atan2f(0.F, __re); +} + +// norm + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +norm(const complex<_Tp>& __c) +{ + if (__libcpp_isinf_or_builtin(__c.real())) + return abs(__c.real()); + if (__libcpp_isinf_or_builtin(__c.imag())) + return abs(__c.imag()); + return __c.real() * __c.real() + __c.imag() * __c.imag(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __libcpp_complex_overload_traits<_Tp>::_ValueType +norm(_Tp __re) +{ + typedef typename __libcpp_complex_overload_traits<_Tp>::_ValueType _ValueType; + return static_cast<_ValueType>(__re) * __re; +} + +// conj + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +conj(const complex<_Tp>& __c) +{ + return complex<_Tp>(__c.real(), -__c.imag()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __libcpp_complex_overload_traits<_Tp>::_ComplexType +conj(_Tp __re) +{ + typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType; + return _ComplexType(__re); +} + + + +// proj + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +proj(const complex<_Tp>& __c) +{ + std::complex<_Tp> __r = __c; + if (__libcpp_isinf_or_builtin(__c.real()) || __libcpp_isinf_or_builtin(__c.imag())) + __r = complex<_Tp>(INFINITY, copysign(_Tp(0), __c.imag())); + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_floating_point<_Tp>::value, + typename __libcpp_complex_overload_traits<_Tp>::_ComplexType +>::type +proj(_Tp __re) +{ + if (__libcpp_isinf_or_builtin(__re)) + __re = abs(__re); + return complex<_Tp>(__re); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + typename __libcpp_complex_overload_traits<_Tp>::_ComplexType +>::type +proj(_Tp __re) +{ + typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType; + return _ComplexType(__re); +} + +// polar + +template +complex<_Tp> +polar(const _Tp& __rho, const _Tp& __theta = _Tp()) +{ + if (__libcpp_isnan_or_builtin(__rho) || signbit(__rho)) + return complex<_Tp>(_Tp(NAN), _Tp(NAN)); + if (__libcpp_isnan_or_builtin(__theta)) + { + if (__libcpp_isinf_or_builtin(__rho)) + return complex<_Tp>(__rho, __theta); + return complex<_Tp>(__theta, __theta); + } + if (__libcpp_isinf_or_builtin(__theta)) + { + if (__libcpp_isinf_or_builtin(__rho)) + return complex<_Tp>(__rho, _Tp(NAN)); + return complex<_Tp>(_Tp(NAN), _Tp(NAN)); + } + _Tp __x = __rho * cos(__theta); + if (__libcpp_isnan_or_builtin(__x)) + __x = 0; + _Tp __y = __rho * sin(__theta); + if (__libcpp_isnan_or_builtin(__y)) + __y = 0; + return complex<_Tp>(__x, __y); +} + +// log + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +log(const complex<_Tp>& __x) +{ + return complex<_Tp>(log(abs(__x)), arg(__x)); +} + +// log10 + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +log10(const complex<_Tp>& __x) +{ + return log(__x) / log(_Tp(10)); +} + +// sqrt + +template +complex<_Tp> +sqrt(const complex<_Tp>& __x) +{ + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(_Tp(INFINITY), __x.imag()); + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (__x.real() > _Tp(0)) + return complex<_Tp>(__x.real(), __libcpp_isnan_or_builtin(__x.imag()) ? __x.imag() : copysign(_Tp(0), __x.imag())); + return complex<_Tp>(__libcpp_isnan_or_builtin(__x.imag()) ? __x.imag() : _Tp(0), copysign(__x.real(), __x.imag())); + } + return polar(sqrt(abs(__x)), arg(__x) / _Tp(2)); +} + +// exp + +template +complex<_Tp> +exp(const complex<_Tp>& __x) +{ + _Tp __i = __x.imag(); + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (__x.real() < _Tp(0)) + { + if (!__libcpp_isfinite_or_builtin(__i)) + __i = _Tp(1); + } + else if (__i == 0 || !__libcpp_isfinite_or_builtin(__i)) + { + if (__libcpp_isinf_or_builtin(__i)) + __i = _Tp(NAN); + return complex<_Tp>(__x.real(), __i); + } + } + else if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0) + return __x; + _Tp __e = exp(__x.real()); + return complex<_Tp>(__e * cos(__i), __e * sin(__i)); +} + +// pow + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +pow(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + return exp(__y * log(__x)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex::type> +pow(const complex<_Tp>& __x, const complex<_Up>& __y) +{ + typedef complex::type> result_type; + return _VSTD::pow(result_type(__x), result_type(__y)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_Up>::value, + complex::type> +>::type +pow(const complex<_Tp>& __x, const _Up& __y) +{ + typedef complex::type> result_type; + return _VSTD::pow(result_type(__x), result_type(__y)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_Tp>::value, + complex::type> +>::type +pow(const _Tp& __x, const complex<_Up>& __y) +{ + typedef complex::type> result_type; + return _VSTD::pow(result_type(__x), result_type(__y)); +} + +// __sqr, computes pow(x, 2) + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +__sqr(const complex<_Tp>& __x) +{ + return complex<_Tp>((__x.real() - __x.imag()) * (__x.real() + __x.imag()), + _Tp(2) * __x.real() * __x.imag()); +} + +// asinh + +template +complex<_Tp> +asinh(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (__libcpp_isnan_or_builtin(__x.imag())) + return __x; + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); + return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag())); + } + if (__libcpp_isnan_or_builtin(__x.real())) + { + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(__x.imag(), __x.real()); + if (__x.imag() == 0) + return __x; + return complex<_Tp>(__x.real(), __x.real()); + } + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(copysign(__x.imag(), __x.real()), copysign(__pi/_Tp(2), __x.imag())); + complex<_Tp> __z = log(__x + sqrt(__sqr(__x) + _Tp(1))); + return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag())); +} + +// acosh + +template +complex<_Tp> +acosh(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (__libcpp_isnan_or_builtin(__x.imag())) + return complex<_Tp>(abs(__x.real()), __x.imag()); + if (__libcpp_isinf_or_builtin(__x.imag())) + { + if (__x.real() > 0) + return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); + else + return complex<_Tp>(-__x.real(), copysign(__pi * _Tp(0.75), __x.imag())); + } + if (__x.real() < 0) + return complex<_Tp>(-__x.real(), copysign(__pi, __x.imag())); + return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag())); + } + if (__libcpp_isnan_or_builtin(__x.real())) + { + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(abs(__x.imag()), __x.real()); + return complex<_Tp>(__x.real(), __x.real()); + } + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(abs(__x.imag()), copysign(__pi/_Tp(2), __x.imag())); + complex<_Tp> __z = log(__x + sqrt(__sqr(__x) - _Tp(1))); + return complex<_Tp>(copysign(__z.real(), _Tp(0)), copysign(__z.imag(), __x.imag())); +} + +// atanh + +template +complex<_Tp> +atanh(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (__libcpp_isinf_or_builtin(__x.imag())) + { + return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag())); + } + if (__libcpp_isnan_or_builtin(__x.imag())) + { + if (__libcpp_isinf_or_builtin(__x.real()) || __x.real() == 0) + return complex<_Tp>(copysign(_Tp(0), __x.real()), __x.imag()); + return complex<_Tp>(__x.imag(), __x.imag()); + } + if (__libcpp_isnan_or_builtin(__x.real())) + { + return complex<_Tp>(__x.real(), __x.real()); + } + if (__libcpp_isinf_or_builtin(__x.real())) + { + return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag())); + } + if (abs(__x.real()) == _Tp(1) && __x.imag() == _Tp(0)) + { + return complex<_Tp>(copysign(_Tp(INFINITY), __x.real()), copysign(_Tp(0), __x.imag())); + } + complex<_Tp> __z = log((_Tp(1) + __x) / (_Tp(1) - __x)) / _Tp(2); + return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag())); +} + +// sinh + +template +complex<_Tp> +sinh(const complex<_Tp>& __x) +{ + if (__libcpp_isinf_or_builtin(__x.real()) && !__libcpp_isfinite_or_builtin(__x.imag())) + return complex<_Tp>(__x.real(), _Tp(NAN)); + if (__x.real() == 0 && !__libcpp_isfinite_or_builtin(__x.imag())) + return complex<_Tp>(__x.real(), _Tp(NAN)); + if (__x.imag() == 0 && !__libcpp_isfinite_or_builtin(__x.real())) + return __x; + return complex<_Tp>(sinh(__x.real()) * cos(__x.imag()), cosh(__x.real()) * sin(__x.imag())); +} + +// cosh + +template +complex<_Tp> +cosh(const complex<_Tp>& __x) +{ + if (__libcpp_isinf_or_builtin(__x.real()) && !__libcpp_isfinite_or_builtin(__x.imag())) + return complex<_Tp>(abs(__x.real()), _Tp(NAN)); + if (__x.real() == 0 && !__libcpp_isfinite_or_builtin(__x.imag())) + return complex<_Tp>(_Tp(NAN), __x.real()); + if (__x.real() == 0 && __x.imag() == 0) + return complex<_Tp>(_Tp(1), __x.imag()); + if (__x.imag() == 0 && !__libcpp_isfinite_or_builtin(__x.real())) + return complex<_Tp>(abs(__x.real()), __x.imag()); + return complex<_Tp>(cosh(__x.real()) * cos(__x.imag()), sinh(__x.real()) * sin(__x.imag())); +} + +// tanh + +template +complex<_Tp> +tanh(const complex<_Tp>& __x) +{ + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (!__libcpp_isfinite_or_builtin(__x.imag())) + return complex<_Tp>(_Tp(1), _Tp(0)); + return complex<_Tp>(_Tp(1), copysign(_Tp(0), sin(_Tp(2) * __x.imag()))); + } + if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0) + return __x; + _Tp __2r(_Tp(2) * __x.real()); + _Tp __2i(_Tp(2) * __x.imag()); + _Tp __d(cosh(__2r) + cos(__2i)); + _Tp __2rsh(sinh(__2r)); + if (__libcpp_isinf_or_builtin(__2rsh) && __libcpp_isinf_or_builtin(__d)) + return complex<_Tp>(__2rsh > _Tp(0) ? _Tp(1) : _Tp(-1), + __2i > _Tp(0) ? _Tp(0) : _Tp(-0.)); + return complex<_Tp>(__2rsh/__d, sin(__2i)/__d); +} + +// asin + +template +complex<_Tp> +asin(const complex<_Tp>& __x) +{ + complex<_Tp> __z = asinh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +// acos + +template +complex<_Tp> +acos(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (__libcpp_isnan_or_builtin(__x.imag())) + return complex<_Tp>(__x.imag(), __x.real()); + if (__libcpp_isinf_or_builtin(__x.imag())) + { + if (__x.real() < _Tp(0)) + return complex<_Tp>(_Tp(0.75) * __pi, -__x.imag()); + return complex<_Tp>(_Tp(0.25) * __pi, -__x.imag()); + } + if (__x.real() < _Tp(0)) + return complex<_Tp>(__pi, signbit(__x.imag()) ? -__x.real() : __x.real()); + return complex<_Tp>(_Tp(0), signbit(__x.imag()) ? __x.real() : -__x.real()); + } + if (__libcpp_isnan_or_builtin(__x.real())) + { + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(__x.real(), -__x.imag()); + return complex<_Tp>(__x.real(), __x.real()); + } + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(__pi/_Tp(2), -__x.imag()); + if (__x.real() == 0 && (__x.imag() == 0 || isnan(__x.imag()))) + return complex<_Tp>(__pi/_Tp(2), -__x.imag()); + complex<_Tp> __z = log(__x + sqrt(__sqr(__x) - _Tp(1))); + if (signbit(__x.imag())) + return complex<_Tp>(abs(__z.imag()), abs(__z.real())); + return complex<_Tp>(abs(__z.imag()), -abs(__z.real())); +} + +// atan + +template +complex<_Tp> +atan(const complex<_Tp>& __x) +{ + complex<_Tp> __z = atanh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +// sin + +template +complex<_Tp> +sin(const complex<_Tp>& __x) +{ + complex<_Tp> __z = sinh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +// cos + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +cos(const complex<_Tp>& __x) +{ + return cosh(complex<_Tp>(-__x.imag(), __x.real())); +} + +// tan + +template +complex<_Tp> +tan(const complex<_Tp>& __x) +{ + complex<_Tp> __z = tanh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +#ifndef THINNER_HEADER +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x) +{ + if (__is.good()) + { + ws(__is); + if (__is.peek() == _CharT('(')) + { + __is.get(); + _Tp __r; + __is >> __r; + if (!__is.fail()) + { + ws(__is); + _CharT __c = __is.peek(); + if (__c == _CharT(',')) + { + __is.get(); + _Tp __i; + __is >> __i; + if (!__is.fail()) + { + ws(__is); + __c = __is.peek(); + if (__c == _CharT(')')) + { + __is.get(); + __x = complex<_Tp>(__r, __i); + } + else + __is.setstate(ios_base::failbit); + } + else + __is.setstate(ios_base::failbit); + } + else if (__c == _CharT(')')) + { + __is.get(); + __x = complex<_Tp>(__r, _Tp(0)); + } + else + __is.setstate(ios_base::failbit); + } + else + __is.setstate(ios_base::failbit); + } + else + { + _Tp __r; + __is >> __r; + if (!__is.fail()) + __x = complex<_Tp>(__r, _Tp(0)); + else + __is.setstate(ios_base::failbit); + } + } + else + __is.setstate(ios_base::failbit); + return __is; +} + +template +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x) +{ + basic_ostringstream<_CharT, _Traits> __s; + __s.flags(__os.flags()); + __s.imbue(__os.getloc()); + __s.precision(__os.precision()); + __s << '(' << __x.real() << ',' << __x.imag() << ')'; + return __os << __s.str(); +} + +#if _LIBCPP_STD_VER > 11 +// Literal suffix for complex number literals [complex.literals] +inline namespace literals +{ + inline namespace complex_literals + { + constexpr complex operator""il(long double __im) + { + return { 0.0l, __im }; + } + + constexpr complex operator""il(unsigned long long __im) + { + return { 0.0l, static_cast(__im) }; + } + + + constexpr complex operator""i(long double __im) + { + return { 0.0, static_cast(__im) }; + } + + constexpr complex operator""i(unsigned long long __im) + { + return { 0.0, static_cast(__im) }; + } + + + constexpr complex operator""if(long double __im) + { + return { 0.0f, static_cast(__im) }; + } + + constexpr complex operator""if(unsigned long long __im) + { + return { 0.0f, static_cast(__im) }; + } + } +} +#endif +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_COMPLEX + diff --git a/libaxx/include/external/libcxx/include/__config b/libaxx/include/external/libcxx/include/__config new file mode 100644 index 000000000..dce88939f --- /dev/null +++ b/libaxx/include/external/libcxx/include/__config @@ -0,0 +1,19 @@ +#ifndef LIBAXX_LIBCXX_CONFIG +#define LIBAXX_LIBCXX_CONFIG + +#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { +#define _LIBCPP_END_NAMESPACE_STD } +#define _LIBCPP_TEMPLATE_VIS __attribute__ ((__visibility__("default"))) +#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__)) +#define _LIBCPP_CONSTEXPR_AFTER_CXX11 +#define _LIBCPP_CONSTEXPR_AFTER_CXX14 +#define _LIBCPP_CONSTEXPR constexpr +#define __has_feature(__x) 0 +#define _LIBCPP_NO_CFI +#define _NOEXCEPT noexcept +#define _NOEXCEPT_(x) noexcept(x) +#define _LIBCPP_HAS_NO_INT128 +#define _VSTD std +#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__visibility__("hidden"), __always_inline__)) + +#endif diff --git a/libaxx/include/external/libcxx/include/cmath b/libaxx/include/external/libcxx/include/cmath new file mode 100644 index 000000000..9b28866b4 --- /dev/null +++ b/libaxx/include/external/libcxx/include/cmath @@ -0,0 +1,32 @@ +#ifndef LIBAXX_LIBCXX_CMATH +#define LIBAXX_LIBCXX_CMATH + +#include_next + +#include "type_traits" + +namespace std { + +template inline constexpr typename enable_if::value, bool>::type __libcpp_isnan_or_builtin(_A1 __lcpp_x) noexcept { + return __builtin_isnan(__lcpp_x); +} + +template inline constexpr typename enable_if::value, bool>::type __libcpp_isinf_or_builtin(_A1 __lcpp_x) noexcept { + return __builtin_isinf(__lcpp_x); +} + +template inline constexpr typename enable_if::value, bool>::type __libcpp_isfinite_or_builtin(_A1 __lcpp_x) noexcept { + return __builtin_isfinite(__lcpp_x); +} + +inline float abs(float __lcpp_x) noexcept { + return fabsf(__lcpp_x); +} + +inline double abs(double __lcpp_x) noexcept { + return fabs(__lcpp_x); +} + +} + +#endif diff --git a/libaxx/include/external/libcxx/include/type_traits b/libaxx/include/external/libcxx/include/type_traits new file mode 100644 index 000000000..92c8107b9 --- /dev/null +++ b/libaxx/include/external/libcxx/include/type_traits @@ -0,0 +1,147 @@ +#ifndef LIBAXX_LIBCXX_TYPE_TRAITS +#define LIBAXX_LIBCXX_TYPE_TRAITS + +namespace std { + +template struct remove_const {typedef _Tp type;}; +template struct remove_const {typedef _Tp type;}; +template struct remove_volatile {typedef _Tp type;}; +template struct remove_volatile {typedef _Tp type;}; +template struct remove_cv {typedef typename remove_volatile::type>::type type;}; + +template +struct integral_constant +{ + static constexpr const _Tp value = __v; + typedef _Tp value_type; + typedef integral_constant type; + inline constexpr operator value_type() const noexcept {return value;} +}; + +typedef integral_constant true_type; +typedef integral_constant false_type; + +// is_integral + +template struct __libcpp_is_integral : public false_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; +template <> struct __libcpp_is_integral : public true_type {}; + +template struct is_integral : public __libcpp_is_integral::type> {}; + +// is_floating_point + +template struct __libcpp_is_floating_point : public false_type {}; +template <> struct __libcpp_is_floating_point : public true_type {}; +template <> struct __libcpp_is_floating_point : public true_type {}; + +template struct is_floating_point : public __libcpp_is_floating_point::type> {}; + +// enable_if + +template struct enable_if {}; +template struct _LIBCPP_TEMPLATE_VIS enable_if {typedef _Tp type;}; + +// is_same + +template struct is_same : public false_type {}; +template struct is_same<_Tp, _Tp> : public true_type {}; + +// declval + +template struct add_rvalue_reference {typedef _Tp&& type;}; +template <> struct add_rvalue_reference {typedef void type;}; +template <> struct add_rvalue_reference {typedef const void type;}; +template <> struct add_rvalue_reference {typedef volatile void type;}; +template <> struct add_rvalue_reference {typedef const volatile void type;}; +template typename add_rvalue_reference<_Tp>::type declval() noexcept; + +//__numeric_type + +template +struct __numeric_type +{ + static void __test(...); + static float __test(float); + static double __test(char); + static double __test(int); + static double __test(unsigned); + static double __test(long); + static double __test(unsigned long); + static double __test(long long); + static double __test(unsigned long long); + static double __test(double); + + typedef decltype(__test(declval<_Tp>())) type; + static const bool value = !is_same::value; +}; + +template <> +struct __numeric_type +{ + static const bool value = true; +}; + +// __promote + +template ::value && + __numeric_type<_A2>::value && + __numeric_type<_A3>::value> +class __promote_imp +{ +public: + static const bool value = false; +}; + +template +class __promote_imp<_A1, _A2, _A3, true> +{ +private: + typedef typename __promote_imp<_A1>::type __type1; + typedef typename __promote_imp<_A2>::type __type2; + typedef typename __promote_imp<_A3>::type __type3; +public: + typedef decltype(__type1() + __type2() + __type3()) type; + static const bool value = true; +}; + +template +class __promote_imp<_A1, _A2, void, true> +{ +private: + typedef typename __promote_imp<_A1>::type __type1; + typedef typename __promote_imp<_A2>::type __type2; +public: + typedef decltype(__type1() + __type2()) type; + static const bool value = true; +}; + +template +class __promote_imp<_A1, void, void, true> +{ +public: + typedef typename __numeric_type<_A1>::type type; + static const bool value = true; +}; + +template +class __promote : public __promote_imp<_A1, _A2, _A3> {}; + +// is_arithmetic + +template struct is_arithmetic : public integral_constant::value || is_floating_point<_Tp>::value> {}; + +} +#endif diff --git a/libaxx/include/type_traits b/libaxx/include/type_traits new file mode 100644 index 000000000..68998dc76 --- /dev/null +++ b/libaxx/include/type_traits @@ -0,0 +1,12 @@ +#ifndef LIBAXX_TYPE_TRAITS +#define LIBAXX_TYPE_TRAITS + +namespace std { + +template struct remove_reference {typedef T type;}; +template struct remove_reference {typedef T type;}; +template struct remove_reference {typedef T type;}; + +} + +#endif diff --git a/libaxx/include/utility b/libaxx/include/utility index 8885d6088..71402947a 100644 --- a/libaxx/include/utility +++ b/libaxx/include/utility @@ -1,11 +1,9 @@ #ifndef LIBAXX_UTILITY #define LIBAXX_UTILITY -namespace std { +#include -template struct remove_reference {typedef T type;}; -template struct remove_reference {typedef T type;}; -template struct remove_reference {typedef T type;}; +namespace std { template typename remove_reference::type&& move(T&& a) { return (typename remove_reference::type&&)a;