Commit 5e90dd71 by Benjamin Kosnik Committed by Benjamin Kosnik

std_complex.h: Tweaks, include cmath for abs overloads.


2000-11-20  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/std_complex.h: Tweaks, include cmath for abs overloads.
	* src/complex.cc: Remove cmath include, formatting tweaks, remove
	dead code.
	* include/c/bits/std_cmath.h: Formatting tweaks.
	* testsuite/26_numerics/complex_value.cc: New file, for catching
	bits gleaned from libstdc++/106.

	* testsuite/23_containers/vector_ctor.cc (test02): Add test from
	libstdc++/102.

From-SVN: r37591
parent 250333d0
2000-11-20 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/std_complex.h: Tweaks, include cmath for abs overloads.
* src/complex.cc: Remove cmath include, formatting tweaks, remove
dead code.
* include/c/bits/std_cmath.h: Formatting tweaks.
* testsuite/26_numerics/complex_value.cc: New file, for catching
bits gleaned from libstdc++/106.
* testsuite/23_containers/vector_ctor.cc (test02): Add test from
libstdc++/102.
* src/string-inst.cc: Tweaks.
2000-11-20 Joseph S. Myers <jsm28@cam.ac.uk> 2000-11-20 Joseph S. Myers <jsm28@cam.ac.uk>
* include/bits/c++config, include/bits/ios_base.h, * include/bits/c++config, include/bits/ios_base.h,
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
// the GNU General Public License. // the GNU General Public License.
// //
// ISO 14882/26.2.1 // ISO C++ 14882: 26.2 Complex Numbers
// Note: this is not a conforming implementation. // Note: this is not a conforming implementation.
// Initially implemented by Ulrich Drepper <drepper@cygnus.com> // Initially implemented by Ulrich Drepper <drepper@cygnus.com>
// Improved by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr> // Improved by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#define _CPP_COMPLEX 1 #define _CPP_COMPLEX 1
#include <bits/c++config.h> #include <bits/c++config.h>
#include <bits/std_cmath.h>
#include <bits/std_iosfwd.h> #include <bits/std_iosfwd.h>
namespace std namespace std
...@@ -64,7 +65,7 @@ namespace std ...@@ -64,7 +65,7 @@ namespace std
template<typename _Tp> complex<_Tp> log10(const complex<_Tp>&); template<typename _Tp> complex<_Tp> log10(const complex<_Tp>&);
template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, int); template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, int);
template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, const _Tp&); template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, const _Tp&);
template<typename _Tp> complex<_Tp> pow (const complex<_Tp>&, template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&,
const complex<_Tp>&); const complex<_Tp>&);
template<typename _Tp> complex<_Tp> pow(const _Tp&, const complex<_Tp>&); template<typename _Tp> complex<_Tp> pow(const _Tp&, const complex<_Tp>&);
template<typename _Tp> complex<_Tp> sin(const complex<_Tp>&); template<typename _Tp> complex<_Tp> sin(const complex<_Tp>&);
...@@ -74,10 +75,8 @@ namespace std ...@@ -74,10 +75,8 @@ namespace std
template<typename _Tp> complex<_Tp> tanh(const complex<_Tp>&); template<typename _Tp> complex<_Tp> tanh(const complex<_Tp>&);
//
// 26.2.2 Primary template class complex // 26.2.2 Primary template class complex
// template<typename _Tp>
template <typename _Tp>
class complex class complex
{ {
public: public:
...@@ -87,7 +86,7 @@ namespace std ...@@ -87,7 +86,7 @@ namespace std
// Let's the compiler synthetize the copy constructor // Let's the compiler synthetize the copy constructor
// complex (const complex<_Tp>&); // complex (const complex<_Tp>&);
template <typename _Up> template<typename _Up>
complex(const complex<_Up>&); complex(const complex<_Up>&);
_Tp real() const; _Tp real() const;
...@@ -102,15 +101,15 @@ namespace std ...@@ -102,15 +101,15 @@ namespace std
// Let's the compiler synthetize the // Let's the compiler synthetize the
// copy and assignment operator // copy and assignment operator
// complex<_Tp>& operator= (const complex<_Tp>&); // complex<_Tp>& operator= (const complex<_Tp>&);
template <typename _Up> template<typename _Up>
complex<_Tp>& operator=(const complex<_Up>&); complex<_Tp>& operator=(const complex<_Up>&);
template <typename _Up> template<typename _Up>
complex<_Tp>& operator+=(const complex<_Up>&); complex<_Tp>& operator+=(const complex<_Up>&);
template <typename _Up> template<typename _Up>
complex<_Tp>& operator-=(const complex<_Up>&); complex<_Tp>& operator-=(const complex<_Up>&);
template <typename _Up> template<typename _Up>
complex<_Tp>& operator*=(const complex<_Up>&); complex<_Tp>& operator*=(const complex<_Up>&);
template <typename _Up> template<typename _Up>
complex<_Tp>& operator/=(const complex<_Up>&); complex<_Tp>& operator/=(const complex<_Up>&);
private: private:
...@@ -125,868 +124,833 @@ namespace std ...@@ -125,868 +124,833 @@ namespace std
inline _Tp inline _Tp
complex<_Tp>::imag() const { return _M_imag; } complex<_Tp>::imag() const { return _M_imag; }
//
// 26.2.3 complex specializations
//
//
// complex<float> specialization
//
template<> class complex<float>
{
public:
typedef float value_type;
complex(float = 0.0f, float = 0.0f);
#ifdef _GLIBCPP_BUGGY_COMPLEX
complex(const complex& __z) : _M_value(__z._M_value) { }
#endif
explicit complex(const complex<double>&);
explicit complex(const complex<long double>&);
float real() const;
float imag() const;
complex<float>& operator=(float);
complex<float>& operator+=(float);
complex<float>& operator-=(float);
complex<float>& operator*=(float);
complex<float>& operator/=(float);
// Let's the compiler synthetize the copy and assignment
// operator. It always does a pretty good job.
// complex& operator= (const complex&);
template <typename _Tp>
complex<float>&operator=(const complex<_Tp>&);
template <typename _Tp>
complex<float>& operator+=(const complex<_Tp>&);
template <class _Tp>
complex<float>& operator-=(const complex<_Tp>&);
template <class _Tp>
complex<float>& operator*=(const complex<_Tp>&);
template <class _Tp>
complex<float>&operator/=(const complex<_Tp>&);
private:
typedef __complex__ float _ComplexT;
_ComplexT _M_value;
complex(_ComplexT __z) : _M_value(__z) { }
friend class complex<double>;
friend class complex<long double>;
friend complex<float> pow<>(const complex<float>&, int);
friend complex<float> pow<>(const complex<float>&, const float&);
friend complex<float> pow<>(const complex<float>&,
const complex<float>&);
friend complex<float> pow<>(const float&, const complex<float>&);
friend complex<float> sqrt<>(const complex<float>&);
friend complex<float> tan<>(const complex<float>&);
friend complex<float> tanh<>(const complex<float>&);
};
inline float
complex<float>::real() const
{ return __real__ _M_value; }
inline float
complex<float>::imag() const
{ return __imag__ _M_value; }
//
// complex<double> specialization
//
template<> class complex<double>
{
public:
typedef double value_type;
complex(double =0.0, double =0.0);
#ifdef _GLIBCPP_BUGGY_COMPLEX
complex(const complex& __z) : _M_value(__z._M_value) { }
#endif
complex(const complex<float>&);
explicit complex(const complex<long double>&);
double real() const;
double imag() const;
complex<double>& operator=(double);
complex<double>& operator+=(double);
complex<double>& operator-=(double);
complex<double>& operator*=(double);
complex<double>& operator/=(double);
// The compiler will synthetize this, efficiently.
// complex& operator= (const complex&);
template <typename _Tp>
complex<double>& operator=(const complex<_Tp>&);
template <typename _Tp>
complex<double>& operator+=(const complex<_Tp>&);
template <typename _Tp>
complex<double>& operator-=(const complex<_Tp>&);
template <typename _Tp>
complex<double>& operator*=(const complex<_Tp>&);
template <typename _Tp>
complex<double>& operator/=(const complex<_Tp>&);
private:
typedef __complex__ double _ComplexT;
_ComplexT _M_value;
complex(_ComplexT __z) : _M_value(__z) { }
friend class complex<float>;
friend class complex<long double>;
friend complex<double> pow<>(const complex<double>&, int);
friend complex<double> pow<>(const complex<double>&, const double&);
friend complex<double> pow<>(const complex<double>&,
const complex<double>&);
friend complex<double> pow<>(const double&, const complex<double>&);
friend complex<double> sqrt<>(const complex<double>&);
friend complex<double> tan<>(const complex<double>&);
friend complex<double> tanh<>(const complex<double>&);
};
inline double
complex<double>::real() const
{ return __real__ _M_value; }
inline double
complex<double>::imag() const
{ return __imag__ _M_value; }
//
// complex<long double> specialization
//
template<> class complex<long double>
{
public:
typedef long double value_type;
complex(long double = 0.0L, long double = 0.0L);
#ifdef _GLIBCPP_BUGGY_COMPLEX
complex(const complex& __z) : _M_value(__z._M_value) { }
#endif
complex(const complex<float>&);
complex(const complex<double>&);
long double real() const;
long double imag() const;
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);
// The compiler knows how to do this efficiently
// complex& operator= (const complex&);
template<typename _Tp>
complex<long double>& operator=(const complex<_Tp>&);
template<typename _Tp>
complex<long double>& operator+=(const complex<_Tp>&);
template<typename _Tp>
complex<long double>& operator-=(const complex<_Tp>&);
template<typename _Tp>
complex<long double>& operator*=(const complex<_Tp>&);
template<typename _Tp> template<typename _Tp>
complex<long double>& operator/=(const complex<_Tp>&);
private:
typedef __complex__ long double _ComplexT;
_ComplexT _M_value;
complex(_ComplexT __z) : _M_value(__z) { }
friend class complex<float>;
friend class complex<double>;
friend complex<long double> pow<>(const complex<long double>&, int);
friend complex<long double> pow<>(const complex<long double>&,
const long double&);
friend complex<long double> pow<>(const complex<long double>&,
const complex<long double>&);
friend complex<long double> pow<>(const long double&,
const complex<long double>&);
friend complex<long double> sqrt<>(const complex<long double>&);
friend complex<long double> tan<>(const complex<long double>&);
friend complex<long double> tanh<>(const complex<long double>&);
};
inline
complex<long double>::complex(long double __r, long double __i)
{
__real__ _M_value = __r;
__imag__ _M_value = __i;
}
inline inline
complex<long double>::complex(const complex<float>& __z) complex<_Tp>::complex(const _Tp& __r, const _Tp& __i)
: _M_value(_ComplexT(__z._M_value)) { } : _M_real(__r), _M_imag(__i) { }
template<typename _Tp>
template<typename _Up>
inline inline
complex<long double>::complex(const complex<double>& __z) complex<_Tp>::complex(const complex<_Up>& __z)
: _M_value(_ComplexT(__z._M_value)) { } : _M_real(__z.real()), _M_imag(__z.imag()) { }
inline long double
complex<long double>::real() const
{ return __real__ _M_value; }
inline 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>& template<typename _Tp>
complex<long double>::operator+=(long double __r) complex<_Tp>&
complex<_Tp>::operator=(const _Tp& __t)
{ {
__real__ _M_value += __r; _M_real = __t;
_M_imag = _Tp();
return *this; return *this;
} }
inline complex<long double>& // 26.2.5/1
complex<long double>::operator-=(long double __r) template<typename _Tp>
inline complex<_Tp>&
complex<_Tp>::operator+=(const _Tp& __t)
{ {
__real__ _M_value -= __r; _M_real += __t;
return *this; return *this;
} }
inline complex<long double>& // 26.2.5/3
complex<long double>::operator*=(long double __r) template<typename _Tp>
inline complex<_Tp>&
complex<_Tp>::operator-=(const _Tp& __t)
{ {
__real__ _M_value *= __r; _M_real -= __t;
return *this; return *this;
} }
inline complex<long double>& // 26.2.5/5
complex<long double>::operator/=(long double __r) template<typename _Tp>
complex<_Tp>&
complex<_Tp>::operator*=(const _Tp& __t)
{ {
__real__ _M_value /= __r; _M_real *= __t;
_M_imag *= __t;
return *this; return *this;
} }
// 26.2.5/7
template<typename _Tp> template<typename _Tp>
inline complex<long double>& complex<_Tp>&
complex<long double>::operator=(const complex<_Tp>& __z) complex<_Tp>::operator/=(const _Tp& __t)
{ {
__real__ _M_value = __z.real(); _M_real /= __t;
__imag__ _M_value = __z.imag(); _M_imag /= __t;
return *this; return *this;
} }
template<typename _Tp> template<typename _Tp>
inline complex<long double>& template<typename _Up>
complex<long double>::operator+=(const complex<_Tp>& __z) complex<_Tp>&
complex<_Tp>::operator=(const complex<_Up>& __z)
{ {
__real__ _M_value += __z.real(); _M_real = __z.real();
__imag__ _M_value += __z.imag(); _M_imag = __z.imag();
return *this; return *this;
} }
// 26.2.5/9
template<typename _Tp> template<typename _Tp>
inline complex<long double>& template<typename _Up>
complex<long double>::operator-=(const complex<_Tp>& __z) complex<_Tp>&
complex<_Tp>::operator+=(const complex<_Up>& __z)
{ {
__real__ _M_value -= __z.real(); _M_real += __z.real();
__imag__ _M_value -= __z.imag(); _M_imag += __z.imag();
return *this; return *this;
} }
// 26.2.5/11
template<typename _Tp> template<typename _Tp>
inline complex<long double>& template<typename _Up>
complex<long double>::operator*=(const complex<_Tp>& __z) complex<_Tp>&
complex<_Tp>::operator-=(const complex<_Up>& __z)
{ {
_ComplexT __t; _M_real -= __z.real();
__real__ __t = __z.real(); _M_imag -= __z.imag();
__imag__ __t = __z.imag();
_M_value *= __t;
return *this; return *this;
} }
// 26.2.5/13
// XXX: This is a grammar school implementation.
template<typename _Tp> template<typename _Tp>
inline complex<long double>& template<typename _Up>
complex<long double>::operator/=(const complex<_Tp>& __z) complex<_Tp>&
{ complex<_Tp>::operator*=(const complex<_Up>& __z)
_ComplexT __t;
__real__ __t = __z.real();
__imag__ __t = __z.imag();
_M_value /= __t;
return *this;
}
//
// complex<float> continued.
//
inline
complex<float>::complex(float r, float i)
{
__real__ _M_value = r;
__imag__ _M_value = i;
}
inline
complex<float>::complex(const complex<double>& __z)
: _M_value(_ComplexT(__z._M_value)) { }
inline
complex<float>::complex(const complex<long double>& __z)
: _M_value(_ComplexT(__z._M_value)) { }
inline complex<float>&
complex<float>::operator=(float __f)
{ {
__real__ _M_value = __f; const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
__imag__ _M_value = 0.0f; _M_imag = _M_real * __z.imag() + _M_imag * __z.real();
_M_real = __r;
return *this; return *this;
} }
inline complex<float>& // 26.2.5/15
complex<float>::operator+=(float __f) // XXX: This is a grammar school implementation.
template<typename _Tp>
template<typename _Up>
complex<_Tp>&
complex<_Tp>::operator/=(const complex<_Up>& __z)
{ {
__real__ _M_value += __f; const _Tp __r = _M_real * __z.real() + _M_imag * __z.imag();
const _Tp __n = norm(__z);
_M_imag = (_M_real * __z.imag() - _M_imag * __z.real()) / __n;
_M_real = __r / __n;
return *this; return *this;
} }
inline complex<float>& // Operators:
complex<float>::operator-=(float __f) template<typename _Tp>
{ inline complex<_Tp>
__real__ _M_value -= __f; operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
return *this; { return complex<_Tp> (__x) += __y; }
}
inline complex<float>& template<typename _Tp>
complex<float>::operator*=(float __f) inline complex<_Tp>
{ operator+(const complex<_Tp>& __x, const _Tp& __y)
_M_value *= __f; { return complex<_Tp> (__x) += __y; }
return *this;
}
inline complex<float>& template<typename _Tp>
complex<float>::operator/=(float __f) inline complex<_Tp>
{ operator+(const _Tp& __x, const complex<_Tp>& __y)
_M_value /= __f; { return complex<_Tp> (__y) += __x; }
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<float>& inline complex<_Tp>
complex<float>::operator=(const complex<_Tp>& __z) operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
{ { return complex<_Tp> (__x) -= __y; }
__real__ _M_value = __z.real();
__imag__ _M_value = __z.imag();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<float>& inline complex<_Tp>
complex<float>::operator+=(const complex<_Tp>& __z) operator-(const complex<_Tp>& __x, const _Tp& __y)
{ { return complex<_Tp> (__x) -= __y; }
__real__ _M_value += __z.real();
__imag__ _M_value += __z.imag();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<float>& inline complex<_Tp>
complex<float>::operator-=(const complex<_Tp>& __z) operator-(const _Tp& __x, const complex<_Tp>& __y)
{ { return complex<_Tp> (__x) -= __y; }
__real__ _M_value -= __z.real();
__imag__ _M_value -= __z.real();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<float>& inline complex<_Tp>
complex<float>::operator*=(const complex<_Tp>& __z) operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
{ { return complex<_Tp> (__x) *= __y; }
_ComplexT __t;
__real__ __t = __z.real();
__imag__ __t = __z.imag();
_M_value *= __t;
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<float>& inline complex<_Tp>
complex<float>::operator/=(const complex<_Tp>& __z) operator*(const complex<_Tp>& __x, const _Tp& __y)
{ { return complex<_Tp> (__x) *= __y; }
_ComplexT __t;
__real__ __t = __z.real();
__imag__ __t = __z.imag();
_M_value /= __t;
return *this;
}
template<typename _Tp>
inline complex<_Tp>
operator*(const _Tp& __x, const complex<_Tp>& __y)
{ return complex<_Tp> (__y) *= __x; }
// template<typename _Tp>
// complex<double> continued. inline complex<_Tp>
// operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
inline { return complex<_Tp> (__x) /= __y; }
complex<double>::complex(double __r, double __i)
{
__real__ _M_value = __r;
__imag__ _M_value = __i;
}
inline template<typename _Tp>
complex<double>::complex(const complex<float>& __z) inline complex<_Tp>
: _M_value(_ComplexT(__z._M_value)) { } operator/(const complex<_Tp>& __x, const _Tp& __y)
{ return complex<_Tp> (__x) /= __y; }
inline template<typename _Tp>
complex<double>::complex(const complex<long double>& __z) inline complex<_Tp>
{ operator/(const _Tp& __x, const complex<_Tp>& __y)
__real__ _M_value = __z.real(); { return complex<_Tp> (__x) /= __y; }
__imag__ _M_value = __z.imag();
}
inline complex<double>& template<typename _Tp>
complex<double>::operator=(double __d) inline complex<_Tp>
{ operator+(const complex<_Tp>& __x)
__real__ _M_value = __d; { return __x; }
__imag__ _M_value = 0.0;
return *this;
}
inline complex<double>& template<typename _Tp>
complex<double>::operator+=(double __d) inline complex<_Tp>
{ operator-(const complex<_Tp>& __x)
__real__ _M_value += __d; { return complex<_Tp>(-__x.real(), -__x.imag()); }
return *this;
}
inline complex<double>& template<typename _Tp>
complex<double>::operator-=(double __d) inline bool
{ operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
__real__ _M_value -= __d; { return __x.real() == __y.real() && __x.imag() == __y.imag(); }
return *this;
}
inline complex<double>& template<typename _Tp>
complex<double>::operator*=(double __d) inline bool
{ operator==(const complex<_Tp>& __x, const _Tp& __y)
_M_value *= __d; { return __x.real() == __y && __x.imag() == _Tp(); }
return *this;
}
inline complex<double>& template<typename _Tp>
complex<double>::operator/=(double __d) inline bool
{ operator==(const _Tp& __x, const complex<_Tp>& __y)
_M_value /= __d; { return __x == __y.real() && _Tp() == __y.imag(); }
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<double>& inline bool
complex<double>::operator=(const complex<_Tp>& __z) operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
{ { return __x.real() != __y.real() || __x.imag() != __y.imag(); }
__real__ _M_value = __z.real();
__imag__ _M_value = __z.imag();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<double>& inline bool
complex<double>::operator+=(const complex<_Tp>& __z) operator!=(const complex<_Tp>& __x, const _Tp& __y)
{ return __x.real() != __y || __x.imag() != _Tp(); }
template<typename _Tp>
inline bool
operator!=(const _Tp& __x, const complex<_Tp>& __y)
{ return __x != __y.real() || _Tp() != __y.imag(); }
template<typename _Tp, typename _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>&, complex<_Tp>&);
template<typename _Tp, typename _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>&, const complex<_Tp>&);
// Values
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(); }
template<typename _Tp>
inline _Tp
abs(const complex<_Tp>& __z)
{ {
__real__ _M_value += __z.real(); _Tp __x = __z.real();
__imag__ _M_value += __z.imag(); _Tp __y = __z.imag();
return *this; const _Tp __s = abs(__x) + abs(__y);
if (__s == _Tp()) // well ...
return __s;
__x /= __s;
__y /= __s;
return __s * sqrt(__x * __x + __y * __y);
} }
template<typename _Tp> template<typename _Tp>
inline complex<double>& inline _Tp
complex<double>::operator-=(const complex<_Tp>& __z) arg(const complex<_Tp>& __z)
{ return atan2(__z.imag(), __z.real()); }
template<typename _Tp>
inline _Tp
norm(const complex<_Tp>& __z)
{ {
__real__ _M_value -= __z.real(); _Tp __res = abs(__z);
__imag__ _M_value -= __z.imag(); return __res * __res;
return *this;
} }
template<typename _Tp> template<typename _Tp>
inline complex<double>& inline complex<_Tp>
complex<double>::operator*=(const complex<_Tp>& __z) polar(const _Tp& __rho, const _Tp& __theta)
{ return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); }
template<typename _Tp>
inline complex<_Tp>
conj(const complex<_Tp>& __z)
{ return complex<_Tp>(__z.real(), -__z.imag()); }
// Transcendentals
template<typename _Tp>
inline complex<_Tp>
cos(const complex<_Tp>& __z)
{ {
_ComplexT __t; const _Tp __x = __z.real();
__real__ __t = __z.real(); const _Tp __y = __z.imag();
__imag__ __t = __z.imag(); return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y));
_M_value *= __t;
return *this;
} }
template<typename _Tp> template<typename _Tp>
inline complex<double>& inline complex<_Tp>
complex<double>::operator/=(const complex<_Tp>& __z) cosh(const complex<_Tp>& __z)
{ {
_ComplexT __t; const _Tp __x = __z.real();
__real__ __t = __z.real(); const _Tp __y = __z.imag();
__imag__ __t = __z.imag(); return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y));
_M_value /= __t;
return *this;
} }
//
// Primary template class complex continued.
//
// 26.2.4
template<typename _Tp> template<typename _Tp>
inline inline complex<_Tp>
complex<_Tp>::complex(const _Tp& __r, const _Tp& __i) exp(const complex<_Tp>& __z)
: _M_real(__r), _M_imag(__i) { } { return polar(exp(__z.real()), __z.imag()); }
template<typename _Tp> template<typename _Tp>
template<typename _Up> inline complex<_Tp>
inline log(const complex<_Tp>& __z)
complex<_Tp>::complex(const complex<_Up>& __z) { return complex<_Tp>(log(abs(__z)), arg(__z)); }
: _M_real(__z.real()), _M_imag(__z.imag()) { }
// 26.2.7/4
template<typename _Tp> template<typename _Tp>
inline _Tp inline complex<_Tp>
norm(const complex<_Tp>& __z) log10(const complex<_Tp>& __z)
{ { return log(__z) / log(_Tp(10.0)); }
// XXX: Grammar school computation
return __z.real() * __z.real() + __z.imag() * __z.imag();
}
template<typename _Tp> template<typename _Tp>
complex<_Tp>& inline complex<_Tp>
complex<_Tp>::operator=(const _Tp& __t) sin(const complex<_Tp>& __z)
{ {
_M_real = __t; const _Tp __x = __z.real();
_M_imag = _Tp(); const _Tp __y = __z.imag();
return *this; return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y));
} }
// 26.2.5/1
template<typename _Tp> template<typename _Tp>
inline complex<_Tp>& inline complex<_Tp>
complex<_Tp>::operator+=(const _Tp& __t) sinh(const complex<_Tp>& __z)
{ {
_M_real += __t; const _Tp __x = __z.real();
return *this; const _Tp __y = __z.imag();
return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y));
} }
// 26.2.5/3 // 26.2.3 complex specializations
// complex<float> specialization
template<> class complex<float>
{
public:
typedef float value_type;
complex(float = 0.0f, float = 0.0f);
#ifdef _GLIBCPP_BUGGY_COMPLEX
complex(const complex& __z) : _M_value(__z._M_value) { }
#endif
explicit complex(const complex<double>&);
explicit complex(const complex<long double>&);
float real() const;
float imag() const;
complex<float>& operator=(float);
complex<float>& operator+=(float);
complex<float>& operator-=(float);
complex<float>& operator*=(float);
complex<float>& operator/=(float);
// Let's the compiler synthetize the copy and assignment
// operator. It always does a pretty good job.
// complex& operator= (const complex&);
template<typename _Tp> template<typename _Tp>
inline complex<_Tp>& complex<float>&operator=(const complex<_Tp>&);
complex<_Tp>::operator-=(const _Tp& __t) template<typename _Tp>
complex<float>& operator+=(const complex<_Tp>&);
template<class _Tp>
complex<float>& operator-=(const complex<_Tp>&);
template<class _Tp>
complex<float>& operator*=(const complex<_Tp>&);
template<class _Tp>
complex<float>&operator/=(const complex<_Tp>&);
private:
typedef __complex__ float _ComplexT;
_ComplexT _M_value;
complex(_ComplexT __z) : _M_value(__z) { }
friend class complex<double>;
friend class complex<long double>;
friend complex<float> pow<>(const complex<float>&, int);
friend complex<float> pow<>(const complex<float>&, const float&);
friend complex<float> pow<>(const complex<float>&,
const complex<float>&);
friend complex<float> pow<>(const float&, const complex<float>&);
friend complex<float> sqrt<>(const complex<float>&);
friend complex<float> tan<>(const complex<float>&);
friend complex<float> tanh<>(const complex<float>&);
};
inline float
complex<float>::real() const
{ return __real__ _M_value; }
inline float
complex<float>::imag() const
{ return __imag__ _M_value; }
inline
complex<float>::complex(float r, float i)
{ {
_M_real -= __t; __real__ _M_value = r;
return *this; __imag__ _M_value = i;
} }
// 26.2.5/5 inline complex<float>&
template<typename _Tp> complex<float>::operator=(float __f)
complex<_Tp>&
complex<_Tp>::operator*=(const _Tp& __t)
{ {
_M_real *= __t; __real__ _M_value = __f;
_M_imag *= __t; __imag__ _M_value = 0.0f;
return *this; return *this;
} }
// 26.2.5/7 inline complex<float>&
template<typename _Tp> complex<float>::operator+=(float __f)
complex<_Tp>&
complex<_Tp>::operator/=(const _Tp& __t)
{ {
_M_real /= __t; __real__ _M_value += __f;
_M_imag /= __t;
return *this; return *this;
} }
template<typename _Tp> inline complex<float>&
template<typename _Up> complex<float>::operator-=(float __f)
complex<_Tp>&
complex<_Tp>::operator=(const complex<_Up>& __z)
{ {
_M_real = __z.real(); __real__ _M_value -= __f;
_M_imag = __z.imag();
return *this; return *this;
} }
// 26.2.5/9 inline complex<float>&
template<typename _Tp> complex<float>::operator*=(float __f)
template<typename _Up>
complex<_Tp>&
complex<_Tp>::operator+=(const complex<_Up>& __z)
{ {
_M_real += __z.real(); _M_value *= __f;
_M_imag += __z.imag();
return *this; return *this;
} }
// 26.2.5/11 inline complex<float>&
template<typename _Tp> complex<float>::operator/=(float __f)
template<typename _Up>
complex<_Tp>&
complex<_Tp>::operator-=(const complex<_Up>& __z)
{ {
_M_real -= __z.real(); _M_value /= __f;
_M_imag -= __z.imag();
return *this; return *this;
} }
// 26.2.5/13
// XXX: this is a grammar school implementation.
template<typename _Tp> template<typename _Tp>
template<typename _Up> inline complex<float>&
complex<_Tp>& complex<float>::operator=(const complex<_Tp>& __z)
complex<_Tp>::operator*=(const complex<_Up>& __z)
{ {
const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag(); __real__ _M_value = __z.real();
_M_imag = _M_real * __z.imag() + _M_imag * __z.real(); __imag__ _M_value = __z.imag();
_M_real = __r;
return *this; return *this;
} }
// 26.2.5/15
// XXX: this is a grammar school implementation.
template<typename _Tp> template<typename _Tp>
template<typename _Up> inline complex<float>&
complex<_Tp>& complex<float>::operator+=(const complex<_Tp>& __z)
complex<_Tp>::operator/=(const complex<_Up>& __z)
{ {
const _Tp __r = _M_real * __z.real() + _M_imag * __z.imag(); __real__ _M_value += __z.real();
const _Tp __n = norm(__z); __imag__ _M_value += __z.imag();
_M_imag = (_M_real * __z.imag() - _M_imag * __z.real()) / __n;
_M_real = __r / __n;
return *this; return *this;
} }
// Operators:
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<float>&
operator+(const complex<_Tp>& __x, const complex<_Tp>& __y) complex<float>::operator-=(const complex<_Tp>& __z)
{ return complex<_Tp> (__x) += __y; } {
__real__ _M_value -= __z.real();
__imag__ _M_value -= __z.real();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<float>&
operator+(const complex<_Tp>& __x, const _Tp& __y) complex<float>::operator*=(const complex<_Tp>& __z)
{ return complex<_Tp> (__x) += __y; } {
_ComplexT __t;
__real__ __t = __z.real();
__imag__ __t = __z.imag();
_M_value *= __t;
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<float>&
operator+(const _Tp& __x, const complex<_Tp>& __y) complex<float>::operator/=(const complex<_Tp>& __z)
{ return complex<_Tp> (__y) += __x; } {
_ComplexT __t;
__real__ __t = __z.real();
__imag__ __t = __z.imag();
_M_value /= __t;
return *this;
}
template<typename _Tp> // 26.2.3 complex specializations
inline complex<_Tp> // complex<double> specialization
operator-(const complex<_Tp>& __x, const complex<_Tp>& __y) template<> class complex<double>
{ return complex<_Tp> (__x) -= __y; } {
public:
typedef double value_type;
template<typename _Tp> complex(double =0.0, double =0.0);
inline complex<_Tp> #ifdef _GLIBCPP_BUGGY_COMPLEX
operator-(const complex<_Tp>& __x, const _Tp& __y) complex(const complex& __z) : _M_value(__z._M_value) { }
{ return complex<_Tp> (__x) -= __y; } #endif
explicit complex(const complex<float>&);
explicit complex(const complex<long double>&);
template<typename _Tp> double real() const;
inline complex<_Tp> double imag() const;
operator-(const _Tp& __x, const complex<_Tp>& __y)
{ return complex<_Tp> (__x) -= __y; }
template<typename _Tp> complex<double>& operator=(double);
inline complex<_Tp> complex<double>& operator+=(double);
operator*(const complex<_Tp>& __x, const complex<_Tp>& __y) complex<double>& operator-=(double);
{ return complex<_Tp> (__x) *= __y; } complex<double>& operator*=(double);
complex<double>& operator/=(double);
// The compiler will synthetize this, efficiently.
// complex& operator= (const complex&);
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> complex<double>& operator=(const complex<_Tp>&);
operator*(const complex<_Tp>& __x, const _Tp& __y)
{ return complex<_Tp> (__x) *= __y; }
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> complex<double>& operator+=(const complex<_Tp>&);
operator*(const _Tp& __x, const complex<_Tp>& __y)
{ return complex<_Tp> (__y) *= __x; }
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> complex<double>& operator-=(const complex<_Tp>&);
operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
{ return complex<_Tp> (__x) /= __y; }
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> complex<double>& operator*=(const complex<_Tp>&);
operator/(const complex<_Tp>& __x, const _Tp& __y)
{ return complex<_Tp> (__x) /= __y; }
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> complex<double>& operator/=(const complex<_Tp>&);
operator/(const _Tp& __x, const complex<_Tp>& __y)
{ return complex<_Tp> (__x) /= __y; }
template<typename _Tp> private:
inline complex<_Tp> typedef __complex__ double _ComplexT;
operator+(const complex<_Tp>& __x) _ComplexT _M_value;
{ return __x; }
template<typename _Tp> complex(_ComplexT __z) : _M_value(__z) { }
inline complex<_Tp>
operator-(const complex<_Tp>& __x)
{ return complex<_Tp>(-__x.real(), -__x.imag()); }
template<typename _Tp> friend class complex<float>;
inline bool friend class complex<long double>;
operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
{ return __x.real() == __y.real() && __x.imag() == __y.imag(); }
template<typename _Tp> friend complex<double> pow<>(const complex<double>&, int);
inline bool friend complex<double> pow<>(const complex<double>&, const double&);
operator==(const complex<_Tp>& __x, const _Tp& __y) friend complex<double> pow<>(const complex<double>&,
{ return __x.real() == __y && __x.imag() == _Tp(); } const complex<double>&);
friend complex<double> pow<>(const double&, const complex<double>&);
friend complex<double> sqrt<>(const complex<double>&);
friend complex<double> tan<>(const complex<double>&);
friend complex<double> tanh<>(const complex<double>&);
};
inline double
complex<double>::real() const
{ return __real__ _M_value; }
inline 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> template<typename _Tp>
inline bool inline complex<double>&
operator==(const _Tp& __x, const complex<_Tp>& __y) complex<double>::operator=(const complex<_Tp>& __z)
{ return __x == __y.real() && _Tp() == __y.imag(); } {
__real__ _M_value = __z.real();
__imag__ _M_value = __z.imag();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline bool inline complex<double>&
operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y) complex<double>::operator+=(const complex<_Tp>& __z)
{ return __x.real() != __y.real() || __x.imag() != __y.imag(); } {
__real__ _M_value += __z.real();
__imag__ _M_value += __z.imag();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline bool inline complex<double>&
operator!=(const complex<_Tp>& __x, const _Tp& __y) complex<double>::operator-=(const complex<_Tp>& __z)
{ return __x.real() != __y || __x.imag() != _Tp(); } {
__real__ _M_value -= __z.real();
__imag__ _M_value -= __z.imag();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline bool inline complex<double>&
operator!=(const _Tp& __x, const complex<_Tp>& __y) complex<double>::operator*=(const complex<_Tp>& __z)
{ return __x != __y.real() || _Tp() != __y.imag(); } {
_ComplexT __t;
__real__ __t = __z.real();
__imag__ __t = __z.imag();
_M_value *= __t;
return *this;
}
template<typename _Tp, typename _CharT, class _Traits> template<typename _Tp>
basic_istream<_CharT, _Traits>& inline complex<double>&
operator>>(basic_istream<_CharT, _Traits>&, 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, typename _CharT, class _Traits> // 26.2.3 complex specializations
basic_ostream<_CharT, _Traits>& // complex<long double> specialization
operator<<(basic_ostream<_CharT, _Traits>&, const complex<_Tp>&); template<> class complex<long double>
{
public:
typedef long double value_type;
complex(long double = 0.0L, long double = 0.0L);
#ifdef _GLIBCPP_BUGGY_COMPLEX
complex(const complex& __z) : _M_value(__z._M_value) { }
#endif
explicit complex(const complex<float>&);
explicit complex(const complex<double>&);
// Values: long double real() const;
template <typename _Tp> long double imag() const;
inline _Tp
real(const complex<_Tp>& __z)
{ return __z.real(); }
template <typename _Tp> complex<long double>& operator= (long double);
inline _Tp complex<long double>& operator+= (long double);
imag(const complex<_Tp>& __z) complex<long double>& operator-= (long double);
{ return __z.imag(); } complex<long double>& operator*= (long double);
complex<long double>& operator/= (long double);
// The compiler knows how to do this efficiently
// complex& operator= (const complex&);
template<typename _Tp> template<typename _Tp>
inline _Tp complex<long double>& operator=(const complex<_Tp>&);
abs(const complex<_Tp>& __z) template<typename _Tp>
complex<long double>& operator+=(const complex<_Tp>&);
template<typename _Tp>
complex<long double>& operator-=(const complex<_Tp>&);
template<typename _Tp>
complex<long double>& operator*=(const complex<_Tp>&);
template<typename _Tp>
complex<long double>& operator/=(const complex<_Tp>&);
private:
typedef __complex__ long double _ComplexT;
_ComplexT _M_value;
complex(_ComplexT __z) : _M_value(__z) { }
friend class complex<float>;
friend class complex<double>;
friend complex<long double> pow<>(const complex<long double>&, int);
friend complex<long double> pow<>(const complex<long double>&,
const long double&);
friend complex<long double> pow<>(const complex<long double>&,
const complex<long double>&);
friend complex<long double> pow<>(const long double&,
const complex<long double>&);
friend complex<long double> sqrt<>(const complex<long double>&);
friend complex<long double> tan<>(const complex<long double>&);
friend complex<long double> tanh<>(const complex<long double>&);
};
inline
complex<long double>::complex(long double __r, long double __i)
{ {
_Tp __x = __z.real(); __real__ _M_value = __r;
_Tp __y = __z.imag(); __imag__ _M_value = __i;
const _Tp __s = abs(__x) + abs(__y);
if (__s == _Tp()) // well ...
return __s;
__x /= __s; __y /= __s;
return __s * sqrt(__x * __x + __y * __y);
} }
template<typename _Tp> inline long double
inline _Tp complex<long double>::real() const
arg(const complex<_Tp>& __z) { return __real__ _M_value; }
{ return atan2(__z.imag(), __z.real()); }
inline long double
complex<long double>::imag() const
{ return __imag__ _M_value; }
template<typename _Tp> inline complex<long double>&
inline complex<_Tp> complex<long double>::operator=(long double __r)
polar(const _Tp& __rho, const _Tp& __theta) {
{ return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); } __real__ _M_value = __r;
__imag__ _M_value = 0.0L;
return *this;
}
template<typename _Tp> inline complex<long double>&
inline complex<_Tp> complex<long double>::operator+=(long double __r)
conj(const complex<_Tp>& __z) {
{ return complex<_Tp>(__z.real(), -__z.imag()); } __real__ _M_value += __r;
return *this;
}
// // We use here a few more specializations. inline complex<long double>&
// template<> complex<long double>::operator-=(long double __r)
// inline complex<float> {
// conj(const complex<float> &__x) __real__ _M_value -= __r;
// #ifdef _GLIBCPP_BUGGY_FLOAT_COMPLEX return *this;
// { }
// complex<float> __tmpf(~__x._M_value);
// return __tmpf;
// }
// #else
// { return complex<float>(~__x._M_value); }
// #endif
// template<>
// inline complex<double>
// conj(const complex<double> &__x)
// { return complex<double> (~__x._M_value); }
// Transcendentals: inline complex<long double>&
template<typename _Tp> complex<long double>::operator*=(long double __r)
inline complex<_Tp>
cos(const complex<_Tp>& __z)
{ {
const _Tp __x = __z.real(); __real__ _M_value *= __r;
const _Tp __y = __z.imag(); return *this;
return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y));
} }
template<typename _Tp> inline complex<long double>&
inline complex<_Tp> complex<long double>::operator/=(long double __r)
cosh(const complex<_Tp>& __z)
{ {
const _Tp __x = __z.real(); __real__ _M_value /= __r;
const _Tp __y = __z.imag(); return *this;
return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y));
} }
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<long double>&
exp(const complex<_Tp>& __z) complex<long double>::operator=(const complex<_Tp>& __z)
{ return polar(exp(__z.real()), __z.imag()); } {
__real__ _M_value = __z.real();
__imag__ _M_value = __z.imag();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<long double>&
log(const complex<_Tp>& __z) complex<long double>::operator+=(const complex<_Tp>& __z)
{ return complex<_Tp>(log(abs(__z)), arg(__z)); } {
__real__ _M_value += __z.real();
__imag__ _M_value += __z.imag();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<long double>&
log10(const complex<_Tp>& __z) complex<long double>::operator-=(const complex<_Tp>& __z)
{ return log(__z) / log(_Tp(10.0)); } {
__real__ _M_value -= __z.real();
__imag__ _M_value -= __z.imag();
return *this;
}
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<long double>&
sin(const complex<_Tp>& __z) complex<long double>::operator*=(const complex<_Tp>& __z)
{ {
const _Tp __x = __z.real(); _ComplexT __t;
const _Tp __y = __z.imag(); __real__ __t = __z.real();
return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y)); __imag__ __t = __z.imag();
_M_value *= __t;
return *this;
} }
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<long double>&
sinh(const complex<_Tp>& __z) complex<long double>::operator/=(const complex<_Tp>& __z)
{ {
const _Tp __x = __z.real(); _ComplexT __t;
const _Tp __y = __z.imag(); __real__ __t = __z.real();
return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y)); __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.
inline
complex<float>::complex(const complex<double>& __z)
: _M_value(_ComplexT(__z._M_value)) { }
inline
complex<float>::complex(const complex<long double>& __z)
: _M_value(_ComplexT(__z._M_value)) { }
inline
complex<double>::complex(const complex<float>& __z)
: _M_value(_ComplexT(__z._M_value)) { }
inline
complex<double>::complex(const complex<long double>& __z)
{
__real__ _M_value = __z.real();
__imag__ _M_value = __z.imag();
}
inline
complex<long double>::complex(const complex<float>& __z)
: _M_value(_ComplexT(__z._M_value)) { }
inline
complex<long double>::complex(const complex<double>& __z)
: _M_value(_ComplexT(__z._M_value)) { }
} // namespace std } // namespace std
#endif /* _CPP_COMPLEX */ #endif /* _CPP_COMPLEX */
...@@ -296,7 +296,7 @@ namespace std ...@@ -296,7 +296,7 @@ namespace std
abs(double __x) { return __builtin_fabs(__x); } abs(double __x) { return __builtin_fabs(__x); }
#else #else
inline double inline double
abs(double __x) { return fabs (__x); } abs(double __x) { return fabs(__x); }
#endif #endif
extern "C" double floor(double __x); extern "C" double floor(double __x);
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
// invalidate any other reasons why the executable file might be covered by // invalidate any other reasons why the executable file might be covered by
// the GNU General Public License. // the GNU General Public License.
#include <bits/std_cmath.h>
#include <bits/std_complex.h> #include <bits/std_complex.h>
// This is a ISO C 9X header. // This is a ISO C 9X header.
...@@ -45,62 +44,6 @@ ...@@ -45,62 +44,6 @@
namespace std namespace std
{ {
// template<>
// FLT
// abs(const complex<FLT>& __x)
// {
// // We don't use cabs here because some systems (IRIX 6.5, for
// // example) define their own incompatible version.
// return hypot (__real__ __x._M_value, __imag__ __x._M_value);
// }
// template<>
// FLT
// arg(const complex<FLT>& __x)
// { return carg(__x._M_value); }
// template<>
// complex<FLT>
// polar(const FLT& __rho, const FLT& __theta)
// {
// #if 0
// // XXX
// // defined(_GLIBCPP_HAVE_SINCOS) && !defined(__osf__)
// // Although sincos does exist on OSF3.2 and OSF4.0 we cannot use it
// // since the necessary types are not defined in the headers.
// FLT __sinx, __cosx;
// sincos(__theta, &__sinx, &__cosx);
// return complex<FLT>(__rho * __cosx, __rho * __sinx);
// #else
// return complex<FLT>(__rho * cos(__theta), __rho * sin(__theta));
// #endif
// }
// template<>
// complex<FLT>
// cos(const complex<FLT>& __x)
// { return complex<FLT>(ccos(__x._M_value)); }
// template<>
// complex<FLT>
// cosh(const complex<FLT>& __x)
// { return complex<FLT>(ccosh(__x._M_value)); }
// template<>
// complex<FLT>
// exp(const complex<FLT>& __x)
// { return complex<FLT>(cexp(__x._M_value)); }
// template<>
// complex<FLT>
// log(const complex<FLT>& __x)
// { return complex<FLT>(c_log(__x._M_value)); }
// template<>
// complex<FLT>
// log10(const complex<FLT>& __x)
// { return complex<FLT>(clog10(__x._M_value)); }
template<> template<>
complex<FLT> complex<FLT>
pow(const complex<FLT>& __x, int __n) pow(const complex<FLT>& __x, int __n)
...@@ -121,16 +64,6 @@ namespace std ...@@ -121,16 +64,6 @@ namespace std
pow(const FLT& __x, const complex<FLT>& __y) pow(const FLT& __x, const complex<FLT>& __y)
{ return complex<FLT>(cexp(__y._M_value * log(__x))); } { return complex<FLT>(cexp(__y._M_value * log(__x))); }
// template<>
// complex<FLT>
// sin(const complex<FLT>& __x)
// { return complex<FLT>(csin(__x._M_value)); }
// template<>
// complex<FLT>
// sinh(const complex<FLT>& __x)
// { return complex<FLT>(csinh(__x._M_value)); }
template<> template<>
complex<FLT> complex<FLT>
sqrt(const complex<FLT>& __x) sqrt(const complex<FLT>& __x)
......
// 1999-06-29 // 1999-06-29
// bkoz // bkoz
// Copyright (C) 1999 Free Software Foundation, Inc. // Copyright (C) 1999, 2000 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -29,7 +29,7 @@ template<typename T> ...@@ -29,7 +29,7 @@ template<typename T>
struct B { }; struct B { };
bool test01() void test01()
{ {
// 1 // 1
...@@ -43,18 +43,25 @@ bool test01() ...@@ -43,18 +43,25 @@ bool test01()
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
assert(test); assert(test);
#endif #endif
return test;
} }
// 2 // 2
template class std::vector<double>; template class std::vector<double>;
template class std::vector< A<B> >; template class std::vector< A<B> >;
// libstdc++/102
void test02
{
std::vector<int> v1;
std::vector<int> v2 (v1);
}
int main() int main()
{ {
test01(); test01();
test02();
return 0; return 0;
} }
......
// 2000-11-20
// Benjamin Kosnik bkoz@redhat.com
// Copyright (C) 2000 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
#include <complex>
#include <debug_assert.h>
void test01()
{
using namespace std;
bool test = true;
typedef complex<double> complex_type;
const double cd1 = -11.451;
const double cd2 = -442.1533;
complex_type a(cd1, cd2);
double d;
d = a.real();
VERIFY( d == cd1);
d = a.imag();
VERIFY(d == cd2);
complex_type c(cd1, cd2);
double d6 = abs(c);
VERIFY( d6 >= 0);
double d7 = arg(c);
double d8 = atan2(c.imag(), c.real());
VERIFY( d7 == d8);
double d9 = norm(c);
double d10 = d6 * d6;
VERIFY(d9 - d10 == 0);
complex_type e = conj(c);
complex_type f = polar(c.imag(), 0.0);
VERIFY(f.real() != 0);
}
int main()
{
test01();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment