- Main Page
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Members

# Complex Class Reference

Complex class implements a set of data types, conversions, and operations for complex numbers. More...

`#include <Complex.h>`

List of all members.

## Public Member Functions
| Complex ()
| Default constructor.
| Complex (Real i)
| Construct Complex from real part.
| Complex (Real r, Real i)
| Construct Complex from real and imaginary.
Real | r (Void)
| Get the real part of Complex number as a Real.
Real | i (Void)
| Get the imaginary part of the Complex number as a Real.
Void | r (Real r)
| Set the real part of Complex number.
Void | i (Real i)
| Set the imaginary part of Complex number.
Complex & | operator= (Const Real &x)
| Asignment operator for Complex = Real.
Bool | operator== (Const Complex &x) Const
| Equality operator for Complex == Complex.
Bool | operator!= (Const Complex &x) Const
| Inquality operator for Complex != Complex.
Bool | operator< (Const Complex &x) Const
| Less-than operator for Complex < Complex.
Bool | operator<= (Const Complex &x) Const
| Less-than or equal operator for Complex < Complex.
Bool | operator>= (Const Complex &x) Const
| Greater-than or equal operator for Complex < Complex.
Bool | operator> (Const Complex &x) Const
| Greater-than operator for Complex < Complex.
Complex | operator+ (Const Complex &c)
| Addition operator for Complex + Complex.
Complex | operator- (Const Complex &c)
| Subtraction operator for Complex - Complex.
Complex | operator- ()
| Negation operator for Complex.
Complex | operator~ ()
| Conjugation operator for Complex.
Complex | operator * (Const Complex &c)
| Multiplication operator for Complex * Complex.
Complex | operator * (Const Real &r)
| Multiplication operator for Complex * Real.
Complex | operator/ (Const Complex &c)
| Division operator for Complex / Complex.
Complex | operator/ (Const Real &r)
| Division operator for Complex / Real.
Complex & | operator+= (const Complex x)
| Increment operator for Complex += Complex.
Complex & | operator-= (const Complex x)
| Decrement operator for Complex -= Complex.
Complex & | operator *= (const Complex x)
| Multiply scale operator for Complex *= Complex.
Complex & | operator/= (const Complex x)
| Divide scale operator for Complex /= Complex.
Complex & | operator/= (const Real r)
| Divide scale operator for Complex /= Real.
Complex | Abs ()
| Complex absolute value.
Complex | Conjugate ()
| Complex conjugate.
Complex | Exp (Complex e)
| Complex exponentiation.
Void | print (String s=0)
| Print complex value, prepended by String s if not null.
## Friends
ostream & | operator<< (ostream &os, const Complex &c)
| Print to output stream.
istream & | operator>> (istream &is, Complex &c)
| Read from input stream.

## Detailed Description

Complex class implements a set of data types, conversions, and operations for complex numbers.

Definition at line 28 of file Complex.h.

## Constructor & Destructor Documentation

Complex::Complex | ( |  | ) | `[inline]`

Default constructor.

Definition at line 55 of file Complex.h.

Referenced by operator *(), operator+(), operator-(), operator/(), and operator~().

    00055                   :
    00056           m_r(0),
    00057           m_i(0) {
    00058           }

Complex::Complex | ( | Real | i | ) | `[inline]`

Construct Complex from real part.

Parameters:

  | i | Initializer for both real and imaginary parts.

Definition at line 62 of file Complex.h.

    00062                         :
    00063           m_r(i),
    00064           m_i(i) {
    00065           }

Complex::Complex | ( | Real | r,
|  | Real | i |
| ) |  |  | `[inline]`

Construct Complex from real and imaginary.

Parameters:

  | r | Real part of complex number as a Real datatype
  | i | Imaginary part of the complex number as a Real datatype

Definition at line 70 of file Complex.h.

    00070                                 :
    00071           m_r(r),
    00072           m_i(i) {
    00073           }

## Member Function Documentation

Complex Complex::Abs | ( |  | ) | `[inline]`

Complex absolute value.

Returns:
  Absolute value.

Definition at line 209 of file Complex.h.

References Return.

Referenced by Abs().

    00209                       {
    00210                 Complex t(m_r < 0.0 ? -m_r : m_r, m_i < 0.0 ? -m_i : m_i);
    00211                 Return(t);
    00212         }

Complex Complex::Conjugate | ( |  | ) | `[inline]`

Complex conjugate.

Returns:
  Conjugate value.

Definition at line 216 of file Complex.h.

References Return.

    00216                             {
    00217                 Complex t(m_r, -m_i);
    00218                 Return(t);
    00219         }

Complex Complex::Exp | ( | Complex | e | ) | `[inline]`

