From 2acceeac67a10df936fd59f47e3ee72f87e162f5 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 25 May 2008 16:55:23 +0000 Subject: [PATCH] complex: Trivial stylistic changes... 2008-05-25 Paolo Carlini * include/std/complex: Trivial stylistic changes, define inline members inline, consistently with the rest of the library. (pow(const _Tp&, const complex<>&)): Minor tweak. From-SVN: r135872 --- libstdc++-v3/ChangeLog | 6 + libstdc++-v3/include/std/complex | 797 +++++++++++++------------------ 2 files changed, 347 insertions(+), 456 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 657bde17864..19e3dca233f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2008-05-25 Paolo Carlini + + * include/std/complex: Trivial stylistic changes, define inline + members inline, consistently with the rest of the library. + (pow(const _Tp&, const complex<>&)): Minor tweak. + 2008-05-24 Paolo Carlini * src/atomic.cc (atomic_flag_test_and_set_explicit, diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex index e3feef0918f..947ab0ec9ef 100644 --- a/libstdc++-v3/include/std/complex +++ b/libstdc++-v3/include/std/complex @@ -121,29 +121,53 @@ _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 - complex(const complex<_Up>&); + complex(const complex<_Up>& __z) + : _M_real(__z.real()), _M_imag(__z.imag()) { } /// 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; } /// 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,40 +192,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template complex<_Tp>& operator/=(const complex<_Up>&); - const complex& __rep() const; + const complex& __rep() const + { return *this; } private: _Tp _M_real; _Tp _M_imag; }; - template - inline _Tp& - complex<_Tp>::real() { return _M_real; } - - template - inline const _Tp& - complex<_Tp>::real() const { return _M_real; } - - template - inline _Tp& - complex<_Tp>::imag() { return _M_imag; } - - template - inline const _Tp& - complex<_Tp>::imag() const { return _M_imag; } - - template - inline - complex<_Tp>::complex(const _Tp& __r, const _Tp& __i) - : _M_real(__r), _M_imag(__i) { } - - template - template - inline - complex<_Tp>::complex(const complex<_Up>& __z) - : _M_real(__z.real()), _M_imag(__z.imag()) { } - template complex<_Tp>& complex<_Tp>::operator=(const _Tp& __t) @@ -211,24 +209,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return *this; } - // 26.2.5/1 - template - inline complex<_Tp>& - complex<_Tp>::operator+=(const _Tp& __t) - { - _M_real += __t; - return *this; - } - - // 26.2.5/3 - template - inline complex<_Tp>& - complex<_Tp>::operator-=(const _Tp& __t) - { - _M_real -= __t; - return *this; - } - // 26.2.5/5 template complex<_Tp>& @@ -307,10 +287,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _M_real = __r / __n; return *this; } - - template - inline const complex<_Tp>& - complex<_Tp>::__rep() const { return *this; } // Operators: //@{ @@ -995,7 +971,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 +984,115 @@ _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&); - explicit complex(const complex&); - - float& real(); - const float& real() const; - float& imag(); - const float& imag() const; - - complex& operator=(float); - complex& operator+=(float); - complex& operator-=(float); - complex& operator*=(float); - complex& operator/=(float); + explicit complex(const complex&); + + float& real() + { return __real__ _M_value; } + + const float& real() const + { return __real__ _M_value; } + + float& imag() + { return __imag__ _M_value; } + + const float& imag() const + { return __imag__ _M_value; } + + complex& + operator=(float __f) + { + __real__ _M_value = __f; + __imag__ _M_value = 0.0f; + return *this; + } + + complex& + operator+=(float __f) + { + __real__ _M_value += __f; + return *this; + } + + complex& + operator-=(float __f) + { + __real__ _M_value -= __f; + return *this; + } + + complex& + operator*=(float __f) + { + _M_value *= __f; + return *this; + } + + complex& + 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 - complex&operator=(const complex<_Tp>&); + complex& + operator=(const complex<_Tp>& __z) + { + __real__ _M_value = __z.real(); + __imag__ _M_value = __z.imag(); + return *this; + } + template - complex& operator+=(const complex<_Tp>&); + complex& + operator+=(const complex<_Tp>& __z) + { + __real__ _M_value += __z.real(); + __imag__ _M_value += __z.imag(); + return *this; + } + template - complex& operator-=(const complex<_Tp>&); + complex& + operator-=(const complex<_Tp>& __z) + { + __real__ _M_value -= __z.real(); + __imag__ _M_value -= __z.imag(); + return *this; + } + template - complex& operator*=(const complex<_Tp>&); + complex& + operator*=(const complex<_Tp>& __z) + { + _ComplexT __t; + __real__ __t = __z.real(); + __imag__ __t = __z.imag(); + _M_value *= __t; + return *this; + } + template - complex&operator/=(const complex<_Tp>&); + complex& + 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 +1100,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _ComplexT _M_value; }; - inline float& - complex::real() - { return __real__ _M_value; } - - inline const float& - complex::real() const - { return __real__ _M_value; } - - inline float& - complex::imag() - { return __imag__ _M_value; } - - inline const float& - complex::imag() const - { return __imag__ _M_value; } - - inline - complex::complex(float __r, float __i) - { - __real__ _M_value = __r; - __imag__ _M_value = __i; - } - - inline complex& - complex::operator=(float __f) - { - __real__ _M_value = __f; - __imag__ _M_value = 0.0f; - return *this; - } - - inline complex& - complex::operator+=(float __f) - { - __real__ _M_value += __f; - return *this; - } - - inline complex& - complex::operator-=(float __f) - { - __real__ _M_value -= __f; - return *this; - } - - inline complex& - complex::operator*=(float __f) - { - _M_value *= __f; - return *this; - } - - inline complex& - complex::operator/=(float __f) - { - _M_value /= __f; - return *this; - } - - template - inline complex& - complex::operator=(const complex<_Tp>& __z) - { - __real__ _M_value = __z.real(); - __imag__ _M_value = __z.imag(); - return *this; - } - - template - inline complex& - complex::operator+=(const complex<_Tp>& __z) - { - __real__ _M_value += __z.real(); - __imag__ _M_value += __z.imag(); - return *this; - } - - template - inline complex& - complex::operator-=(const complex<_Tp>& __z) - { - __real__ _M_value -= __z.real(); - __imag__ _M_value -= __z.imag(); - return *this; - } - - template - inline complex& - complex::operator*=(const complex<_Tp>& __z) - { - _ComplexT __t; - __real__ __t = __z.real(); - __imag__ __t = __z.imag(); - _M_value *= __t; - return *this; - } - - template - inline complex& - complex::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 specialization template<> @@ -1162,34 +1110,116 @@ _GLIBCXX_BEGIN_NAMESPACE(std) complex(_ComplexT __z) : _M_value(__z) { } - complex(double = 0.0, double = 0.0); - - complex(const complex&); - explicit complex(const complex&); - - double& real(); - const double& real() const; - double& imag(); - const double& imag() const; - - complex& operator=(double); - complex& operator+=(double); - complex& operator-=(double); - complex& operator*=(double); - complex& operator/=(double); + complex(double __r = 0.0, double __i = 0.0) + { + __real__ _M_value = __r; + __imag__ _M_value = __i; + } + + complex(const complex& __z) + : _M_value(__z.__rep()) { } + + explicit complex(const complex&); + + double& real() + { return __real__ _M_value; } + + const double& real() const + { return __real__ _M_value; } + + double& imag() + { return __imag__ _M_value; } + + const double& imag() const + { return __imag__ _M_value; } + + complex& + operator=(double __d) + { + __real__ _M_value = __d; + __imag__ _M_value = 0.0; + return *this; + } + + complex& + operator+=(double __d) + { + __real__ _M_value += __d; + return *this; + } + + complex& + operator-=(double __d) + { + __real__ _M_value -= __d; + return *this; + } + + complex& + operator*=(double __d) + { + _M_value *= __d; + return *this; + } + + complex& + operator/=(double __d) + { + _M_value /= __d; + return *this; + } // The compiler will synthesize this, efficiently. - // complex& operator= (const complex&); + // complex& operator=(const complex&); + template - complex& operator=(const complex<_Tp>&); + complex& + operator=(const complex<_Tp>& __z) + { + __real__ _M_value = __z.real(); + __imag__ _M_value = __z.imag(); + return *this; + } + template - complex& operator+=(const complex<_Tp>&); + complex& + operator+=(const complex<_Tp>& __z) + { + __real__ _M_value += __z.real(); + __imag__ _M_value += __z.imag(); + return *this; + } + template - complex& operator-=(const complex<_Tp>&); + complex& + operator-=(const complex<_Tp>& __z) + { + __real__ _M_value -= __z.real(); + __imag__ _M_value -= __z.imag(); + return *this; + } + template - complex& operator*=(const complex<_Tp>&); + complex& + operator*=(const complex<_Tp>& __z) + { + _ComplexT __t; + __real__ __t = __z.real(); + __imag__ __t = __z.imag(); + _M_value *= __t; + return *this; + } + template - complex& operator/=(const complex<_Tp>&); + complex& + 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 +1227,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _ComplexT _M_value; }; - inline double& - complex::real() - { return __real__ _M_value; } - - inline const double& - complex::real() const - { return __real__ _M_value; } - - inline double& - complex::imag() - { return __imag__ _M_value; } - - inline const double& - complex::imag() const - { return __imag__ _M_value; } - - inline - complex::complex(double __r, double __i) - { - __real__ _M_value = __r; - __imag__ _M_value = __i; - } - - inline complex& - complex::operator=(double __d) - { - __real__ _M_value = __d; - __imag__ _M_value = 0.0; - return *this; - } - - inline complex& - complex::operator+=(double __d) - { - __real__ _M_value += __d; - return *this; - } - - inline complex& - complex::operator-=(double __d) - { - __real__ _M_value -= __d; - return *this; - } - - inline complex& - complex::operator*=(double __d) - { - _M_value *= __d; - return *this; - } - - inline complex& - complex::operator/=(double __d) - { - _M_value /= __d; - return *this; - } - - template - inline complex& - complex::operator=(const complex<_Tp>& __z) - { - __real__ _M_value = __z.real(); - __imag__ _M_value = __z.imag(); - return *this; - } - - template - inline complex& - complex::operator+=(const complex<_Tp>& __z) - { - __real__ _M_value += __z.real(); - __imag__ _M_value += __z.imag(); - return *this; - } - - template - inline complex& - complex::operator-=(const complex<_Tp>& __z) - { - __real__ _M_value -= __z.real(); - __imag__ _M_value -= __z.imag(); - return *this; - } - - template - inline complex& - complex::operator*=(const complex<_Tp>& __z) - { - _ComplexT __t; - __real__ __t = __z.real(); - __imag__ __t = __z.imag(); - _M_value *= __t; - return *this; - } - - template - inline complex& - complex::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 specialization template<> @@ -1315,34 +1237,117 @@ _GLIBCXX_BEGIN_NAMESPACE(std) complex(_ComplexT __z) : _M_value(__z) { } - complex(long double = 0.0L, long double = 0.0L); - - complex(const complex&); - complex(const complex&); - - long double& real(); - const long double& real() const; - long double& imag(); - const long double& imag() const; - - complex& operator= (long double); - complex& operator+= (long double); - complex& operator-= (long double); - complex& operator*= (long double); - complex& operator/= (long double); + complex(long double __r = 0.0L, long double __i = 0.0L) + { + __real__ _M_value = __r; + __imag__ _M_value = __i; + } + + complex(const complex& __z) + : _M_value(__z.__rep()) { } + + complex(const complex& __z) + : _M_value(__z.__rep()) { } + + long double& real() + { return __real__ _M_value; } + + const long double& real() const + { return __real__ _M_value; } + + long double& imag() + { return __imag__ _M_value; } + + const long double& imag() const + { return __imag__ _M_value; } + + complex& + operator=(long double __r) + { + __real__ _M_value = __r; + __imag__ _M_value = 0.0L; + return *this; + } + + complex& + operator+=(long double __r) + { + __real__ _M_value += __r; + return *this; + } + + complex& + operator-=(long double __r) + { + __real__ _M_value -= __r; + return *this; + } + + complex& + operator*=(long double __r) + { + _M_value *= __r; + return *this; + } + + complex& + 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 - complex& operator=(const complex<_Tp>&); + complex& + operator=(const complex<_Tp>& __z) + { + __real__ _M_value = __z.real(); + __imag__ _M_value = __z.imag(); + return *this; + } + template - complex& operator+=(const complex<_Tp>&); + complex& + operator+=(const complex<_Tp>& __z) + { + __real__ _M_value += __z.real(); + __imag__ _M_value += __z.imag(); + return *this; + } + template - complex& operator-=(const complex<_Tp>&); + complex& + operator-=(const complex<_Tp>& __z) + { + __real__ _M_value -= __z.real(); + __imag__ _M_value -= __z.imag(); + return *this; + } + template - complex& operator*=(const complex<_Tp>&); + complex& + operator*=(const complex<_Tp>& __z) + { + _ComplexT __t; + __real__ __t = __z.real(); + __imag__ __t = __z.imag(); + _M_value *= __t; + return *this; + } + template - complex& operator/=(const complex<_Tp>&); + complex& + 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 +1355,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _ComplexT _M_value; }; - inline - complex::complex(long double __r, long double __i) - { - __real__ _M_value = __r; - __imag__ _M_value = __i; - } - - inline long double& - complex::real() - { return __real__ _M_value; } - - inline const long double& - complex::real() const - { return __real__ _M_value; } - - inline long double& - complex::imag() - { return __imag__ _M_value; } - - inline const long double& - complex::imag() const - { return __imag__ _M_value; } - - inline complex& - complex::operator=(long double __r) - { - __real__ _M_value = __r; - __imag__ _M_value = 0.0L; - return *this; - } - - inline complex& - complex::operator+=(long double __r) - { - __real__ _M_value += __r; - return *this; - } - - inline complex& - complex::operator-=(long double __r) - { - __real__ _M_value -= __r; - return *this; - } - - inline complex& - complex::operator*=(long double __r) - { - _M_value *= __r; - return *this; - } - - inline complex& - complex::operator/=(long double __r) - { - _M_value /= __r; - return *this; - } - - template - inline complex& - complex::operator=(const complex<_Tp>& __z) - { - __real__ _M_value = __z.real(); - __imag__ _M_value = __z.imag(); - return *this; - } - - template - inline complex& - complex::operator+=(const complex<_Tp>& __z) - { - __real__ _M_value += __z.real(); - __imag__ _M_value += __z.imag(); - return *this; - } - - template - inline complex& - complex::operator-=(const complex<_Tp>& __z) - { - __real__ _M_value -= __z.real(); - __imag__ _M_value -= __z.imag(); - return *this; - } - - template - inline complex& - complex::operator*=(const complex<_Tp>& __z) - { - _ComplexT __t; - __real__ __t = __z.real(); - __imag__ __t = __z.imag(); - _M_value *= __t; - return *this; - } - - template - inline complex& - complex::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 @@ -1470,22 +1367,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) complex::complex(const complex& __z) : _M_value(__z.__rep()) { } - inline - complex::complex(const complex& __z) - : _M_value(__z.__rep()) { } - inline complex::complex(const complex& __z) : _M_value(__z.__rep()) { } - inline - complex::complex(const complex& __z) - : _M_value(__z.__rep()) { } - - inline - complex::complex(const complex& __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. -- 2.30.2