Complex Class Reference

Class Complex to represent complex numbers as a field. More...

## Public Member Functions

| Complex (double x=0.f, double y=0.f, bool is_polar=false)
| Complex Constructor which initialises our complex number. More...
| Complex (const Complex &other)
| Copy Constructor. More...
double | real () const
| Member function to get real value of our complex number. Member function (getter) to access the class' re value.
double | imag () const
| Member function to get imaginary value of our complex number. Member function (getter) to access the class' im value.
double | abs () const
| Member function to give the modulus of our complex number. Member function to which gives the absolute value (modulus) of our complex number. More...
double | arg () const
| Member function to give the argument of our complex number. More...
Complex | operator+ (const Complex &other)
| Operator overload of '+' on Complex class. Operator overload to be able to add two complex numbers. More...
Complex | operator- (const Complex &other)
| Operator overload of '-' on Complex class. Operator overload to be able to subtract two complex numbers. More...
Complex | operator* (const Complex &other)
| Operator overload of '*' on Complex class. Operator overload to be able to multiple two complex numbers. More...
Complex | operator~ () const
| Operator overload of '~' on Complex class. 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. More...
Complex | operator/ (const Complex &other)
| Operator overload of '/' on Complex class. Operator overload to be able to divide two complex numbers. This function would throw an exception if the other number is zero. More...
const Complex & | operator= (const Complex &other)
| Operator overload of '=' on Complex class. Operator overload to be able to copy RHS instance of Complex to LHS instance of Complex.

## Private Attributes

double | re
double | im

## Detailed Description

Class Complex to represent complex numbers as a field.

## Constructor & Destructor Documentation

## Complex() [1/2]

Complex::Complex | ( | double | x = `0.f`,
|  | double | y = `0.f`,
|  | bool | is_polar = `false`
| ) |  |

inlineexplicit

Complex Constructor which initialises our complex number.

Complex Constructor which initialises the complex number which takes three 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).

{
if (!is_polar) {
re = x;
im = y;
return;
}
re = x * std::cos(y);
im = x * std::sin(y);
}
std::cos
T cos(T... args)
std::sin
T sin(T... args)
Here is the call graph for this function:

## Complex() [2/2]

Complex::Complex | ( | const Complex & | other | ) |

inline

Copy Constructor.

Parameters

  other | The other number to equate our number to.

: re(other.real()), im(other.imag()) {}
Complex::real
double real() const
Member function to get real value of our complex number. Member function (getter) to access the class...
Definition: complex_numbers.cpp:64
Complex::imag
double imag() const
Member function to get imaginary value of our complex number. Member function (getter) to access the ...
Definition: complex_numbers.cpp:70

## Member Function Documentation

## abs()

double Complex::abs | ( |  | ) | const

inline

Member function to give the modulus of our complex number. Member function to which gives the absolute value (modulus) of our complex number.

Returns
  \( \sqrt{z \bar{z}} \) where \( z \) is our complex number.

{
return std::sqrt(this->re * this->re + this->im * this->im);
}
std::sqrt
T sqrt(T... args)
Here is the call graph for this function:

## arg()

double Complex::arg | ( |  | ) | const

inline

Member function to give the argument of our complex number.

Returns
  Argument of our Complex number in radians.

{ return std::atan2(this->im, this->re); }
std::atan2
T atan2(T... args)
Here is the call graph for this function:

## operator*()

Complex Complex::operator* | ( | const Complex & | other | ) |

inline

Operator overload of '*' on Complex class. 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.

{
Complex result(this->re * other.re - this->im * other.im,
this->re * other.im + this->im * other.re);
return result;
}
Complex
Class Complex to represent complex numbers as a field.
Definition: complex_numbers.cpp:20
math::fibonacci_sum::result
uint64_t result(uint64_t n)
Definition: fibonacci_sum.cpp:76

## operator+()

Complex Complex::operator+ | ( | const Complex & | other | ) |

inline

Operator overload of '+' on Complex class. 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

{
Complex result(this->re + other.re, this->im + other.im);
return result;
}

## operator-()

Complex Complex::operator- | ( | const Complex & | other | ) |

inline

Operator overload of '-' on Complex class. 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

{
Complex result(this->re - other.re, this->im - other.im);
return result;
}

## operator/()

Complex Complex::operator/ | ( | const Complex & | other | ) |

inline

Operator overload of '/' on Complex class. 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.

{
Complex result = *this * ~other;
double denominator =
other.real() * other.real() + other.imag() * other.imag();
if (denominator != 0) {
result = Complex(result.real() / denominator,
result.imag() / denominator);
return result;
} else {
throw std::invalid_argument("Undefined Value");
}
}
Complex::Complex
Complex(double x=0.f, double y=0.f, bool is_polar=false)
Complex Constructor which initialises our complex number.
Definition: complex_numbers.cpp:43
std::invalid_argument
Here is the call graph for this function:

## operator~()

Complex Complex::operator~ | ( |  | ) | const

inline

Operator overload of '~' on Complex class. 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.

{
Complex result(this->re, -(this->im));
return result;
}

The documentation for this class was generated from the following file:

- math/complex_numbers.cpp