#ifndef complex_h #define complex_h class Complex { private: float re_; float im_; public: Complex(float r=0, float i=0) { re_=r; im_=i; } int operator==( const Complex& c ); Complex operator+( const Complex& c ); Complex operator-( const Complex& c ); Complex operator/( const Complex& c ); Complex operator*( const Complex& c ); float getRe() { return re_; }; float setRe(float re_) { re_ = re_; }; float getIm() { return im_; }; float setIm(float im_) { im_ = im_; }; }; inline int Complex::operator==( const Complex& c ) { return( re_==c.re_ && im_==c.im_ ); } inline Complex Complex::operator+( const Complex& c ) { return( Complex (re_+c.re_, im_+c.im_) ); // Cria Objeto temporario } inline Complex Complex::operator-( const Complex& c ) { return( Complex (re_-c.re_, im_-c.im_) ); // Cria Objeto temporario } inline Complex Complex::operator*( const Complex& c ) { return( Complex (re_*c.re_-im_*c.im_, re_*c.im_ + im_*c.re_) ); // Cria Objeto temporario } inline Complex Complex::operator/( const Complex& c ) { if( c.re_ > c.im_ ) { float d1 = c.im_/c.re_, // (a+bi)/(c-di) = ((a+bd')+i(b-ad'))/(c+dd') // onde d' = d/c div = c.re_ + c.im_*d1; return Complex( (re_+im_*d1)/div, (im_ - re_*d1)/div ); } else { float c1 = c.re_/c.im_, // (a+bi)/(c-di) = ((a+bc')+i(b-ac'))/(cc'+d) // onde c' = c/d div = c.re_*c1 + c.im_; return Complex( (re_*c1+im_)/div, (im_*c1 - re_)/div ); } } #endif