TComplex TComplex::operator= (TComplex complex) { //проверка на самоприсваивание if (this == &complex) { return *this; } this->real = complex.get_re(); this->imagine = complex.get_im(); return TComplex(complex.get_re(), complex.get_im()); }
bool TComplex::operator !=(TComplex right) { return real != right.get_re() || imagine != right.get_im(); }
bool TComplex::operator ==(TComplex right) { return real == right.get_re() && imagine == right.get_im(); }
TComplex TComplex::operator/ (TComplex right) { /*(a1*a2 + b1*b2)/(a2**2 + b2**2)+i*(a2*b1 – a1*b2)/(a2**2 + b2**2))*/ double _real = (real * right.get_re() + imagine * right.get_im()) / (right.get_re()*right.get_re() + right.get_im()*right.get_im()); double _imagine = (imagine * right.get_re() - real * right.get_im()) / (right.get_re()*right.get_re() + right.get_im()*right.get_im()); return TComplex(_real, _imagine); }
TComplex TComplex::operator* (TComplex right) { /*(a1*a2 - b1*b2)+i*(a1*b2+ a2*b1))*/ double _real = real * right.get_re() - imagine * right.get_im(); double _imagine = real * right.get_im() + imagine * right.get_re(); return TComplex(_real, _imagine); }
TComplex TComplex::operator- (TComplex right) { return TComplex(real - right.get_re(), imagine - right.get_im()); }
TComplex TComplex::operator+ (TComplex right) { return TComplex(real + right.get_re(), imagine + right.get_im()); }