diff options
Diffstat (limited to 'libstdc++-v3/include/std/complex')
-rw-r--r-- | libstdc++-v3/include/std/complex | 865 |
1 files changed, 417 insertions, 448 deletions
diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex index e3feef0918f..0fa381cbeac 100644 --- a/libstdc++-v3/include/std/complex +++ b/libstdc++-v3/include/std/complex @@ -121,29 +121,71 @@ _GLIBCXX_BEGIN_NAMESPACE(std) /// Default constructor. First parameter is x, second parameter is y. /// Unspecified parameters default to 0. - complex(const _Tp& = _Tp(), const _Tp & = _Tp()); + complex(const _Tp& __r = _Tp(), const _Tp& __i = _Tp()) + : _M_real(__r), _M_imag(__i) { } // Lets the compiler synthesize the copy constructor // complex (const complex<_Tp>&); /// Copy constructor. template<typename _Up> - complex(const complex<_Up>&); + complex(const complex<_Up>& __z) + : _M_real(__z.real()), _M_imag(__z.imag()) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + _Tp real() const + { return _M_real; } + + _Tp imag() const + { return _M_imag; } +#else /// Return real part of complex number. - _Tp& real(); + _Tp& real() + { return _M_real; } + /// Return real part of complex number. - const _Tp& real() const; + const _Tp& real() const + { return _M_real; } + /// Return imaginary part of complex number. - _Tp& imag(); + _Tp& imag() + { return _M_imag; } + /// Return imaginary part of complex number. - const _Tp& imag() const; + const _Tp& imag() const + { return _M_imag; } +#endif + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + void real(_Tp __val) + { _M_real = __val; } + + void imag(_Tp __val) + { _M_imag = __val; } /// Assign this complex number to scalar @a t. complex<_Tp>& operator=(const _Tp&); + /// Add @a t to this complex number. - complex<_Tp>& operator+=(const _Tp&); + // 26.2.5/1 + complex<_Tp>& + operator+=(const _Tp& __t) + { + _M_real += __t; + return *this; + } + /// Subtract @a t from this complex number. - complex<_Tp>& operator-=(const _Tp&); + // 26.2.5/3 + complex<_Tp>& + operator-=(const _Tp& __t) + { + _M_real -= __t; + return *this; + } + /// Multiply this complex number by @a t. complex<_Tp>& operator*=(const _Tp&); /// Divide this complex number by @a t. @@ -168,7 +210,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _Up> complex<_Tp>& operator/=(const complex<_Up>&); - const complex& __rep() const; + const complex& __rep() const + { return *this; } private: _Tp _M_real; @@ -176,33 +219,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) }; template<typename _Tp> - inline _Tp& - complex<_Tp>::real() { return _M_real; } - - template<typename _Tp> - inline const _Tp& - complex<_Tp>::real() const { return _M_real; } - - template<typename _Tp> - inline _Tp& - complex<_Tp>::imag() { return _M_imag; } - - template<typename _Tp> - inline const _Tp& - complex<_Tp>::imag() const { return _M_imag; } - - template<typename _Tp> - inline - complex<_Tp>::complex(const _Tp& __r, const _Tp& __i) - : _M_real(__r), _M_imag(__i) { } - - template<typename _Tp> - template<typename _Up> - inline - complex<_Tp>::complex(const complex<_Up>& __z) - : _M_real(__z.real()), _M_imag(__z.imag()) { } - - template<typename _Tp> complex<_Tp>& complex<_Tp>::operator=(const _Tp& __t) { @@ -211,24 +227,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return *this; } - // 26.2.5/1 - template<typename _Tp> - inline complex<_Tp>& - complex<_Tp>::operator+=(const _Tp& __t) - { - _M_real += __t; - return *this; - } - - // 26.2.5/3 - template<typename _Tp> - inline complex<_Tp>& - complex<_Tp>::operator-=(const _Tp& __t) - { - _M_real -= __t; - return *this; - } - // 26.2.5/5 template<typename _Tp> complex<_Tp>& @@ -307,10 +305,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _M_real = __r / __n; return *this; } - - template<typename _Tp> - inline const complex<_Tp>& - complex<_Tp>::__rep() const { return *this; } // Operators: //@{ @@ -528,6 +522,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } // Values +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Tp> + inline _Tp + real(const complex<_Tp>& __z) + { return __z.real(); } + + template<typename _Tp> + inline _Tp + imag(const complex<_Tp>& __z) + { return __z.imag(); } +#else template<typename _Tp> inline _Tp& real(complex<_Tp>& __z) @@ -547,6 +552,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) inline const _Tp& imag(const complex<_Tp>& __z) { return __z.imag(); } +#endif // 26.2.7/3 abs(__z): Returns the magnitude of __z. template<typename _Tp> @@ -995,7 +1001,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return __x > _Tp() ? std::polar(pow(__x, __y.real()), __y.imag() * log(__x)) - : std::pow(complex<_Tp>(__x, _Tp()), __y); + : std::pow(complex<_Tp>(__x), __y); } // 26.2.3 complex specializations @@ -1008,35 +1014,133 @@ _GLIBCXX_BEGIN_NAMESPACE(std) complex(_ComplexT __z) : _M_value(__z) { } - complex(float = 0.0f, float = 0.0f); + complex(float __r = 0.0f, float __i = 0.0f) + { + __real__ _M_value = __r; + __imag__ _M_value = __i; + } explicit complex(const complex<double>&); - explicit complex(const complex<long double>&); + explicit complex(const complex<long double>&); + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + float real() const + { return __real__ _M_value; } - float& real(); - const float& real() const; - float& imag(); - const float& imag() const; + float imag() const + { return __imag__ _M_value; } +#else + float& real() + { return __real__ _M_value; } - complex<float>& operator=(float); - complex<float>& operator+=(float); - complex<float>& operator-=(float); - complex<float>& operator*=(float); - complex<float>& operator/=(float); + const float& real() const + { return __real__ _M_value; } + + float& imag() + { return __imag__ _M_value; } + + const float& imag() const + { return __imag__ _M_value; } +#endif + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + void real(float __val) + { __real__ _M_value = __val; } + + void imag(float __val) + { __imag__ _M_value = __val; } + + complex<float>& + operator=(float __f) + { + __real__ _M_value = __f; + __imag__ _M_value = 0.0f; + return *this; + } + + complex<float>& + operator+=(float __f) + { + __real__ _M_value += __f; + return *this; + } + + complex<float>& + operator-=(float __f) + { + __real__ _M_value -= __f; + return *this; + } + + complex<float>& + operator*=(float __f) + { + _M_value *= __f; + return *this; + } + + complex<float>& + operator/=(float __f) + { + _M_value /= __f; + return *this; + } // Let the compiler synthesize the copy and assignment // operator. It always does a pretty good job. - // complex& operator= (const complex&); + // complex& operator=(const complex&); + template<typename _Tp> - complex<float>&operator=(const complex<_Tp>&); + complex<float>& + operator=(const complex<_Tp>& __z) + { + __real__ _M_value = __z.real(); + __imag__ _M_value = __z.imag(); + return *this; + } + template<typename _Tp> - complex<float>& operator+=(const complex<_Tp>&); + complex<float>& + operator+=(const complex<_Tp>& __z) + { + __real__ _M_value += __z.real(); + __imag__ _M_value += __z.imag(); + return *this; + } + template<class _Tp> - complex<float>& operator-=(const complex<_Tp>&); + complex<float>& + operator-=(const complex<_Tp>& __z) + { + __real__ _M_value -= __z.real(); + __imag__ _M_value -= __z.imag(); + return *this; + } + template<class _Tp> - complex<float>& operator*=(const complex<_Tp>&); + complex<float>& + operator*=(const complex<_Tp>& __z) + { + _ComplexT __t; + __real__ __t = __z.real(); + __imag__ __t = __z.imag(); + _M_value *= __t; + return *this; + } + template<class _Tp> - complex<float>&operator/=(const complex<_Tp>&); + complex<float>& + operator/=(const complex<_Tp>& __z) + { + _ComplexT __t; + __real__ __t = __z.real(); + __imag__ __t = __z.imag(); + _M_value /= __t; + return *this; + } const _ComplexT& __rep() const { return _M_value; } @@ -1044,114 +1148,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _ComplexT _M_value; }; - inline float& - complex<float>::real() - { return __real__ _M_value; } - - inline const float& - complex<float>::real() const - { return __real__ _M_value; } - - inline float& - complex<float>::imag() - { return __imag__ _M_value; } - - inline const float& - complex<float>::imag() const - { return __imag__ _M_value; } - - inline - complex<float>::complex(float __r, float __i) - { - __real__ _M_value = __r; - __imag__ _M_value = __i; - } - - inline complex<float>& - complex<float>::operator=(float __f) - { - __real__ _M_value = __f; - __imag__ _M_value = 0.0f; - return *this; - } - - inline complex<float>& - complex<float>::operator+=(float __f) - { - __real__ _M_value += __f; - return *this; - } - - inline complex<float>& - complex<float>::operator-=(float __f) - { - __real__ _M_value -= __f; - return *this; - } - - inline complex<float>& - complex<float>::operator*=(float __f) - { - _M_value *= __f; - return *this; - } - - inline complex<float>& - complex<float>::operator/=(float __f) - { - _M_value /= __f; - return *this; - } - - template<typename _Tp> - inline complex<float>& - complex<float>::operator=(const complex<_Tp>& __z) - { - __real__ _M_value = __z.real(); - __imag__ _M_value = __z.imag(); - return *this; - } - - template<typename _Tp> - inline complex<float>& - complex<float>::operator+=(const complex<_Tp>& __z) - { - __real__ _M_value += __z.real(); - __imag__ _M_value += __z.imag(); - return *this; - } - - template<typename _Tp> - inline complex<float>& - complex<float>::operator-=(const complex<_Tp>& __z) - { - __real__ _M_value -= __z.real(); - __imag__ _M_value -= __z.imag(); - return *this; - } - - template<typename _Tp> - inline complex<float>& - complex<float>::operator*=(const complex<_Tp>& __z) - { - _ComplexT __t; - __real__ __t = __z.real(); - __imag__ __t = __z.imag(); - _M_value *= __t; - return *this; - } - - template<typename _Tp> - inline complex<float>& - complex<float>::operator/=(const complex<_Tp>& __z) - { - _ComplexT __t; - __real__ __t = __z.real(); - __imag__ __t = __z.imag(); - _M_value /= __t; - return *this; - } - // 26.2.3 complex specializations // complex<double> specialization template<> @@ -1162,34 +1158,134 @@ _GLIBCXX_BEGIN_NAMESPACE(std) complex(_ComplexT __z) : _M_value(__z) { } - complex(double = 0.0, double = 0.0); + complex(double __r = 0.0, double __i = 0.0) + { + __real__ _M_value = __r; + __imag__ _M_value = __i; + } + + complex(const complex<float>& __z) + : _M_value(__z.__rep()) { } + + explicit complex(const complex<long double>&); + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + double real() const + { return __real__ _M_value; } + + double imag() const + { return __imag__ _M_value; } +#else + double& real() + { return __real__ _M_value; } + + const double& real() const + { return __real__ _M_value; } - complex(const complex<float>&); - explicit complex(const complex<long double>&); + double& imag() + { return __imag__ _M_value; } - double& real(); - const double& real() const; - double& imag(); - const double& imag() const; + const double& imag() const + { return __imag__ _M_value; } +#endif - complex<double>& operator=(double); - complex<double>& operator+=(double); - complex<double>& operator-=(double); - complex<double>& operator*=(double); - complex<double>& operator/=(double); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + void real(double __val) + { __real__ _M_value = __val; } + + void imag(double __val) + { __imag__ _M_value = __val; } + + complex<double>& + operator=(double __d) + { + __real__ _M_value = __d; + __imag__ _M_value = 0.0; + return *this; + } + + complex<double>& + operator+=(double __d) + { + __real__ _M_value += __d; + return *this; + } + + complex<double>& + operator-=(double __d) + { + __real__ _M_value -= __d; + return *this; + } + + complex<double>& + operator*=(double __d) + { + _M_value *= __d; + return *this; + } + + complex<double>& + operator/=(double __d) + { + _M_value /= __d; + return *this; + } // The compiler will synthesize this, efficiently. - // complex& operator= (const complex&); + // complex& operator=(const complex&); + template<typename _Tp> - complex<double>& operator=(const complex<_Tp>&); + complex<double>& + operator=(const complex<_Tp>& __z) + { + __real__ _M_value = __z.real(); + __imag__ _M_value = __z.imag(); + return *this; + } + template<typename _Tp> - complex<double>& operator+=(const complex<_Tp>&); + complex<double>& + operator+=(const complex<_Tp>& __z) + { + __real__ _M_value += __z.real(); + __imag__ _M_value += __z.imag(); + return *this; + } + template<typename _Tp> - complex<double>& operator-=(const complex<_Tp>&); + complex<double>& + operator-=(const complex<_Tp>& __z) + { + __real__ _M_value -= __z.real(); + __imag__ _M_value -= __z.imag(); + return *this; + } + template<typename _Tp> - complex<double>& operator*=(const complex<_Tp>&); + complex<double>& + operator*=(const complex<_Tp>& __z) + { + _ComplexT __t; + __real__ __t = __z.real(); + __imag__ __t = __z.imag(); + _M_value *= __t; + return *this; + } + template<typename _Tp> - complex<double>& operator/=(const complex<_Tp>&); + complex<double>& + operator/=(const complex<_Tp>& __z) + { + _ComplexT __t; + __real__ __t = __z.real(); + __imag__ __t = __z.imag(); + _M_value /= __t; + return *this; + } const _ComplexT& __rep() const { return _M_value; } @@ -1197,114 +1293,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _ComplexT _M_value; }; - inline double& - complex<double>::real() - { return __real__ _M_value; } - - inline const double& - complex<double>::real() const - { return __real__ _M_value; } - - inline double& - complex<double>::imag() - { return __imag__ _M_value; } - - inline const double& - complex<double>::imag() const - { return __imag__ _M_value; } - - inline - complex<double>::complex(double __r, double __i) - { - __real__ _M_value = __r; - __imag__ _M_value = __i; - } - - inline complex<double>& - complex<double>::operator=(double __d) - { - __real__ _M_value = __d; - __imag__ _M_value = 0.0; - return *this; - } - - inline complex<double>& - complex<double>::operator+=(double __d) - { - __real__ _M_value += __d; - return *this; - } - - inline complex<double>& - complex<double>::operator-=(double __d) - { - __real__ _M_value -= __d; - return *this; - } - - inline complex<double>& - complex<double>::operator*=(double __d) - { - _M_value *= __d; - return *this; - } - - inline complex<double>& - complex<double>::operator/=(double __d) - { - _M_value /= __d; - return *this; - } - - template<typename _Tp> - inline complex<double>& - complex<double>::operator=(const complex<_Tp>& __z) - { - __real__ _M_value = __z.real(); - __imag__ _M_value = __z.imag(); - return *this; - } - - template<typename _Tp> - inline complex<double>& - complex<double>::operator+=(const complex<_Tp>& __z) - { - __real__ _M_value += __z.real(); - __imag__ _M_value += __z.imag(); - return *this; - } - - template<typename _Tp> - inline complex<double>& - complex<double>::operator-=(const complex<_Tp>& __z) - { - __real__ _M_value -= __z.real(); - __imag__ _M_value -= __z.imag(); - return *this; - } - - template<typename _Tp> - inline complex<double>& - complex<double>::operator*=(const complex<_Tp>& __z) - { - _ComplexT __t; - __real__ __t = __z.real(); - __imag__ __t = __z.imag(); - _M_value *= __t; - return *this; - } - - template<typename _Tp> - inline complex<double>& - complex<double>::operator/=(const complex<_Tp>& __z) - { - _ComplexT __t; - __real__ __t = __z.real(); - __imag__ __t = __z.imag(); - _M_value /= __t; - return *this; - } - // 26.2.3 complex specializations // complex<long double> specialization template<> @@ -1315,34 +1303,135 @@ _GLIBCXX_BEGIN_NAMESPACE(std) complex(_ComplexT __z) : _M_value(__z) { } - complex(long double = 0.0L, long double = 0.0L); + complex(long double __r = 0.0L, long double __i = 0.0L) + { + __real__ _M_value = __r; + __imag__ _M_value = __i; + } + + complex(const complex<float>& __z) + : _M_value(__z.__rep()) { } + + complex(const complex<double>& __z) + : _M_value(__z.__rep()) { } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + long double real() const + { return __real__ _M_value; } + + long double imag() const + { return __imag__ _M_value; } +#else + long double& real() + { return __real__ _M_value; } + + const long double& real() const + { return __real__ _M_value; } - complex(const complex<float>&); - complex(const complex<double>&); + long double& imag() + { return __imag__ _M_value; } - long double& real(); - const long double& real() const; - long double& imag(); - const long double& imag() const; + const long double& imag() const + { return __imag__ _M_value; } +#endif - complex<long double>& operator= (long double); - complex<long double>& operator+= (long double); - complex<long double>& operator-= (long double); - complex<long double>& operator*= (long double); - complex<long double>& operator/= (long double); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + void real(long double __val) + { __real__ _M_value = __val; } + + void imag(long double __val) + { __imag__ _M_value = __val; } + + complex<long double>& + operator=(long double __r) + { + __real__ _M_value = __r; + __imag__ _M_value = 0.0L; + return *this; + } + + complex<long double>& + operator+=(long double __r) + { + __real__ _M_value += __r; + return *this; + } + + complex<long double>& + operator-=(long double __r) + { + __real__ _M_value -= __r; + return *this; + } + + complex<long double>& + operator*=(long double __r) + { + _M_value *= __r; + return *this; + } + + complex<long double>& + operator/=(long double __r) + { + _M_value /= __r; + return *this; + } // The compiler knows how to do this efficiently - // complex& operator= (const complex&); + // complex& operator=(const complex&); + template<typename _Tp> - complex<long double>& operator=(const complex<_Tp>&); + complex<long double>& + operator=(const complex<_Tp>& __z) + { + __real__ _M_value = __z.real(); + __imag__ _M_value = __z.imag(); + return *this; + } + template<typename _Tp> - complex<long double>& operator+=(const complex<_Tp>&); + complex<long double>& + operator+=(const complex<_Tp>& __z) + { + __real__ _M_value += __z.real(); + __imag__ _M_value += __z.imag(); + return *this; + } + template<typename _Tp> - complex<long double>& operator-=(const complex<_Tp>&); + complex<long double>& + operator-=(const complex<_Tp>& __z) + { + __real__ _M_value -= __z.real(); + __imag__ _M_value -= __z.imag(); + return *this; + } + template<typename _Tp> - complex<long double>& operator*=(const complex<_Tp>&); + complex<long double>& + operator*=(const complex<_Tp>& __z) + { + _ComplexT __t; + __real__ __t = __z.real(); + __imag__ __t = __z.imag(); + _M_value *= __t; + return *this; + } + template<typename _Tp> - complex<long double>& operator/=(const complex<_Tp>&); + complex<long double>& + operator/=(const complex<_Tp>& __z) + { + _ComplexT __t; + __real__ __t = __z.real(); + __imag__ __t = __z.imag(); + _M_value /= __t; + return *this; + } const _ComplexT& __rep() const { return _M_value; } @@ -1350,114 +1439,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _ComplexT _M_value; }; - inline - complex<long double>::complex(long double __r, long double __i) - { - __real__ _M_value = __r; - __imag__ _M_value = __i; - } - - inline long double& - complex<long double>::real() - { return __real__ _M_value; } - - inline const long double& - complex<long double>::real() const - { return __real__ _M_value; } - - inline long double& - complex<long double>::imag() - { return __imag__ _M_value; } - - inline const long double& - complex<long double>::imag() const - { return __imag__ _M_value; } - - inline complex<long double>& - complex<long double>::operator=(long double __r) - { - __real__ _M_value = __r; - __imag__ _M_value = 0.0L; - return *this; - } - - inline complex<long double>& - complex<long double>::operator+=(long double __r) - { - __real__ _M_value += __r; - return *this; - } - - inline complex<long double>& - complex<long double>::operator-=(long double __r) - { - __real__ _M_value -= __r; - return *this; - } - - inline complex<long double>& - complex<long double>::operator*=(long double __r) - { - _M_value *= __r; - return *this; - } - - inline complex<long double>& - complex<long double>::operator/=(long double __r) - { - _M_value /= __r; - return *this; - } - - template<typename _Tp> - inline complex<long double>& - complex<long double>::operator=(const complex<_Tp>& __z) - { - __real__ _M_value = __z.real(); - __imag__ _M_value = __z.imag(); - return *this; - } - - template<typename _Tp> - inline complex<long double>& - complex<long double>::operator+=(const complex<_Tp>& __z) - { - __real__ _M_value += __z.real(); - __imag__ _M_value += __z.imag(); - return *this; - } - - template<typename _Tp> - inline complex<long double>& - complex<long double>::operator-=(const complex<_Tp>& __z) - { - __real__ _M_value -= __z.real(); - __imag__ _M_value -= __z.imag(); - return *this; - } - - template<typename _Tp> - inline complex<long double>& - complex<long double>::operator*=(const complex<_Tp>& __z) - { - _ComplexT __t; - __real__ __t = __z.real(); - __imag__ __t = __z.imag(); - _M_value *= __t; - return *this; - } - - template<typename _Tp> - inline complex<long double>& - complex<long double>::operator/=(const complex<_Tp>& __z) - { - _ComplexT __t; - __real__ __t = __z.real(); - __imag__ __t = __z.imag(); - _M_value /= __t; - return *this; - } - // These bits have to be at the end of this file, so that the // specializations have all been defined. // ??? No, they have to be there because of compiler limitation at @@ -1471,21 +1452,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) : _M_value(__z.__rep()) { } inline - complex<double>::complex(const complex<float>& __z) - : _M_value(__z.__rep()) { } - - inline complex<double>::complex(const complex<long double>& __z) : _M_value(__z.__rep()) { } - inline - complex<long double>::complex(const complex<float>& __z) - : _M_value(__z.__rep()) { } - - inline - complex<long double>::complex(const complex<double>& __z) - : _M_value(__z.__rep()) { } - // Inhibit implicit instantiations for required instantiations, // which are defined via explicit instantiations elsewhere. // NB: This syntax is a GNU extension. |