Complex exponentiation.

Definition at line 222 of file Complex.h.

References Cos(), i(), r(), Return, and Sin().

Referenced by Exp().

    00222                                {
    00223                 Real r = e.r();
    00224                 r = exp(r);
    00225                 Real theta = e.i();
    00226                 Complex t(r * Cos(theta), r * Sin(theta));
    00227                 Return t;
    00228         }

Void Complex::i | ( | Real | i | ) | `[inline]`

Set the imaginary part of Complex number.

See also:
  i(Void)

Definition at line 93 of file Complex.h.

    00093 { m_i = i; }

Real Complex::i | ( | Void |  | ) | `[inline]`

Get the imaginary part of the Complex number as a Real.

Returns:
  The imaginary part of the complex number as a Real

Definition at line 83 of file Complex.h.

References Return.

Referenced by Exp(), ImagPart(), and operator/().

    00083                      {
    00084                 Return m_i;
    00085         }

Complex Complex::operator * | ( | Const Real & | r | ) | `[inline]`

Multiplication operator for Complex * Real.

Definition at line 161 of file Complex.h.

References Return.

    00161                                         {
    00162                 Complex c(r, 0.0);
    00163                 Return *this * c;
    00164         }

Complex Complex::operator * | ( | Const Complex & | c | ) | `[inline]`

Multiplication operator for Complex * Complex.

Definition at line 155 of file Complex.h.

References Complex(), and Return.

    00155                                            {
    00156                 Return Complex(m_r * c.m_r - m_i * c.m_i,
    00157                                            m_r * c.m_i + m_i * c.m_r);
    00158         }

Complex& Complex::operator *= | ( | const Complex | x | ) | `[inline]`

Multiply scale operator for Complex *= Complex.

Definition at line 192 of file Complex.h.

References Return.

    00192                                              {
    00193                 Return( *this = *this * x );
    00194         }

Bool Complex::operator!= | ( | Const Complex & | x | ) | `[inline]`

Inquality operator for Complex != Complex.

Definition at line 108 of file Complex.h.

References Return.

    00108                                                 {
    00109                 Return !(m_r == x.m_r && m_i == x.m_i);
    00110         }

Complex Complex::operator+ | ( | Const Complex & | c | ) | `[inline]`

Addition operator for Complex + Complex.

Definition at line 133 of file Complex.h.

References Complex(), and Return.

    00133                                            {
    00134                 Return Complex(m_r + c.m_r, m_i + c.m_i);
    00135         }

Complex& Complex::operator+= | ( | const Complex | x | ) | `[inline]`

Increment operator for Complex += Complex.

Definition at line 182 of file Complex.h.

References Return.

    00182                                              {
    00183                 Return( *this = *this + x );
    00184         }

Complex Complex::operator- | ( |  | ) | `[inline]`

Negation operator for Complex.

Both real and imaginary parts are negated.

See also:
  operator~()

Definition at line 144 of file Complex.h.

References Complex(), and Return.

    00144                            {
    00145                 Return Complex(-m_r, -m_i);
    00146         }

Complex Complex::operator- | ( | Const Complex & | c | ) | `[inline]`

Subtraction operator for Complex - Complex.

Definition at line 138 of file Complex.h.

References Complex(), and Return.

    00138                                            {
    00139                 Return Complex(m_r - c.m_r, m_i - c.m_i);
    00140         }

Complex& Complex::operator-= | ( | const Complex | x | ) | `[inline]`

Decrement operator for Complex -= Complex.

Definition at line 187 of file Complex.h.

References Return.

    00187                                              {
    00188                 Return( *this = *this - x );
    00189         }

Complex Complex::operator/ | ( | Const Real & | r | ) | `[inline]`

Division operator for Complex / Real.

Definition at line 176 of file Complex.h.

References Return.

    00176                                         {
    00177                 Complex c(r, 0.0);
    00178                 Return *this / c;
    00179         }

Complex Complex::operator/ | ( | Const Complex & | c | ) | `[inline]`

Division operator for Complex / Complex.

Definition at line 167 of file Complex.h.

References Complex(), i(), r(), and Return.

    00167                                            {
    00168                 Real modulus = c.m_r * c.m_r + c.m_i * c.m_i;
    00169                 Real r = m_i * c.m_i + m_r * c.m_r;
    00170                 Real i = m_i * c.m_r - m_r * c.m_i;
    00171
    00172                 Return Complex(r / modulus, i / modulus);
    00173         }

Complex& Complex::operator/= | ( | const Real | r | ) | `[inline]`

Divide scale operator for Complex /= Real.

Definition at line 202 of file Complex.h.

References Return.

    00202                                           {
    00203                 Complex x(r, 0.0);
    00204                 Return( *this = *this / x );
    00205         }

