Class Complex to represent complex numbers as a field.
◆ Complex() [1/2]
| Complex::Complex |
( |
double |
x = 0.f, |
|
|
double |
y = 0.f, |
|
|
bool |
is_polar = false |
|
) |
| |
|
inlineexplicit |
Complex Constructor which initialises the complex number which takes two arguments.
- Parameters
-
| x | If the third parameter is 'true' then this x is the absolute value of the complex number, if the third parameter is 'false' then this x is the real value of the complex number (optional). |
| y | If the third parameter is 'true' then this y is the argument of the complex number, if the third parameter is 'false' then this y is the imaginary value of the complex number (optional). |
| is_polar | 'false' by default. If we want to initialise our complex number using polar form then set this to true, otherwise set it to false to use initialiser which initialises real and imaginary values using the first two parameters (optional). |
◆ Complex() [2/2]
| Complex::Complex |
( |
const Complex & |
other | ) |
|
|
inline |
Copy Constructor
- Parameters
-
| other | The other number to equate our number to. |
55 : re(other.
real()), im(other.
imag()) {}
◆ abs()
| double Complex::abs |
( |
| ) |
const |
|
inline |
Member function to which gives the absolute value (modulus) of our complex number
- Returns
- \( \sqrt{z \dot \bar{z}} \) where \( z \) is our complex number.
74 return std::sqrt(this->re * this->re + this->im * this->im);
◆ arg()
| double Complex::arg |
( |
| ) |
const |
|
inline |
Member function which gives the argument of our complex number.
- Returns
- Argument of our Complex number in radians.
◆ imag()
| double Complex::imag |
( |
| ) |
const |
|
inline |
Member function (getter) to access the class' im value.
◆ operator*()
Operator overload to be able to multiple two complex numbers.
- Parameters
-
| other | The other number to multiply the current number to. |
- Returns
- result current number times other number.
109 Complex result(this->re * other.re - this->im * other.im,
110 this->re * other.im + this->im * other.re);
◆ operator+()
Operator overload to be able to add two complex numbers.
- Parameters
-
| other | The other number that is added to the current number. |
- Returns
- result current number plus other number
89 Complex result(this->re + other.re, this->im + other.im);
◆ operator-()
Operator overload to be able to subtract two complex numbers.
- Parameters
-
| other | The other number being subtracted from the current number. |
- Returns
- result current number subtract other number
99 Complex result(this->re - other.re, this->im - other.im);
◆ operator/()
Operator overload to be able to divide two complex numbers. This function would throw an exception if the other number is zero.
- Parameters
-
| other | The other number we divide our number by. |
- Returns
- result Current number divided by other number.
132 Complex result = *
this * ~other;
135 if (denominator != 0) {
137 result.
imag() / denominator);
◆ operator=()
Operator overload to be able to copy RHS instance of Complex to LHS instance of Complex
149 this->re = other.
real();
150 this->im = other.
imag();
◆ operator~()
| Complex Complex::operator~ |
( |
| ) |
const |
|
inline |
Operator overload of the BITWISE NOT which gives us the conjugate of our complex number. NOTE: This is overloading the BITWISE operator but its not a BITWISE operation in this definition.
- Returns
- result The conjugate of our complex number.
121 Complex result(this->re, -(this->im));
◆ real()
| double Complex::real |
( |
| ) |
const |
|
inline |
Member function (getter) to access the class' re value.
The documentation for this class was generated from the following file: