Public Member Functions | Friends

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.
Complexoperator= (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.
Complexoperator+= (const Complex x)
 Increment operator for Complex += Complex.
Complexoperator-= (const Complex x)
 Decrement operator for Complex -= Complex.
Complexoperator*= (const Complex x)
 Multiply scale operator for Complex *= Complex.
Complexoperator/= (const Complex x)
 Divide scale operator for Complex /= Complex.
Complexoperator/= (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 27 of file Complex.h.


Constructor & Destructor Documentation

Complex::Complex (  ) [inline]

Default constructor.

Definition at line 50 of file Complex.h.

      :

Complex::Complex ( Real  i ) [inline]

Construct Complex from real part.

Parameters:
iInitializer for both real and imaginary parts.

Definition at line 57 of file Complex.h.

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

Construct Complex from real and imaginary.

Parameters:
rReal part of complex number as a Real datatype
iImaginary part of the complex number as a Real datatype

Definition at line 65 of file Complex.h.

                                : 

Member Function Documentation

Complex Complex::Abs (  ) [inline]

Complex absolute value.

Returns:
Absolute value.

Definition at line 204 of file Complex.h.

Referenced by Abs().

                      {
Complex Complex::Conjugate (  ) [inline]

Complex conjugate.

Returns:
Conjugate value.

Definition at line 211 of file Complex.h.

                            {
Complex Complex::Exp ( Complex  e ) [inline]

Complex exponentiation.

Definition at line 217 of file Complex.h.

Referenced by Exp().

                               {
                Real r = e.r();
                r = exp(r);
Void Complex::i ( Real  i ) [inline]

Set the imaginary part of Complex number.

See also:
i(Void)

Definition at line 88 of file Complex.h.

References r().

{ m_r = r; }
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 78 of file Complex.h.

Referenced by ImagPart().

                     {
Bool Complex::operator!= ( Const Complex x ) [inline]

Inquality operator for Complex != Complex.

Definition at line 103 of file Complex.h.

                                                {
Complex Complex::operator* ( Const Complex c ) [inline]

Multiplication operator for Complex * Complex.

Definition at line 150 of file Complex.h.

                                           {
Complex Complex::operator* ( Const Real r ) [inline]

Multiplication operator for Complex * Real.

Definition at line 156 of file Complex.h.

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

Multiply scale operator for Complex *= Complex.

Definition at line 187 of file Complex.h.

                                             {
Complex Complex::operator+ ( Const Complex c ) [inline]

Addition operator for Complex + Complex.

Definition at line 128 of file Complex.h.

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

Increment operator for Complex += Complex.

Definition at line 177 of file Complex.h.

                                             {
Complex Complex::operator- ( Const Complex c ) [inline]

Subtraction operator for Complex - Complex.

Definition at line 133 of file Complex.h.

                                           {
Complex Complex::operator- (  ) [inline]

Negation operator for Complex.

Both real and imaginary parts are negated.

See also:
operator~()

Definition at line 139 of file Complex.h.

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

Decrement operator for Complex -= Complex.

Definition at line 182 of file Complex.h.

                                             {
Complex Complex::operator/ ( Const Complex c ) [inline]

Division operator for Complex / Complex.

Definition at line 162 of file Complex.h.

                                           {
                Real modulus = c.m_r * c.m_r + c.m_i * c.m_i;
                Real r = m_i * c.m_i + m_r * c.m_r;
Complex Complex::operator/ ( Const Real r ) [inline]

Division operator for Complex / Real.

Definition at line 171 of file Complex.h.

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

Divide scale operator for Complex /= Complex.

Definition at line 192 of file Complex.h.

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

Divide scale operator for Complex /= Real.

Definition at line 197 of file Complex.h.

                                          {
Bool Complex::operator< ( Const Complex x ) [inline]

Less-than operator for Complex < Complex.

Definition at line 108 of file Complex.h.

                                               {
Bool Complex::operator<= ( Const Complex x ) [inline]

Less-than or equal operator for Complex < Complex.

Definition at line 113 of file Complex.h.

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

Asignment operator for Complex = Real.

Definition at line 91 of file Complex.h.

                       { m_i = i; }

        Complex& operator=(Const Real& x) {
Bool Complex::operator== ( Const Complex x ) [inline]

Equality operator for Complex == Complex.

Definition at line 98 of file Complex.h.

                                                {
Bool Complex::operator> ( Const Complex x ) [inline]

Greater-than operator for Complex < Complex.

Definition at line 123 of file Complex.h.

                                               {
Bool Complex::operator>= ( Const Complex x ) [inline]

Greater-than or equal operator for Complex < Complex.

Definition at line 118 of file Complex.h.

                                                {
Complex Complex::operator~ (  ) [inline]

Conjugation operator for Complex.

Only imaginary part is negated.

See also:
operator-()

Definition at line 145 of file Complex.h.

                           {
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:
sString to prefix to complex number.

Definition at line 228 of file Complex.h.

References If.

                                         {r,i}".
        Void print(String s = 0) {
                If (s)
                        cout << s;
                cout << "{ ";
                cout.precision(2);
Void Complex::r ( Real  r ) [inline]

Set the real part of Complex number.

See also:
r(Void)

Definition at line 84 of file Complex.h.

{ 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 72 of file Complex.h.

Referenced by i(), and RealPart().

                     {

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 27 of file Complex.h.

{
        friend ostream& operator<<( ostream& os, const Complex& c ) {
                cout << "(";
                // cout.precision(2); // Use this to set precision, if desired
                cout << c.m_r << ", ";
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 39 of file Complex.h.

                                          {' <real_part> ',' <imag_part> '}'
        friend istream& operator>>( istream& is, Complex& c ) {
                char ch;
                is >> ch && (ch == '{' || ch == '(')

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