Created
December 7, 2012 00:14
-
-
Save daemonfire300/4229626 to your computer and use it in GitHub Desktop.
Complex Numbers in C++ WIP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef COMPLEX_H_INCLUDED | |
#define COMPLEX_H_INCLUDED | |
struct ComplexNumber{ | |
double realPart; | |
double imaginaryPart; | |
ComplexNumber operator+(ComplexNumber k) | |
{ | |
this.realPart += k.realPart; | |
this.imaginaryPart += k.imaginaryPart; | |
return this; | |
} | |
ComplexNumber operator-(ComplexNumber k) | |
{ | |
this.realPart -= k.realPart; | |
this.imaginaryPart -= k.imaginaryPart; | |
return this; | |
} | |
ComplexNumber operator*(ComplexNumber k) | |
{ | |
this.realPart = (this.realPart * k.imaginaryPart) - (k.realPart * this.imaginaryPart); | |
this.imaginaryPart = (k.realPart * this.imaginaryPart) + (this.realPart * k.imaginaryPart); | |
return this; | |
} | |
ComplexNumber operator/(ComplexNumber k) | |
{ | |
this.realPart = ((this.realPart * k.realPart) + (this.imaginaryPart * k.imaginaryPart)) / (pow(k.realPart, 2)+pow(k.imaginaryPart, 2)); | |
this.imaginaryPart = ((this.imaginaryPart * k.realPart) + (this.realPart * k.imaginaryPart)) / (pow(k.realPart, 2)+pow(k.imaginaryPart, 2)); | |
return this; | |
} | |
} | |
#endif // COMPLEX_H_INCLUDED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment