37template <
class _TypeT>
39pow (
const complex<_TypeT>& __a,
int __n)
41 if (__a == complex<_TypeT>())
42 return complex<_TypeT>(0 == __n);
44 if (_TypeT () == __a.imag ()) {
45 if (__a.real () < _TypeT ())
46 return pow (__a, complex<_TypeT>(__n));
48 return complex<_TypeT>(_RWSTD_C::pow (__a.real (), __n));
51 _TypeT __r = _RWSTD_C::pow (_TypeT (
abs (__a)), __n);
52 _TypeT __th = __n *
arg (__a);
54 return complex<_TypeT>(__r * _RWSTD_C::cos (__th),
55 __r * _RWSTD_C::sin (__th));
62template <
class _TypeT>
64pow (
const complex<_TypeT> &__a,
const _TypeT &__s)
66 if (__a == complex<_TypeT>())
67 return complex<_TypeT>(_TypeT () == __s);
69 if (_TypeT () == __a.imag ()) {
70 if (__a.real () < _TypeT ())
71 return pow (__a, complex<_TypeT>(__s));
73 return complex<_TypeT>(_RWSTD_C::pow (__a.real (), __s));
75 return exp (__s * log (__a));
82template <
class _TypeT>
84pow (
const _TypeT& __s,
const complex<_TypeT>& __a)
87 return complex<_TypeT>(complex<_TypeT>() == __a);
90 return pow (complex<_TypeT>(__s), __a);
92 if (_TypeT () == __a.imag ())
93 return complex<_TypeT>(_RWSTD_C::pow (__s, __a.real ()));
95 return complex<_TypeT>(exp(__a * _TypeT (_RWSTD_C::log (__s))));
104template <
class _TypeT>
106pow (
const complex<_TypeT>& __x,
const complex<_TypeT>& __y)
108 if (complex<_TypeT>() == __x)
109 return complex<_TypeT>(complex<_TypeT>() == __y);
111 _TypeT __r1 =
abs (__x);
112 _TypeT __u2 = real (__y);
113 _TypeT __v2 = imag (__y);
114 _TypeT __th1 =
arg (__x);
115 _TypeT __rho = _RWSTD_C::pow (__r1, __u2) * _RWSTD_C::exp (-__v2 * __th1);
116 _TypeT __phi = __v2 * _RWSTD_C::log (__r1) + __u2 * __th1;
118 return complex<_TypeT>(__rho * _RWSTD_C::cos (__phi),
119 __rho * _RWSTD_C::sin (__phi));
124template <
class _TypeT,
class _CharT,
class _Traits>
125basic_istream<_CharT, _Traits >&
126operator>> (basic_istream<_CharT, _Traits>& __strm, complex<_TypeT> &__val)
135 _TypeT __re = _TypeT (),
140 if (!(__strm >> __ch))
144 if (__strm >> __re && __strm >> __ch) {
145 if (
',' == __ch && __strm >> __im)
150 if (
')' != __ch && __strm)
151 __strm.setstate (__strm.failbit);
154 else if (__strm.putback (__ch)) {
159 __val = complex<_TypeT>(__re, __im);
166template <
class _TypeT,
class _CharT,
class _Traits>
167basic_ostream<_CharT, _Traits>&
168operator<< (basic_ostream<_CharT, _Traits >& __strm,
169 const complex<_TypeT>& __val)
171 basic_ostringstream<_CharT, _Traits, allocator<_CharT> > __ss;
172 __ss.flags (__strm.flags ());
173 __ss.imbue (__strm.getloc ());
174 __ss.precision (__strm.precision ());
175 __ss <<
'(' << __val.real () <<
',' << __val.imag () <<
')';
176 return __strm << __ss.str ();
#define _RWSTD_NAMESPACE(name)
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &lhs, node_type rhs)
Pretty-prints the value of a node_type to a stream.