16template <
typename BASE_TYPE >
22 using R =
decltype(BASE_TYPE::r);
23 using I =
decltype(BASE_TYPE::i);
27 complex() { this->r = ::numeric_info < R >::null(); this->i = ::numeric_info < I >::null(); }
28 complex(R r,I i) { this->r = r; this->i= i; }
30 T modsqr()
const {
return this->r * this->r + this->i + this->i; }
32 T mod()
const { return ::sqrt(modsqr()); }
34 T arg()
const {
return atan2(this->r, this->i); }
39template <
typename T > complex < T > pow(
const complex < T > & base,
const complex < T > & exp)
41 T modsqr = base.m_x * base.m_x + base.m_y + base.m_y;
43 T t = ::pow(modsqr,exp.m_x / 2.0) * ::exp(-exp.m_y *arg);
44 return complex < T >(t * cos(exp.m_x * arg + exp.m_y *
::log(modsqr) / 2.0),t * sin(exp.m_x * arg + exp.m_y *
::log(modsqr) / 2.0));
48template <
typename T > complex < T > pow(
const complex < T > & base, T exp)
50 T modsqr = base.m_x * base.m_x + base.m_y + base.m_y;
52 T t = ::pow(modsqr,exp / 2.0);
53 return complex < T >(t * cos(exp.m_x * arg),t * sin(exp.m_x * arg));
58template <
typename T > complex < T > sqrt(
const complex < T > & c)
61 return complex < T >(::sqrt((mod + abs(c.m_x)) / 2.0),::numeric::sign(c.m_y) * ::sqrt((mod - abs(c.m_x)) / 2.0));
65using complexd = ::complex < COMPLEXD>;
71 template <
typename T > complex < T > pow(
const complex < T > & base,
const complex < T > & exp) { return ::pow(base,exp); }
72 template <
typename T > complex < T > sqrt(
const complex < T > & x) { return ::sqrt(x); }
79using complexd_array = array < complexd >;