complex: Trivial stylistic changes...

2008-05-25  Paolo Carlini  <paolo.carlini@oracle.com>

	* 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
This commit is contained in:
Paolo Carlini 2008-05-25 16:55:23 +00:00 committed by Paolo Carlini
parent 3bffa1954c
commit 2acceeac67
2 changed files with 339 additions and 448 deletions

View File

@ -1,3 +1,9 @@
2008-05-25 Paolo Carlini <paolo.carlini@oracle.com>
* 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 <paolo.carlini@oracle.com> 2008-05-24 Paolo Carlini <paolo.carlini@oracle.com>
* src/atomic.cc (atomic_flag_test_and_set_explicit, * src/atomic.cc (atomic_flag_test_and_set_explicit,

View File

@ -121,29 +121,53 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
/// Default constructor. First parameter is x, second parameter is y. /// Default constructor. First parameter is x, second parameter is y.
/// Unspecified parameters default to 0. /// 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 // Lets the compiler synthesize the copy constructor
// complex (const complex<_Tp>&); // complex (const complex<_Tp>&);
/// Copy constructor. /// Copy constructor.
template<typename _Up> template<typename _Up>
complex(const complex<_Up>&); complex(const complex<_Up>& __z)
: _M_real(__z.real()), _M_imag(__z.imag()) { }
/// Return real part of complex number. /// Return real part of complex number.
_Tp& real(); _Tp& real()
{ return _M_real; }
/// Return real part of complex number. /// Return real part of complex number.
const _Tp& real() const; const _Tp& real() const
{ return _M_real; }
/// Return imaginary part of complex number. /// Return imaginary part of complex number.
_Tp& imag(); _Tp& imag()
{ return _M_imag; }
/// Return imaginary part of complex number. /// 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. /// Assign this complex number to scalar @a t.
complex<_Tp>& operator=(const _Tp&); complex<_Tp>& operator=(const _Tp&);
/// Add @a t to this complex number. /// 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. /// 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. /// Multiply this complex number by @a t.
complex<_Tp>& operator*=(const _Tp&); complex<_Tp>& operator*=(const _Tp&);
/// Divide this complex number by @a t. /// Divide this complex number by @a t.
@ -168,40 +192,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Up> template<typename _Up>
complex<_Tp>& operator/=(const complex<_Up>&); complex<_Tp>& operator/=(const complex<_Up>&);
const complex& __rep() const; const complex& __rep() const
{ return *this; }
private: private:
_Tp _M_real; _Tp _M_real;
_Tp _M_imag; _Tp _M_imag;
}; };
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> template<typename _Tp>
complex<_Tp>& complex<_Tp>&
complex<_Tp>::operator=(const _Tp& __t) complex<_Tp>::operator=(const _Tp& __t)
@ -211,24 +209,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
return *this; 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 // 26.2.5/5
template<typename _Tp> template<typename _Tp>
complex<_Tp>& complex<_Tp>&
@ -307,10 +287,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_M_real = __r / __n; _M_real = __r / __n;
return *this; return *this;
} }
template<typename _Tp>
inline const complex<_Tp>&
complex<_Tp>::__rep() const { return *this; }
// Operators: // Operators:
//@{ //@{
@ -995,7 +971,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ {
return __x > _Tp() ? std::polar(pow(__x, __y.real()), return __x > _Tp() ? std::polar(pow(__x, __y.real()),
__y.imag() * log(__x)) __y.imag() * log(__x))
: std::pow(complex<_Tp>(__x, _Tp()), __y); : std::pow(complex<_Tp>(__x), __y);
} }
// 26.2.3 complex specializations // 26.2.3 complex specializations
@ -1008,35 +984,115 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
complex(_ComplexT __z) : _M_value(__z) { } 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<double>&);
explicit complex(const complex<long double>&); explicit complex(const complex<long double>&);
float& real(); float& real()
const float& real() const; { return __real__ _M_value; }
float& imag();
const float& imag() const;
complex<float>& operator=(float); const float& real() const
complex<float>& operator+=(float); { return __real__ _M_value; }
complex<float>& operator-=(float);
complex<float>& operator*=(float); float& imag()
complex<float>& operator/=(float); { return __imag__ _M_value; }
const float& imag() const
{ return __imag__ _M_value; }
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 // Let the compiler synthesize the copy and assignment
// operator. It always does a pretty good job. // operator. It always does a pretty good job.
// complex& operator= (const complex&); // complex& operator=(const complex&);
template<typename _Tp> 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> 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> 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> 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> 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; } const _ComplexT& __rep() const { return _M_value; }
@ -1044,114 +1100,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_ComplexT _M_value; _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 // 26.2.3 complex specializations
// complex<double> specialization // complex<double> specialization
template<> template<>
@ -1162,34 +1110,116 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
complex(_ComplexT __z) : _M_value(__z) { } 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>&); complex(const complex<float>& __z)
explicit complex(const complex<long double>&); : _M_value(__z.__rep()) { }
double& real(); explicit complex(const complex<long double>&);
const double& real() const;
double& imag();
const double& imag() const;
complex<double>& operator=(double); double& real()
complex<double>& operator+=(double); { return __real__ _M_value; }
complex<double>& operator-=(double);
complex<double>& operator*=(double); const double& real() const
complex<double>& operator/=(double); { return __real__ _M_value; }
double& imag()
{ return __imag__ _M_value; }
const double& imag() const
{ return __imag__ _M_value; }
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. // The compiler will synthesize this, efficiently.
// complex& operator= (const complex&); // complex& operator=(const complex&);
template<typename _Tp> 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> 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> 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> 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> 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; } const _ComplexT& __rep() const { return _M_value; }
@ -1197,114 +1227,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_ComplexT _M_value; _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 // 26.2.3 complex specializations
// complex<long double> specialization // complex<long double> specialization
template<> template<>
@ -1315,34 +1237,117 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
complex(_ComplexT __z) : _M_value(__z) { } 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>&); complex(const complex<float>& __z)
complex(const complex<double>&); : _M_value(__z.__rep()) { }
long double& real(); complex(const complex<double>& __z)
const long double& real() const; : _M_value(__z.__rep()) { }
long double& imag();
const long double& imag() const;
complex<long double>& operator= (long double); long double& real()
complex<long double>& operator+= (long double); { return __real__ _M_value; }
complex<long double>& operator-= (long double);
complex<long double>& operator*= (long double); const long double& real() const
complex<long double>& operator/= (long double); { return __real__ _M_value; }
long double& imag()
{ return __imag__ _M_value; }
const long double& imag() const
{ return __imag__ _M_value; }
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 // The compiler knows how to do this efficiently
// complex& operator= (const complex&); // complex& operator=(const complex&);
template<typename _Tp> 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> 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> 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> 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> 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; } const _ComplexT& __rep() const { return _M_value; }
@ -1350,114 +1355,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_ComplexT _M_value; _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 // These bits have to be at the end of this file, so that the
// specializations have all been defined. // specializations have all been defined.
// ??? No, they have to be there because of compiler limitation at // ??? No, they have to be there because of compiler limitation at
@ -1470,22 +1367,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
complex<float>::complex(const complex<long double>& __z) complex<float>::complex(const complex<long double>& __z)
: _M_value(__z.__rep()) { } : _M_value(__z.__rep()) { }
inline
complex<double>::complex(const complex<float>& __z)
: _M_value(__z.__rep()) { }
inline inline
complex<double>::complex(const complex<long double>& __z) complex<double>::complex(const complex<long double>& __z)
: _M_value(__z.__rep()) { } : _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, // Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere. // which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension. // NB: This syntax is a GNU extension.