Complex& Complex::operator/= | ( | const Complex | x | ) | `[inline]`

Divide scale operator for Complex /= Complex.

Definition at line 197 of file Complex.h.

References Return.

    00197                                              {
    00198                 Return( *this = *this / x );
    00199         }

Bool Complex::operator< | ( | Const Complex & | x | ) | `[inline]`

Less-than operator for Complex < Complex.

Definition at line 113 of file Complex.h.

References Return.

    00113                                                {
    00114                 Return m_r < x.m_r && m_i < x.m_i;
    00115         }

Bool Complex::operator<= | ( | Const Complex & | x | ) | `[inline]`

Less-than or equal operator for Complex < Complex.

Definition at line 118 of file Complex.h.

References Return.

    00118                                                 {
    00119                 Return m_r <= x.m_r && m_i <= x.m_i;
    00120         }

Complex& Complex::operator= | ( | Const Real & | x | ) | `[inline]`

Asignment operator for Complex = Real.

Definition at line 96 of file Complex.h.

References Return.

    00096                                           {
    00097                 m_r = x;
    00098                 m_i = 0;
    00099                 Return *this;
    00100         }

Bool Complex::operator== | ( | Const Complex & | x | ) | `[inline]`

Equality operator for Complex == Complex.

Definition at line 103 of file Complex.h.

References Return.

    00103                                                 {
    00104                 Return m_r == x.m_r && m_i == x.m_i;
    00105         }

Bool Complex::operator> | ( | Const Complex & | x | ) | `[inline]`

Greater-than operator for Complex < Complex.

Definition at line 128 of file Complex.h.

References Return.

    00128                                                {
    00129                 Return m_r > x.m_r && m_i > x.m_i;
    00130         }

Bool Complex::operator>= | ( | Const Complex & | x | ) | `[inline]`

Greater-than or equal operator for Complex < Complex.

Definition at line 123 of file Complex.h.

References Return.

    00123                                                 {
    00124                 Return m_r >= x.m_r && m_i >= x.m_i;
    00125         }

Complex Complex::operator~ | ( |  | ) | `[inline]`

Conjugation operator for Complex.

Only imaginary part is negated.

See also:
  operator-()

Definition at line 150 of file Complex.h.

References Complex(), and Return.

    00150                            {
    00151                 Return Complex(m_r, -m_i);
    00152         }

Void Complex::print | ( | String | s = `0` | ) | `[inline]`

Print complex value, prepended by String s if not null.

Complex value is printed as "{r,i}".

Parameters:

  | s | String to prefix to complex number.

Definition at line 233 of file Complex.h.

References If.

    00233                                         {
    00234                 If (s)
    00235                         cout << s;
    00236                 cout << "{ ";
    00237                 cout.precision(2);
    00238                 cout << m_r << ", ";
    00239                 cout << m_i;
    00240                 cout << " }" << endl;
    00241         }

Void Complex::r | ( | Real | r | ) | `[inline]`

Set the real part of Complex number.

See also:
  r(Void)

Definition at line 89 of file Complex.h.

    00089 { m_r = r; }

Real Complex::r | ( | Void |  | ) | `[inline]`

Get the real part of Complex number as a Real.

Returns:
  The real part of the complex number as a Real

Definition at line 77 of file Complex.h.

References Return.

Referenced by Exp(), operator/(), and RealPart().

    00077                      {
    00078                 Return m_r;
    00079         }

## Friends And Related Function Documentation

ostream& operator<< | ( | ostream & | os,
|  | const Complex & | c |
| ) |  |  | `[friend]`

Print to output stream.

Complex number is printed as '(' <real_part> ',' <imag_part> ')'

Definition at line 32 of file Complex.h.

    00032                                                                     {
    00033                 cout << "(";
    00034                 // cout.precision(2); // Use this to set precision, if desired
    00035                 cout << c.m_r << ", ";
    00036                 cout << c.m_i;
    00037                 cout << ")";
    00038                 Return os;
    00039         }

istream& operator>> | ( | istream & | is,
|  | Complex & | c |
| ) |  |  | `[friend]`

Read from input stream.

Complex number is scanned as '{' <real_part> ',' <imag_part> '}' Alternately, parenthesis can be used to bracket complex number.

Definition at line 44 of file Complex.h.

    00044                                                               {
    00045                 char ch;
    00046                 is >> ch && (ch == '{' || ch == '(')
    00047                         && is >> c.m_r >> ch && ch == ','
    00048                         && is >> c.m_i >> ch && (ch == '}' || ch == '(');
    00049                 Return is;
    00050         }

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

- C:/Musimathics_local/Musimat/include/Complex.h