Category : Printer + Display Graphics
Archive   : BMRPH102.ZIP
Filename : COMPLEX.HPP

 
Output of file : COMPLEX.HPP contained in archive : BMRPH102.ZIP
// Header: Complex
// Version: 2.00 28-Oct-1989
//
// Language: C++ 2.0
// Environ: Any
// Compilers: Zortech C++ 2.01
//
// Purpose: Provides the class "Complex" for C++ programs. The majority
// of the class is implemented inline for efficiency. Only
// the division, power, and i/o methods are actual functions.
//
// Written by: Scott Robert Ladd
// 705 West Virginia
// Gunnison CO 81230
//
// BBS (303)641-6438
// FidoNet 1:104/708

#if !defined(__COMPLEX_HPP)
#define __COMPLEX_HPP 1

#include "stream.hpp"
#include "math.h"

class Complex
{
private:
double Real; // Real part
double Imag; // Imaginary part

static void (* ErrorHandler)();

public:
// constructors
Complex (void);
Complex (const Complex & C);
Complex (double & R, double & I);
Complex (double & R);

// method to set error handler function
static void SetErrorHandler(void (* UserHandler)());

// value extraction methods
friend double real(const Complex & C);
friend double imag(const Complex & C);

// assignment methods
void operator = (const Complex & C);
void operator = (double & R);

// unary minus method
Complex operator - ();

// calculation methods
friend Complex operator + (const Complex & C1, const Complex &C2);
friend Complex operator - (const Complex & C1, const Complex &C2);
friend Complex operator * (const Complex & C1, const Complex &C2);
friend Complex operator / (const Complex & C1, const Complex &C2);

Complex operator += (const Complex & C);
Complex operator -= (const Complex & C);
Complex operator *= (const Complex & C);
Complex operator /= (const Complex & C);

// comparison methods
friend int operator == (const Complex & C1, const Complex & C2);
friend int operator != (const Complex & C1, const Complex & C2);

friend int operator < (const Complex & C1, const Complex & C2);
friend int operator <= (const Complex & C1, const Complex & C2);

friend int operator > (const Complex & C1, const Complex & C2);
friend int operator >= (const Complex & C1, const Complex & C2);

// utility methods
friend double abs(const Complex & C);
friend double norm(const Complex & C);
friend double arg(const Complex & C);

// polar coordinate methods
friend Complex polar(double Radius, double Theta = 0.0);
friend Complex conj(const Complex & C);

// trigonometric methods
friend Complex cos(const Complex & C);
friend Complex sin(const Complex & C);
friend Complex tan(const Complex & C);

friend Complex cosh(const Complex & C);
friend Complex sinh(const Complex & C);
friend Complex tanh(const Complex & C);

// logarithmic methods
friend Complex exp(const Complex & C);
friend Complex log(const Complex & C);

// "power" methods
friend Complex pow(const Complex & C, const Complex & Power);
friend Complex sqrt(const Complex & C);

// output method
friend ostream & operator << (ostream & Output, const Complex & C);
friend istream & operator >> (istream & Input, Complex & C);
};

// constructors
inline Complex::Complex (void)
{
Real = 0.0;
Imag = 0.0;
}

inline Complex::Complex (const Complex & C)
{
Real = C.Real;
Imag = C.Imag;
}

inline Complex::Complex (double & R, double & I)
{
Real = R;
Imag = I;
}

inline Complex::Complex (double & R)
{
Real = R;
Imag = 0.0;
}

inline void Complex::SetErrorHandler(void (* UserHandler)())
{
ErrorHandler = UserHandler;
}

// value extraction methods
inline double real (const Complex & C)
{
return C.Real;
}

inline double imag (const Complex & C)
{
return C.Imag;
}

// assignment method
inline void Complex::operator = (const Complex & C)
{
Real = C.Real;
Imag = C.Imag;
}

inline void Complex::operator = (double & R)
{
Real = R;
Imag = 0.0;
}

// unary minus method
inline Complex Complex::operator - ()
{
Complex Result;

Result.Real = -Real;
Result.Imag = -Imag;

return Result;
}

// calculation methods
inline Complex operator + (const Complex & C1, const Complex &C2)
{
Complex Result;

Result.Real = C1.Real + C2.Real;
Result.Imag = C1.Imag + C2.Imag;

return Result;
}

