#include #include #include #include #include "ComplexVector.hpp" void ComplexDebug(char *fmtstr, ...) { char buf[1024]; va_list args; va_start(args, fmtstr); vsprintf(buf, fmtstr, args); va_end(args); OutputDebugString(buf); } // Class Methods // Standard constructor ComplexVector::ComplexVector(uint32_t size, radio_float_t *real, radio_float_t *imag) : m_size(size) , m_real(size, real) , m_imag(size, imag) { } // Constructor from RealVector ComplexVector::ComplexVector(const RealVector &real, const RealVector &imag) : m_size(real.getSize()) , m_real(real, real.m_unary_modifier) , m_imag(imag, imag.m_unary_modifier) { // Check if real and imag have same length } // Constructor from RealVector pointer ComplexVector::ComplexVector(RealVector *real, RealVector *imag) : m_size(real->getSize()) , m_real(*real) , m_imag(*imag) { // Check if real and imag have same length } // Scalar constructor ComplexVector::ComplexVector(radio_float_t real, radio_float_t imag) : m_size(1) , m_real(real) , m_imag(imag) { } // ComplexVector::ComplexVector(const _ComplexVector &src) : m_size(src.m_size) , m_real(src.m_real) , m_imag(src.m_imag) { } // _ComplexVector::_ComplexVector(const ComplexVector &src) : m_size(src.m_size) , m_real(src.m_real) , m_imag(src.m_imag) { } _ComplexVector::_ComplexVector(const _RealVector &real, const _RealVector &imag) : m_size(real.m_size) , m_real(real) , m_imag(imag) { } ComplexVector::~ComplexVector(void) { } _ComplexVector _ComplexVector::operator-() const { return _ComplexVector(-this->m_real, -this->m_imag); } _ComplexVector _ComplexVector::conj() const { return _ComplexVector(this->m_real, -this->m_imag); } uint32_t ComplexVector::getSize() { return m_size; } ComplexVector ComplexVector::at(uint32_t const &i) { return ComplexVector(*this, i, 1, i); } void ComplexVector::print(char *pPrefix) { uint32_t i; ComplexDebug("%s:\n", pPrefix); for (i=0; i < m_size; i++) { if (m_imag.at(i).getValue() < 0) { ComplexDebug("%d: %.6f - %.6fj\n", i, m_real.at(i).getValue(), -m_imag.at(i).getValue()); } else { ComplexDebug("%d: %.6f + %.6fj\n", i, m_real.at(i).getValue(), m_imag.at(i).getValue()); } } } ComplexVector ComplexVector::operator-() const { return ComplexVector(-this->m_real, -this->m_imag); } const ComplexVector& ComplexVector::operator+() const { return *this; } ComplexVector ComplexVector::conj() const { return ComplexVector(this->m_real, -this->m_imag); } // ------------------------------------------------- // Assignments // ------------------------------------------------- // = ComplexVector ComplexVector& ComplexVector::operator=(const ComplexVector &src) { this->m_real = src.m_real; this->m_imag = src.m_imag; return *this; } // += ComplexVector ComplexVector& ComplexVector::operator+=(const ComplexVector &src) { this->m_real += src.m_real; this->m_imag += src.m_imag; return *this; } // -= ComplexVector ComplexVector& ComplexVector::operator-=(const ComplexVector &src) { this->m_real -= src.m_real; this->m_imag -= src.m_imag; return *this; } // *= ComplexVector ComplexVector& ComplexVector::operator*=(const ComplexVector &src) { this->m_real = (this->m_real*src.m_real - this->m_imag*src.m_imag); this->m_imag = (this->m_real*src.m_imag + this->m_imag*src.m_real); return *this; } // /= ComplexVector ComplexVector& ComplexVector::operator/=(const ComplexVector &src) { // ToDo: Das ist falsch this->m_real = (this->m_real*src.m_real - this->m_imag*src.m_imag); this->m_imag = (this->m_real*src.m_imag + this->m_imag*src.m_real); return *this; } // Binary operators // = ComplexVector::OpBinaryAdd ComplexVector& ComplexVector::operator=(OpBinary src) { this->m_real = (src.a.m_real + src.b.m_real); this->m_imag = (src.a.m_imag + src.b.m_imag); return *this; } // = ComplexVector::OpBinaryAdd ComplexVector& ComplexVector::operator+=(OpBinary src) { this->m_real += (src.a.m_real + src.b.m_real); this->m_imag += (src.a.m_imag + src.b.m_imag); return *this; } // = ComplexVector::OpBinaryAdd ComplexVector& ComplexVector::operator-=(OpBinary src) { this->m_real -= (src.a.m_real + src.b.m_real); this->m_imag -= (src.a.m_imag + src.b.m_imag); return *this; } // = ComplexVector::OpBinaryAdd ComplexVector& ComplexVector::operator*=(OpBinary src) { // ToDo: this wird über schrieben this->m_real = ((src.a.m_real + src.b.m_real)*this->m_real - (src.a.m_imag + src.b.m_imag)*this->m_imag); this->m_imag = ((src.a.m_imag + src.b.m_imag)*this->m_real + (src.a.m_real + src.b.m_real)*this->m_imag); return *this; } // = ComplexVector::OpBinaryAdd ComplexVector& ComplexVector::operator/=(OpBinary src) { // ToDo: this wird über schrieben // ToDo: Das ist falsch this->m_real = ((src.a.m_real + src.b.m_real)*this->m_real - (src.a.m_imag + src.b.m_imag)*this->m_imag); this->m_imag = ((src.a.m_imag + src.b.m_imag)*this->m_real + (src.a.m_real + src.b.m_real)*this->m_imag); return *this; } // = ComplexVector::OpBinarySub ComplexVector& ComplexVector::operator=(OpBinary src) { this->m_real = (src.a.m_real - src.b.m_real); this->m_imag = (src.a.m_imag - src.b.m_imag); return *this; } // = ComplexVector::OpBinarySub ComplexVector& ComplexVector::operator+=(OpBinary src) { this->m_real += (src.a.m_real - src.b.m_real); this->m_imag += (src.a.m_imag - src.b.m_imag); return *this; } // = ComplexVector::OpBinarySub ComplexVector& ComplexVector::operator-=(OpBinary src) { this->m_real -= (src.a.m_real - src.b.m_real); this->m_imag -= (src.a.m_imag - src.b.m_imag); return *this; } // = ComplexVector::OpBinarySub ComplexVector& ComplexVector::operator*=(OpBinary src) { // ToDo: this wird über schrieben this->m_real = ((src.a.m_real - src.b.m_real)*this->m_real - (src.a.m_imag - src.b.m_imag)*this->m_imag); this->m_imag = ((src.a.m_imag - src.b.m_imag)*this->m_real + (src.a.m_real - src.b.m_real)*this->m_imag); return *this; } // = ComplexVector::OpBinarySub ComplexVector& ComplexVector::operator/=(OpBinary src) { // ToDo: this wird über schrieben // ToDo: Das ist falsch this->m_real = ((src.a.m_real - src.b.m_real)*this->m_real - (src.a.m_imag - src.b.m_imag)*this->m_imag); this->m_imag = ((src.a.m_imag - src.b.m_imag)*this->m_real + (src.a.m_real - src.b.m_real)*this->m_imag); return *this; } // = ComplexVector::OpBinaryMul ComplexVector& ComplexVector::operator=(OpBinary src) { if ((this != &reinterpret_cast(src.a)) && (this != &reinterpret_cast(src.b))) { this->m_real = (src.a.m_real * src.b.m_real); this->m_real -= (src.a.m_imag * src.b.m_imag); this->m_imag = (src.a.m_real * src.b.m_imag); this->m_imag += (src.a.m_imag * src.b.m_real); } else { ComplexVector result((src.a.m_real * src.b.m_real) - (src.a.m_imag * src.b.m_imag), (src.a.m_real * src.b.m_imag) + (src.a.m_imag * src.b.m_real)); *this = result; } return *this; } // += ComplexVector::OpBinaryMul ComplexVector& ComplexVector::operator+=(OpBinary src) { if ((this != &reinterpret_cast(src.a)) && (this != &reinterpret_cast(src.b))) { this->m_real += (src.a.m_real * src.b.m_real); this->m_real -= (src.a.m_imag * src.b.m_imag); this->m_imag += (src.a.m_real * src.b.m_imag); this->m_imag += (src.a.m_imag * src.b.m_real); } else { ComplexVector result((src.a.m_real * src.b.m_real) - (src.a.m_imag * src.b.m_imag), (src.a.m_real * src.b.m_imag) + (src.a.m_imag * src.b.m_real)); *this = *this + result; } return *this; } // -= ComplexVector::OpBinaryMul ComplexVector& ComplexVector::operator-=(OpBinary src) { if ((this != &reinterpret_cast(src.a)) && (this != &reinterpret_cast(src.b))) { this->m_real -= (src.a.m_real * src.b.m_real); this->m_real += (src.a.m_imag * src.b.m_imag); this->m_imag -= (src.a.m_real * src.b.m_imag); this->m_imag -= (src.a.m_imag * src.b.m_real); } else { ComplexVector result((src.a.m_real * src.b.m_real) - (src.a.m_imag * src.b.m_imag), (src.a.m_real * src.b.m_imag) + (src.a.m_imag * src.b.m_real)); *this = *this - result; } return *this; } // *= ComplexVector::OpBinaryMul ComplexVector& ComplexVector::operator*=(OpBinary src) { ComplexVector result((src.a.m_real * src.b.m_real) - (src.a.m_imag * src.b.m_imag), (src.a.m_real * src.b.m_imag) + (src.a.m_imag * src.b.m_real)); *this = *this * result; return *this; } // /= ComplexVector::OpBinaryMul ComplexVector& ComplexVector::operator/=(OpBinary src) { ComplexVector result((src.a.m_real * src.b.m_real) - (src.a.m_imag * src.b.m_imag), (src.a.m_real * src.b.m_imag) + (src.a.m_imag * src.b.m_real)); *this = *this / result; return *this; } // Div // = ComplexVector::OpBinaryDiv ComplexVector& ComplexVector::operator=(OpBinary src) { if ((this != &reinterpret_cast(src.a)) && (this != &reinterpret_cast(src.b))) { this->m_real = (src.a.m_real * src.b.m_real); this->m_real -= (src.a.m_imag * src.b.m_imag); this->m_imag = (src.a.m_real * src.b.m_imag); this->m_imag += (src.a.m_imag * src.b.m_real); } else { ComplexVector result((src.a.m_real * src.b.m_real) - (src.a.m_imag * src.b.m_imag), (src.a.m_real * src.b.m_imag) + (src.a.m_imag * src.b.m_real)); *this = result; } return *this; } // += ComplexVector::OpBinaryDiv ComplexVector& ComplexVector::operator+=(OpBinary src) { if ((this != &reinterpret_cast(src.a)) && (this != &reinterpret_cast(src.b))) { this->m_real += (src.a.m_real * src.b.m_real); this->m_real -= (src.a.m_imag * src.b.m_imag); this->m_imag += (src.a.m_real * src.b.m_imag); this->m_imag += (src.a.m_imag * src.b.m_real); } else { ComplexVector result((src.a.m_real * src.b.m_real) - (src.a.m_imag * src.b.m_imag), (src.a.m_real * src.b.m_imag) + (src.a.m_imag * src.b.m_real)); *this = *this + result; } return *this; } // -= ComplexVector::OpBinaryDiv ComplexVector& ComplexVector::operator-=(OpBinary src) { if ((this != &reinterpret_cast(src.a)) && (this != &reinterpret_cast(src.b))) { this->m_real -= (src.a.m_real * src.b.m_real); this->m_real += (src.a.m_imag * src.b.m_imag); this->m_imag -= (src.a.m_real * src.b.m_imag); this->m_imag -= (src.a.m_imag * src.b.m_real); } else { ComplexVector result((src.a.m_real * src.b.m_real) - (src.a.m_imag * src.b.m_imag), (src.a.m_real * src.b.m_imag) + (src.a.m_imag * src.b.m_real)); *this = *this - result; } return *this; } // *= ComplexVector::OpBinaryDiv ComplexVector& ComplexVector::operator*=(OpBinary src) { ComplexVector result((src.a.m_real * src.b.m_real) - (src.a.m_imag * src.b.m_imag), (src.a.m_real * src.b.m_imag) + (src.a.m_imag * src.b.m_real)); *this = *this * result; return *this; } // /= ComplexVector::OpBinaryDiv ComplexVector& ComplexVector::operator/=(OpBinary src) { ComplexVector result((src.a.m_real * src.b.m_real) - (src.a.m_imag * src.b.m_imag), (src.a.m_real * src.b.m_imag) + (src.a.m_imag * src.b.m_real)); *this = *this / result; return *this; } // ------------------------------------------------- // Binary Operators // ------------------------------------------------- // Add // ComplexVector + ComplexVector* ComplexVector::OpBinary operator+(const ComplexVector &a, const ComplexVector &b) { return ComplexVector::OpBinary (a, b); } // Sub // ComplexVector - ComplexVector* ComplexVector::OpBinary operator-(const ComplexVector &a, const ComplexVector &b) { return ComplexVector::OpBinary (a, b); } // Mul // ComplexVector * ComplexVector* ComplexVector::OpBinary operator*(const ComplexVector &a, const ComplexVector &b) { return ComplexVector::OpBinary (a, b); } // Div // ComplexVector / ComplexVector* ComplexVector::OpBinary operator/(const ComplexVector &a, const ComplexVector &b) { return ComplexVector::OpBinary (a, b); }