14 #ifndef BRIDGE_COMPLEX_INCLUDED
15 #define BRIDGE_COMPLEX_INCLUDED
29 #if defined USE_STD_COMPLEX
34 typedef std::complex<int> icomplex;
35 typedef std::complex<float> fcomplex;
36 typedef std::complex<double> dcomplex;
39 inline icomplex cmplx(
const int r,
const int i) {
return icomplex(r, i); }
40 inline fcomplex cmplx(
const float r,
const float i) {
return fcomplex(r, i); }
41 inline dcomplex cmplx(
const double r,
const double i) {
return dcomplex(r, i); }
46 #elif defined USE_C99_COMPLEX
52 icomplex() : m_r(0), m_i(0) {}
53 icomplex(
const int r,
const int i = 0) : m_r(r), m_i(i) {}
54 icomplex(
const icomplex& rhs) : m_r(rhs.m_r), m_i(rhs.m_i) {}
57 icomplex& operator=(
const icomplex& rhs)
64 icomplex& operator*=(
const icomplex& rhs)
69 m_r = re * rhs.m_r - im * rhs.m_i;
70 m_i = re * rhs.m_i + im * rhs.m_r;
74 friend icomplex
operator*(
const icomplex& lhs,
const icomplex& rhs)
76 return icomplex(lhs.m_r * rhs.m_r - lhs.m_i * rhs.m_i,
77 lhs.m_r * rhs.m_i + lhs.m_i * rhs.m_r);
80 friend int real(
const icomplex& z) {
return z.m_r; }
81 friend int imag(
const icomplex& z) {
return z.m_i; }
88 inline icomplex cmplx(
const int real,
const int imag)
90 return icomplex(real, imag);
94 typedef float _Complex fcomplex;
95 typedef double _Complex dcomplex;
98 inline float real(
const fcomplex& z) {
return crealf(z); }
99 inline float imag(
const fcomplex& z) {
return cimagf(z); }
100 inline float abs(
const fcomplex& z) {
return cabsf(z); }
101 inline fcomplex cmplx(
const float real,
const float imag)
103 return real + imag * _Complex_I;
107 inline double real(
const dcomplex& z) {
return creal(z); }
108 inline double imag(
const dcomplex& z) {
return cimag(z); }
109 inline double abs(
const dcomplex& z) {
return cabs(z); }
110 inline dcomplex cmplx(
const double real,
const double imag)
112 return real + imag * _Complex_I;
116 inline dcomplex sqrt(
const dcomplex& z) {
return csqrt(z); }
135 #endif // BRIDGE_COMPLEX_INCLUDED