inline Complex operator - (const Complex & C1, const Complex &C2)
{
Complex Result;

Result.Real = C1.Real - C2.Real;
Result.Imag = C1.Imag - C2.Imag;

return Result;
}

inline Complex operator * (const Complex & C1, const Complex &C2)
{
Complex Result;

Result.Real = (C1.Real * C2.Real) - (C1.Imag * C2.Imag);
Result.Imag = (C1.Real * C2.Imag) + (C1.Imag * C2.Real);

return Result;
}

inline Complex Complex::operator += (const Complex &C)
{
Real += C.Real;
Imag += C.Imag;

return *this;
}

inline Complex Complex::operator -= (const Complex &C)
{
Real -= C.Real;
Imag -= C.Imag;

return *this;
}

inline Complex Complex::operator *= (const Complex &C)
{
double OldReal;

OldReal = Real; // save old Real value

Real = (Real * C.Real) - (Imag * C.Imag);
Imag = (OldReal * C.Imag) + (Imag * C.Real);

return *this;
}

// comparison methods
inline int operator == (const Complex & C1, const Complex & C2)
{
return (C1.Real == C2.Real) && (C1.Imag == C2.Imag);
}

inline int operator != (const Complex & C1, const Complex & C2)
{
return (C1.Real != C2.Real) || (C1.Imag != C2.Imag);
}


inline int operator < (const Complex & C1, const Complex & C2)
{
return abs(C1) < abs(C2);
}

inline int operator <= (const Complex & C1, const Complex & C2)
{
return abs(C1) <= abs(C2);
}


inline int operator > (const Complex & C1, const Complex & C2)
{
return abs(C1) > abs(C2);
}

inline int operator >= (const Complex & C1, const Complex & C2)
{
return abs(C1) >= abs(C2);
}


// utility methods
inline double abs(const Complex & C)
{
double Result;

Result = sqrt(C.Real * C.Real + C.Imag * C.Imag);

return Result;
}

inline double norm(const Complex & C)
{
double Result;

Result = (C.Real * C.Real) + (C.Imag * C.Imag);

return Result;
}

inline double arg(const Complex & C)
{
double Result;

Result = atan2(C.Imag, C.Real);

return Result;
}


// polar coordinate methods
inline Complex polar(double Radius, double Theta)
{
Complex Result;

Result.Real = Radius * cos(Theta);
Result.Imag = Radius * sin(Theta);

return Result;
}

inline Complex conj(const Complex & C)
{
Complex Result;

Result.Real = C.Real;
Result.Imag = -C.Imag;

return Result;
}


// trigonometric methods
inline Complex cos(const Complex & C)
{
Complex Result;

Result.Real = cos(C.Real) * cosh(C.Imag);
Result.Imag = -sin(C.Real) * sinh(C.Imag);

return Result;
}

inline Complex sin(const Complex & C)
{
Complex Result;

Result.Real = sin(C.Real) * cosh(C.Imag);
Result.Imag = cos(C.Real) * sinh(C.Imag);

return Result;
}

inline Complex tan(const Complex & C)
{
Complex Result;

Result = sin(C) / cos(C);

return Result;
}


inline Complex cosh(const Complex & C)
{
Complex Result;

Result = cos(C.Imag) * cosh(C.Real);
Result = sin(C.Imag) * sinh(C.Real);

return Result;
}

inline Complex sinh(const Complex & C)
{
Complex Result;

Result.Real = cos(C.Imag) * sinh(C.Real);
Result.Imag = sin(C.Imag) * cosh(C.Real);

return Result;
}

inline Complex tanh(const Complex & C)
{
Complex Result;

Result = sinh(C) / cosh(C);

return Result;
}


// logarithmic methods
inline Complex exp(const Complex & C)
{
Complex Result;

double X = exp(C.Real);

Result.Real = X * cos(C.Imag);
Result.Imag = X * sin(C.Imag);

return Result;
}

inline Complex log(const Complex & C)
{
Complex Result;
double Hypot = abs(C);

if (Hypot > 0.0)
{
Result.Real = log(Hypot);
Result.Imag = atan2(C.Imag, C.Real);
}
else
Complex::ErrorHandler();

return Result;
}

#endif // __Complex_HPP


  3 Responses to “Category : Printer + Display Graphics
Archive   : BMRPH102.ZIP
Filename : COMPLEX.HPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/